Skip to content

Commit

Permalink
feat: don't remove login panel when noCommonBaseModal set to true, up…
Browse files Browse the repository at this point in the history
…date loginEagerly error text
  • Loading branch information
aelf-lxy committed Jul 19, 2024
1 parent ddbd47c commit b958e85
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const wallets = [
new PortkeyDiscoverWallet({
networkType: NETWORK_TYPE,
chainId: CHAIN_ID,
autoRequestAccount: true,
autoRequestAccount: true, // If set to true, please contact Portkey to add whitelist @Rachel
autoLogoutOnDisconnected: true,
autoLogoutOnNetworkMismatch: true,
autoLogoutOnAccountMismatch: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-base",
"version": "0.1.2",
"version": "0.1.3-alpha.2",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const ERR_CODE = {
export const ERR_CODE_MSG: {
[key: number]: string;
} = {
10001: 'Discover login eagerly fail',
10001: 'Automatic login failed. Please log in manually.',
10002:
'Unmatched network. Please switch the network through "My" > "Wallet" > "Switch Networks" to continue.',
10003: 'Synchronising data on the blockchain. Please wait a few seconds.',
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-bridge",
"version": "0.1.2",
"version": "0.1.3-alpha.2",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
17 changes: 12 additions & 5 deletions packages/bridge/src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,18 @@ import {
} from './store';
import { DIDWalletInfo, TelegramPlatform } from '@portkey/did-ui-react';
import { isPortkeyApp } from '@aelf-web-login/utils';
import { IBaseConfig } from '.';

class Bridge {
private _wallets: WalletAdapter[];
private _activeWallet: WalletAdapter | undefined;
private _loginResolve: (value: TWalletInfo) => void;
private _loginReject: (error: TWalletError) => void;
private _eventMap: Record<keyof IWalletAdapterEvents, any> = {} as IWalletAdapterEvents;
private _noCommonBaseModal: boolean;

constructor(wallets: WalletAdapter[]) {
constructor(wallets: WalletAdapter[], { noCommonBaseModal = false }: IBaseConfig) {
this._noCommonBaseModal = noCommonBaseModal;
this._wallets = wallets;
this._activeWallet = undefined;
this._loginResolve = () => {};
Expand Down Expand Up @@ -192,11 +195,13 @@ class Bridge {

onConnectErrorHandler = (err: TWalletError) => {
console.log('in error event', err, this.activeWallet);
if (!this._noCommonBaseModal) {
this.closeLoginPanel();
this.closeNestedModal();
}
this.unbindEvents();
this.closeLoginPanel();
this.closeLoadingModal();
this._loginReject(err);
this.closeNestedModal();
dispatch(clearWalletInfo());
dispatch(clearWalletType());
dispatch(setLoginError(err));
Expand Down Expand Up @@ -250,8 +255,10 @@ class Bridge {
} catch (e) {
console.log('onUniqueWalletClick--', e);
} finally {
this.closeLoadingModal();
this.closeLoginPanel();
if (!this._noCommonBaseModal) {
this.closeLoadingModal();
this.closeLoginPanel();
}
}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ export interface IBridgeAPI {
store: AppStore;
mountApp: () => void;
unMountApp: () => void;
getSignIn: () => React.ReactNode;
getSignIn: (arg: React.ReactNode) => React.ReactNode;
}
export function initBridge({ baseConfig, wallets, didConfig }: IConfigProps): IBridgeAPI {
const bridgeInstance = new Bridge(wallets);
const bridgeInstance = new Bridge(wallets, baseConfig);
ConfigProvider.setGlobalConfig(didConfig);
console.log('init bridge');

Expand Down
10 changes: 6 additions & 4 deletions packages/bridge/src/mountApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function mountApp(
const root = createRoot(SignInWrapperDom);
root.render(
<PortkeyProvider {...baseConfig.PortkeyProviderProps} networkType={baseConfig.networkType}>
<SignInModal bridgeInstance={bridgeInstance} wallets={wallets} baseConfig={baseConfig} />,
<SignInModal bridgeInstance={bridgeInstance} wallets={wallets} baseConfig={baseConfig} />
</PortkeyProvider>,
);
containerElement.appendChild(SignInWrapperDom);
Expand All @@ -36,14 +36,16 @@ export function useMountSignIn(
bridgeInstance: Bridge,
wallets: WalletAdapter[],
baseConfig: IBaseConfig,
) {
children: React.ReactNode,
): React.ReactNode {
const SignInNode = useMemo(() => {
return (
<PortkeyProvider {...baseConfig.PortkeyProviderProps} networkType={baseConfig.networkType}>
<SignInModal bridgeInstance={bridgeInstance} wallets={wallets} baseConfig={baseConfig} />,
<SignInModal bridgeInstance={bridgeInstance} wallets={wallets} baseConfig={baseConfig} />
{children}
</PortkeyProvider>
);
}, [baseConfig, bridgeInstance, wallets]);
}, [baseConfig, bridgeInstance, children, wallets]);
return SignInNode;
}

Expand Down
22 changes: 21 additions & 1 deletion packages/bridge/src/useVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,27 @@ import {
import { TChainId } from '@aelf-web-login/wallet-adapter-base';
import { AccountType, OperationTypeEnum } from '@portkey/services';

const useVerifier = () => {
interface IUseVerifier {
getRecommendationVerifier: (chainId: TChainId) => Promise<IVerifier>;
verifySocialToken: ({
accountType,
token,
guardianIdentifier,
verifier,
chainId,
operationType,
operationDetails,
}: {
guardianIdentifier: string;
accountType: AccountType;
token?: string;
verifier: IVerifier;
chainId: TChainId;
operationType: OperationTypeEnum;
operationDetails: string;
}) => any;
}
const useVerifier: () => IUseVerifier = () => {
const verifyToken = useVerifyToken();

const socialLogin = useMemo<ISocialLoginConfig | undefined>(
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-react",
"version": "0.1.2",
"version": "0.1.3-alpha.2",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
29 changes: 19 additions & 10 deletions packages/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import VConsole from 'vconsole';

const HOOK_ERROR_MESSAGE =
'Must call the provided initialization method`init` method before using hooks.';

// let noCommonBaseModal = false;
export const init = (options: IConfigProps): IBridgeAPI => {
// noCommonBaseModal = options.baseConfig.noCommonBaseModal ?? false;
if (options.baseConfig.showVconsole) {
new VConsole();
}
Expand Down Expand Up @@ -40,21 +41,29 @@ interface IWebLoginProviderProps {
}

export const WebLoginProvider: React.FC<IWebLoginProviderProps> = ({ children, bridgeAPI }) => {
const { mountApp, unMountApp } = bridgeAPI ?? {
mountApp: () => {},
unMountApp: () => {},
// const { mountApp, unMountApp, getSignIn } = bridgeAPI ?? {
// mountApp: () => {},
// unMountApp: () => {},
// getSignIn: () => null,
// };
// useEffect(() => {
// if (noCommonBaseModal) {
// return;
// }
// mountApp();
// return unMountApp;
// }, [mountApp, unMountApp]);
const { getSignIn } = bridgeAPI ?? {
getSignIn: () => null,
};
useEffect(() => {
mountApp();
return unMountApp;
}, [mountApp, unMountApp]);

if (!bridgeAPI) {
return null;
}
return (
<WebLoginContext.Provider value={bridgeAPI}>
{/* {getSignIn()} */}
{children}
{/* {noCommonBaseModal ? getSignIn(children) : children} */}
{getSignIn(children)}
</WebLoginContext.Provider>
);
};
Expand Down
14 changes: 7 additions & 7 deletions packages/starter/src/Demo/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ const didConfig = {
};

// const SignInProxy = () => {
// console.log('SignInProxy-----------');
// const { isLocking } = useConnectWallet();
// console.log('-----', isLocking);
// // console.log('SignInProxy-----------');
// // const { isLocking } = useConnectWallet();
// // console.log('-----', isLocking);
// return <div>111</div>;
// };

const baseConfig = {
// SignInComponent: SignInProxy,
PortkeyProviderProps: {
theme: 'light',
theme: 'dark' as any,
},
showVconsole: true,
networkType: NETWORK_TYPE,
chainId: CHAIN_ID,
keyboard: true,
noCommonBaseModal: true,
design: SignInDesignEnum.Web2Design, // "SocialDesign" | "CryptoDesign" | "Web2Design"
// noCommonBaseModal: true,
design: SignInDesignEnum.CryptoDesign, // "SocialDesign" | "CryptoDesign" | "Web2Design"
titleForSocialDesign: 'Crypto wallet',
iconSrcForSocialDesign:
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNTYiIHZpZXdCb3g9IjAgMCA1NiA1NiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgaWQ9IkVsZiBFeHBsb3JlciI+CjxyZWN0IHdpZHRoPSI1NiIgaGVpZ2h0PSI1NiIgZmlsbD0id2hpdGUiLz4KPHBhdGggaWQ9IlNoYXBlIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTMwLjAwMDMgMTEuODQyQzMzLjEwNjkgMTEuODQyIDM1LjYyNTIgOS4zMjM3MSAzNS42MjUyIDYuMjE3MTlDMzUuNjI1MiAzLjExMDY4IDMzLjEwNjkgMC41OTIzNDYgMzAuMDAwMyAwLjU5MjM0NkMyNi44OTM4IDAuNTkyMzQ2IDI0LjM3NTUgMy4xMTA2OCAyNC4zNzU1IDYuMjE3MTlDMjQuMzc1NSA5LjMyMzcxIDI2Ljg5MzggMTEuODQyIDMwLjAwMDMgMTEuODQyWk01NS40MDkzIDI4LjAzNzhDNTUuNDA5MyAzNC4zNTc5IDUwLjI4NTggMzkuNDgxNCA0My45NjU3IDM5LjQ4MTRDMzcuNjQ1NSAzOS40ODE0IDMyLjUyMiAzNC4zNTc5IDMyLjUyMiAyOC4wMzc4QzMyLjUyMiAyMS43MTc2IDM3LjY0NTUgMTYuNTk0MSA0My45NjU3IDE2LjU5NDFDNTAuMjg1OCAxNi41OTQxIDU1LjQwOTMgMjEu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q0QzIi8+CjwvZz4KPC9zdmc+Cg==',
Expand All @@ -80,7 +80,7 @@ const wallets = [
new PortkeyDiscoverWallet({
networkType: NETWORK_TYPE,
chainId: CHAIN_ID,
autoRequestAccount: true,
autoRequestAccount: true, // If set to true, please contact Portkey to add whitelist @Rachel
autoLogoutOnDisconnected: true,
autoLogoutOnNetworkMismatch: true,
autoLogoutOnAccountMismatch: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/utils",
"version": "0.1.2",
"version": "0.1.3-alpha.2",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/night-elf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-night-elf",
"version": "0.1.2",
"version": "0.1.3-alpha.2",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/portkey-aa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-portkey-aa",
"version": "0.1.2",
"version": "0.1.3-alpha.2",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/portkey-discover/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-portkey-discover",
"version": "0.1.2",
"version": "0.1.3-alpha.2",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
65 changes: 63 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b958e85

Please sign in to comment.