Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/awaken access #109

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.0",
"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.0",
"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
15 changes: 12 additions & 3 deletions packages/bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import {
WalletAdapter,
} from '@aelf-web-login/wallet-adapter-base';
import { Bridge } from './bridge';
import { mountApp, unMountApp } from './mountApp';
import { mountApp, unMountApp, useMountSignIn } from './mountApp';
import { store, AppStore } from './store';
import { GlobalConfigProps } from '@portkey/did-ui-react/dist/_types/src/components/config-provider/types';
import { ConfigProvider } from '@portkey/did-ui-react';
import { ConfigProvider, SignInProps, ISignIn, PortkeyProvider } from '@portkey/did-ui-react';
import { RefAttributes } from 'react';

type BaseConfigProviderProps = Omit<React.ComponentProps<typeof PortkeyProvider>, 'children'>;

export interface IBaseConfig {
networkType: NetworkEnum;
Expand All @@ -20,6 +23,8 @@ export interface IBaseConfig {
titleForSocialDesign?: string;
noCommonBaseModal?: boolean;
showVconsole?: boolean;
SignInComponent?: React.FC<SignInProps & RefAttributes<ISignIn>>;
PortkeyProviderProps?: Partial<BaseConfigProviderProps>;
}
export interface IConfigProps {
didConfig: GlobalConfigProps;
Expand All @@ -31,9 +36,10 @@ export interface IBridgeAPI {
store: AppStore;
mountApp: () => void;
unMountApp: () => void;
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 All @@ -43,5 +49,8 @@ export function initBridge({ baseConfig, wallets, didConfig }: IConfigProps): IB
store,
mountApp: mountApp.bind(null, bridgeInstance, wallets, baseConfig),
unMountApp,
getSignIn: useMountSignIn.bind(null, bridgeInstance, wallets, baseConfig),
};
}

export * as PortkeyDid from '@portkey/did-ui-react';
22 changes: 20 additions & 2 deletions packages/bridge/src/mountApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SignInModal from './ui';
import { Bridge } from './bridge';
import { IBaseConfig } from '.';
import { PortkeyProvider } from '@portkey/did-ui-react';
import { useMemo } from 'react';

export function mountApp(
bridgeInstance: Bridge,
Expand All @@ -24,13 +25,30 @@ export function mountApp(
SignInWrapperDom.setAttribute('id', 'sign-in-wrapper');
const root = createRoot(SignInWrapperDom);
root.render(
<PortkeyProvider networkType={baseConfig.networkType} theme="dark">
<SignInModal bridgeInstance={bridgeInstance} wallets={wallets} baseConfig={baseConfig} />,
<PortkeyProvider {...baseConfig.PortkeyProviderProps} networkType={baseConfig.networkType}>
<SignInModal bridgeInstance={bridgeInstance} wallets={wallets} baseConfig={baseConfig} />
</PortkeyProvider>,
);
containerElement.appendChild(SignInWrapperDom);
}

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} />
{children}
</PortkeyProvider>
);
}, [baseConfig, bridgeInstance, children, wallets]);
return SignInNode;
}

export function unMountApp() {
if (typeof window === 'undefined') {
return;
Expand Down
5 changes: 3 additions & 2 deletions packages/bridge/src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
);
const filteredWallets = wallets.filter((ele) => ele.name !== PORTKEYAA);
const isMobileDevice = isMobile();
const { noCommonBaseModal = false } = baseConfig;
const { noCommonBaseModal = false, SignInComponent } = baseConfig;
const FinalSignInComponent = SignInComponent || SignIn;
// const isLocking = store.getState().isLocking;
// console.log('isLocking', isLocking);

Expand Down Expand Up @@ -425,7 +426,7 @@ const SignInModal: React.FC<ISignInModalProps> = (props: ISignInModalProps) => {
onCloseHandler={onCloseWrapperInternal}
noCommonBaseModal={noCommonBaseModal}
>
<SignIn
<FinalSignInComponent
pin={TelegramPlatform.isTelegramPlatform() ? DEFAULT_PIN : undefined}
defaultLifeCycle={currentLifeCircle}
defaultChainId={baseConfig.chainId}
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.0",
"version": "0.1.3-alpha.2",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
31 changes: 24 additions & 7 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,15 +41,31 @@ interface IWebLoginProviderProps {
}

export const WebLoginProvider: React.FC<IWebLoginProviderProps> = ({ children, bridgeAPI }) => {
const { mountApp, unMountApp } = bridgeAPI ?? { mountApp: () => {}, unMountApp: () => {} };
useEffect(() => {
mountApp();
return unMountApp;
}, [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,
};

if (!bridgeAPI) {
return null;
}
return <WebLoginContext.Provider value={bridgeAPI}>{children}</WebLoginContext.Provider>;
return (
<WebLoginContext.Provider value={bridgeAPI}>
{/* {noCommonBaseModal ? getSignIn(children) : children} */}
{getSignIn(children)}
</WebLoginContext.Provider>
);
};

export function useWebLoginContext(): IBridgeAPI {
Expand Down
8 changes: 4 additions & 4 deletions packages/starter/.dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export default defineConfig({
},
favicons: ['https://ipfs.io/ipfs/QmWtjvb47DU1EQ4MpridFY1ow4214aAWCkhGu3ZF4xvRSY/'],
locales: [{ id: 'en-US', name: 'EN' }],
https: {
key: './ssl/server.key',
cert: './ssl/server.cert',
},
// https: {
// key: './ssl/server.key',
// cert: './ssl/server.cert',
// },
});
15 changes: 13 additions & 2 deletions packages/starter/src/Demo/demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,23 @@ const didConfig = {
// }
};

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

const baseConfig = {
// SignInComponent: SignInProxy,
PortkeyProviderProps: {
theme: 'dark' as any,
},
showVconsole: true,
networkType: NETWORK_TYPE,
chainId: CHAIN_ID,
keyboard: true,
noCommonBaseModal: false,
// noCommonBaseModal: true,
design: SignInDesignEnum.CryptoDesign, // "SocialDesign" | "CryptoDesign" | "Web2Design"
titleForSocialDesign: 'Crypto wallet',
iconSrcForSocialDesign:
Expand All @@ -69,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
6 changes: 3 additions & 3 deletions 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.0",
"version": "0.1.3-alpha.2",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -28,8 +28,8 @@
"test:coverage": "jest --config=jest.config.ts --coverage --detectOpenHandles"
},
"dependencies": {
"@aelf-web-login/wallet-adapter-base": "0.0.2-alpha.34",
"@aelf-web-login/wallet-adapter-react": "0.0.2-alpha.34",
"@aelf-web-login/wallet-adapter-base": "0.1.2",
"@aelf-web-login/wallet-adapter-react": "0.1.2",
"bignumber.js": "^9.1.2",
"dayjs": "^1.11.11",
"react": "^18.0.0",
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.0",
"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.0",
"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.0",
"version": "0.1.3-alpha.2",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
Loading
Loading