Skip to content

Commit

Permalink
🚸 Enable opening of register screen for AuthCore users (#61)
Browse files Browse the repository at this point in the history
* 🎨 Add initialScreen param for initAuthcore

* 🎨 Improve params format

* 🐛 Delay initAuthcore to ensure DOM is loaded

* 🚸 Use setInterval to check if the DOM is fully loaded
  • Loading branch information
AuroraHuang22 authored Jul 18, 2024
1 parent 5f89929 commit a7b461a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
LikeCoinWalletConnectorMethodType,
LikeCoinWalletConnectorOptions,
LikeCoinWalletConnectorSession,
AuthCoreInitialScreen,
} from './types';

import './style.css';
Expand Down Expand Up @@ -355,7 +356,8 @@ export class LikeCoinWalletConnector {
init = async (
methodType: LikeCoinWalletConnectorMethodType,
params?: any,
language = this.options.language
language = this.options.language,
initialScreen?: AuthCoreInitialScreen
) => {
let initiator: Promise<LikeCoinWalletConnectorInitResponse>;

Expand All @@ -368,7 +370,13 @@ export class LikeCoinWalletConnector {
<IntlProvider language={language}>
<AuthcoreDialog
onMount={({ containerId }) => {
initAuthcore(this.options, { containerId });
const intervalId = setInterval(() => {
const containerElement = document.getElementById(containerId);
if (containerElement) {
initAuthcore(this.options, { containerId, initialScreen });
clearInterval(intervalId);
}
}, 200);
}}
onClose={() => {
this.closeDialog();
Expand All @@ -386,7 +394,7 @@ export class LikeCoinWalletConnector {
);
});
} else {
initiator = initAuthcore(this.options, { accessToken });
initiator = initAuthcore(this.options, { accessToken, initialScreen });
}
break;

Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export type LikeCoinWalletConnectorEvent =
method: LikeCoinWalletConnectorMethodType;
};

export type AuthCoreInitialScreen = 'signin' | 'register'

export interface LikeCoinWalletConnectorConfig {
chainId: string;
chainName: string;
Expand Down
7 changes: 5 additions & 2 deletions src/utils/authcore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AuthCoreAuthClient, AuthCoreWidgets } from '@likecoin/authcore-js';
import {
LikeCoinWalletConnectorInitResponse,
LikeCoinWalletConnectorOptions,
AuthCoreInitialScreen
} from '../types';
import { convertAddressPrefix } from './wallet';

Expand All @@ -26,10 +27,12 @@ export async function initAuthcore(
{
accessToken,
containerId,
initialScreen = 'signin',
}: {
accessToken?: string;
containerId?: string;
} = {}
initialScreen?: AuthCoreInitialScreen;
} = {},
): Promise<LikeCoinWalletConnectorInitResponse> {
const authcoreApiHost = options.authcoreApiHost;

Expand Down Expand Up @@ -66,7 +69,7 @@ export async function initAuthcore(
primaryColour: '#28646e',
container: containerId,
root: `${authcoreApiHost}/widgets`,
initialScreen: 'signin',
initialScreen: initialScreen,
socialLoginPaneStyle: 'top',
socialLoginPaneOption: 'grid',
internal: true,
Expand Down

0 comments on commit a7b461a

Please sign in to comment.