diff --git a/packages/base/src/types.ts b/packages/base/src/types.ts index 136b45a..1777548 100644 --- a/packages/base/src/types.ts +++ b/packages/base/src/types.ts @@ -1,4 +1,5 @@ -import { SendOptions, IContract, LoginStatusEnum } from '@portkey/types'; +import { BaseGuardianItem } from '@portkey/did-ui-react'; +import { IContract, LoginStatusEnum, SendOptions } from '@portkey/types'; export enum WalletStateEnum { // Wallet plug-in detected @@ -52,12 +53,12 @@ export interface ICallContractParams { args: T; chainId?: TChainId; sendOptions?: SendOptions; - guardiansApproved?: any[]; + approvedGuardians?: BaseGuardianItem[]; } export interface ISendOrViewAdapter extends ICallContractParams { caContract: IContract; - guardiansApproved: any[]; + approvedGuardians: ICallContractParams['approvedGuardians']; type?: string; } diff --git a/packages/bridge/src/bridge.ts b/packages/bridge/src/bridge.ts index f3b915a..5c2a8f5 100644 --- a/packages/bridge/src/bridge.ts +++ b/packages/bridge/src/bridge.ts @@ -37,7 +37,7 @@ import { clearManagerReadonlyStatusInSideChain, EE, SET_GUARDIAN_APPROVAL_MODAL, - SET_GUARDIAN_LIST, + SET_GUARDIAN_APPROVAL_PAYLOAD, } from './utils'; const { isPortkeyApp } = utils; @@ -189,11 +189,11 @@ class Bridge { props.methodName !== 'Approve' ) { EE.emit(SET_GUARDIAN_APPROVAL_MODAL, true); - const { guardians, caHash, caAddress } = await this.getGuardianListFromGuardianApproveModal(); - console.log('intg----getGuardianListFromGuardianApproveModal', guardians, caHash, caAddress); + const { guardians, caHash, caAddress } = await this.getApprovalModalGuardians(); + console.log('intg----getApprovalModalGuardians', guardians, caHash, caAddress); const rs = await this.activeWallet?.callSendMethod({ ...props, - guardiansApproved: guardians, + approvedGuardians: guardians, }); console.log('intg---rs of callSendMethod', rs); dispatch(setIsManagerReadOnlyStatus(false)); @@ -209,13 +209,13 @@ class Bridge { } }; - getGuardianListFromGuardianApproveModal = async (): Promise<{ + getApprovalModalGuardians = async (): Promise<{ guardians: any[]; caHash: string; caAddress: string; }> => { return new Promise((resolve) => { - EE.once(SET_GUARDIAN_LIST, (result) => { + EE.once(SET_GUARDIAN_APPROVAL_PAYLOAD, (result) => { resolve(result); }); }); diff --git a/packages/bridge/src/store.ts b/packages/bridge/src/store.ts index 1ad6e52..a846da9 100644 --- a/packages/bridge/src/store.ts +++ b/packages/bridge/src/store.ts @@ -1,6 +1,7 @@ -import { createSlice, configureStore, EnhancedStore } from '@reduxjs/toolkit'; -import { TWalletInfo, WalletTypeEnum, TWalletError } from '@aelf-web-login/wallet-adapter-base'; +import { TWalletError, TWalletInfo, WalletTypeEnum } from '@aelf-web-login/wallet-adapter-base'; +import { BaseGuardianItem } from '@portkey/did-ui-react'; import { LoginStatusEnum } from '@portkey/types'; +import { configureStore, createSlice, EnhancedStore } from '@reduxjs/toolkit'; export enum IsManagerReadOnlyStatusEnum { INIT = 'INIT', @@ -14,7 +15,7 @@ type TState = { walletType: WalletTypeEnum; loginError: TWalletError | null; loginOnChainStatus: LoginStatusEnum; - approveGuardians: any[]; + approvedGuardians: BaseGuardianItem[]; isManagerReadOnlyStatus: IsManagerReadOnlyStatusEnum; }; @@ -24,7 +25,7 @@ const initialState: TState = { walletType: WalletTypeEnum.unknown, loginError: null, loginOnChainStatus: LoginStatusEnum.INIT, - approveGuardians: [], + approvedGuardians: [], isManagerReadOnlyStatus: IsManagerReadOnlyStatusEnum.INIT, }; @@ -56,8 +57,8 @@ const aelfWebLoginSlice = createSlice({ setLoginOnChainStatus: (state, action) => { state.loginOnChainStatus = action.payload; }, - setApproveGuardians: (state, action) => { - state.approveGuardians = action.payload; + setApprovedGuardians: (state, action) => { + state.approvedGuardians = action.payload; }, setIsManagerReadOnlyStatus: (state, action) => { state.isManagerReadOnlyStatus = action.payload @@ -104,7 +105,7 @@ export const { setLoginError, clearLoginError, setLoginOnChainStatus, - setApproveGuardians, + setApprovedGuardians, setIsManagerReadOnlyStatus, } = aelfWebLoginSlice.actions; diff --git a/packages/bridge/src/ui.tsx b/packages/bridge/src/ui.tsx index 5a3ae2c..7a48087 100644 --- a/packages/bridge/src/ui.tsx +++ b/packages/bridge/src/ui.tsx @@ -522,12 +522,9 @@ const SignInModal: React.FC = (props: ISignInModalProps) => { const [showGuardianApprovalModal, setShowGuardianApprovalModal] = useState(false); useEffect(() => { - const hander = (isShow: boolean) => { - setShowGuardianApprovalModal(isShow); - }; - EE.on(SET_GUARDIAN_APPROVAL_MODAL, hander); + EE.on(SET_GUARDIAN_APPROVAL_MODAL, setShowGuardianApprovalModal); return () => { - EE.off(SET_GUARDIAN_APPROVAL_MODAL, hander); + EE.off(SET_GUARDIAN_APPROVAL_MODAL, setShowGuardianApprovalModal); }; }, []); diff --git a/packages/bridge/src/useTelegram.ts b/packages/bridge/src/useTelegram.ts index 5fd3a6b..7202d63 100644 --- a/packages/bridge/src/useTelegram.ts +++ b/packages/bridge/src/useTelegram.ts @@ -73,13 +73,15 @@ const useTelegram = ( } console.log('intg-----------onCreatePendingHandler,'); //TODO: only muti-guardian need to execute 76-82 - const isManagerReadOnly = await getIsManagerReadOnly( - chainId, - createPendingInfo.didWallet?.caInfo.caHash, - createPendingInfo.walletInfo.address, - ); - caAddressRef.current = createPendingInfo.didWallet?.caInfo.caAddress ?? ''; - dispatch(setIsManagerReadOnlyStatus(isManagerReadOnly)); + if (guardianList?.length && guardianList.length > 1) { + const isManagerReadOnly = await getIsManagerReadOnly( + chainId, + createPendingInfo.didWallet?.caInfo.caHash, + createPendingInfo.walletInfo.address, + ); + caAddressRef.current = createPendingInfo.didWallet?.caInfo.caAddress ?? ''; + dispatch(setIsManagerReadOnlyStatus(isManagerReadOnly)); + } bridgeInstance.onPortkeyAAWalletCreatePending(createPendingInfo); }, []); const [currentLifeCircle, setCurrentLifeCircle] = useState< @@ -255,17 +257,7 @@ const useTelegram = ( } else { setLoading(false); if (isTelegramPlatform && enableAcceleration) { - // console.log('intg-----------more guardian', signResult.value.guardianList); - // setGuardianList(signResult.value.guardianList || []); - // setTimeout(() => { - // setApprovalVisible(true); - // ConfigProvider.setGlobalConfig({ - // globalLoadingHandler: undefined, - // }); - // }, 500); - - const guardianListFromSignResult = signResult.value.guardianList ?? []; - const resetGuardianList = guardianListFromSignResult.map((ele: any) => { + const resetGuardianList = (signResult.value.guardianList ?? []).map((ele: any) => { return { ...ele, status: null, @@ -335,8 +327,12 @@ const useTelegram = ( const onTGSignInApprovalSuccess = useCallback( async (guardians: any[]) => { EE.emit(SET_GUARDIAN_APPROVAL_MODAL, false); - EE.emit(SET_GUARDIAN_LIST, { guardians, caHash, caAddress: caAddressRef.current }); - dispatch(setApproveGuardians(guardians)); + EE.emit(SET_GUARDIAN_APPROVAL_PAYLOAD, { + guardians, + caHash, + caAddress: caAddressRef.current, + }); + dispatch(setApprovedGuardians(guardians)); }, [EE, caHash], ); diff --git a/packages/bridge/src/utils.ts b/packages/bridge/src/utils.ts index cd482bd..4634006 100644 --- a/packages/bridge/src/utils.ts +++ b/packages/bridge/src/utils.ts @@ -5,7 +5,7 @@ import { TChainId, EventEmitter } from '@aelf-web-login/wallet-adapter-base'; export const EE = new EventEmitter(); export const SET_GUARDIAN_APPROVAL_MODAL = 'SET_GUARDIAN_APPROVAL_MODAL'; -export const SET_GUARDIAN_LIST = 'SET_GUARDIAN_LIST'; +export const SET_GUARDIAN_APPROVAL_PAYLOAD = 'SET_GUARDIAN_APPROVAL_PAYLOAD'; const getCaContractBase = async (chainId: TChainId) => { const chainInfo = await getChainInfo(chainId); @@ -24,21 +24,21 @@ const getCaContractBase = async (chainId: TChainId) => { const clearManagerReadonlyStatusInMainChain = async ( caAddress = '', caHash = '', - guardiansApproved?: any[], + approvedGuardians?: any[], ) => { console.log( 'intg-----clearManagerReadonlyStatusInMainChain', caAddress, caHash, - guardiansApproved, + approvedGuardians, ); - if (!guardiansApproved || guardiansApproved.length === 0) { + if (!approvedGuardians || approvedGuardians.length === 0) { return; } const ca = await getCaContractBase('AELF'); await ca.callSendMethod('RemoveReadOnlyManager', caAddress, { caHash, - guardiansApproved: guardiansApproved, + approvedGuardians: approvedGuardians, }); }; @@ -46,22 +46,22 @@ const clearManagerReadonlyStatusInSideChain = async ( chainId: TChainId, caAddress = '', caHash = '', - guardiansApproved?: any[], + approvedGuardians?: any[], ) => { console.log( 'intg-----clearManagerReadonlyStatusInSideChain', chainId, caAddress, caHash, - guardiansApproved, + approvedGuardians, ); - if (!guardiansApproved || guardiansApproved.length === 0) { + if (!approvedGuardians || approvedGuardians.length === 0) { return; } const ca = await getCaContractBase(chainId); await ca.callSendMethod('RemoveReadOnlyManager', caAddress, { caHash, - guardiansApproved: guardiansApproved, + approvedGuardians: approvedGuardians, }); }; diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx index ada8648..bcbfc71 100644 --- a/packages/react/src/index.tsx +++ b/packages/react/src/index.tsx @@ -1,11 +1,11 @@ /* eslint-disable @typescript-eslint/no-empty-function */ -import React, { useCallback, useMemo, useState, useSyncExternalStore } from 'react'; -import { initBridge, IConfigProps, IBridgeAPI } from '@aelf-web-login/wallet-adapter-bridge'; import { ConnectedWallet, enhancedLocalStorage, PORTKEYAA, } from '@aelf-web-login/wallet-adapter-base'; +import { IBridgeAPI, IConfigProps, initBridge } from '@aelf-web-login/wallet-adapter-bridge'; +import React, { useCallback, useMemo, useState, useSyncExternalStore } from 'react'; const HOOK_ERROR_MESSAGE = 'Must call the provided initialization method`init` method before using hooks.'; @@ -153,7 +153,7 @@ export function useConnectWallet() { isConnected: isConnected, loginError: stateFromStore.loginError, loginOnChainStatus: stateFromStore.loginOnChainStatus, - approvedGuardians: stateFromStore.approveGuardians, + approvedGuardians: stateFromStore.approvedGuardians, lock, getAccountByChainId, getWalletSyncIsCompleted, diff --git a/packages/starter/src/Demo/demo.tsx b/packages/starter/src/Demo/demo.tsx index ef7ed1e..a07490b 100644 --- a/packages/starter/src/Demo/demo.tsx +++ b/packages/starter/src/Demo/demo.tsx @@ -24,7 +24,7 @@ const GRAPHQL_SERVER = 'https://dapp-aa-portkey-test.portkey.finance/aefinder-v2/api/app/graphql/portkey'; const CONNECT_SERVER = 'https://auth-aa-portkey-test.portkey.finance'; const SERVICE_SERVER = 'https://aa-portkey-test.portkey.finance'; -const TELEGRAM_BOT_ID = '7781140664'; +const TELEGRAM_BOT_ID = '8158866605'; const didConfig = { graphQLUrl: GRAPHQL_SERVER, @@ -151,6 +151,7 @@ const App: React.FC = () => { const bridgeAPI = init(config); return ( + 123 diff --git a/packages/wallets/portkey-aa/src/index.ts b/packages/wallets/portkey-aa/src/index.ts index c5fd44d..a24a98d 100644 --- a/packages/wallets/portkey-aa/src/index.ts +++ b/packages/wallets/portkey-aa/src/index.ts @@ -435,7 +435,7 @@ export class PortkeyAAWallet extends BaseWalletAdapter { methodName, args, sendOptions, - guardiansApproved = [], + approvedGuardians = [], }: ISendOrViewAdapter) { const didWalletInfo = this._wallet!.extraInfo?.portkeyInfo; @@ -449,7 +449,7 @@ export class PortkeyAAWallet extends BaseWalletAdapter { const originChainId = didWalletInfo.chainId; // use amount from result of managerApprove not from params // dapp user may change amount at pop-up - const { amount, guardiansApproved, symbol } = (await managerApprove({ + const { amount, approvedGuardians, symbol } = (await managerApprove({ originChainId, targetChainId: chainId, caHash: didWalletInfo.caInfo?.caHash, @@ -466,7 +466,7 @@ export class PortkeyAAWallet extends BaseWalletAdapter { { caHash: didWalletInfo.caInfo?.caHash, ...args, - guardiansApproved, + approvedGuardians, amount, symbol, }, @@ -474,7 +474,7 @@ export class PortkeyAAWallet extends BaseWalletAdapter { ); } else { const params = { - guardiansApproved: guardiansApproved, + approvedGuardians: approvedGuardians, caHash: didWalletInfo.caInfo?.caHash, contractAddress: contractAddress, methodName: methodName, @@ -512,7 +512,7 @@ export class PortkeyAAWallet extends BaseWalletAdapter { methodName, args, sendOptions, - guardiansApproved = [], + approvedGuardians = [], }: ICallContractParams) { const enableAcceleration = this._config.enableAcceleration; if (!this._wallet) { @@ -553,7 +553,7 @@ export class PortkeyAAWallet extends BaseWalletAdapter { const finalChainId = chainId || this._config.chainId; const contract = await this.getContract(finalChainId); const adapterProps = { - guardiansApproved, + approvedGuardians, caContract: contract, chainId: finalChainId, contractAddress,