From 27fbc96839dcef358731182fca5d318803686f8f Mon Sep 17 00:00:00 2001 From: ChenWei Date: Fri, 20 Sep 2024 19:07:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20wallet=20=E6=96=B0=E5=A2=9E=E6=82=AC?= =?UTF-8?q?=E6=B5=AE=E6=8C=89=E9=92=AE=E9=85=8D=E7=BD=AE+=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E9=BB=98=E8=AE=A4chain+=E5=A2=9E=E5=8A=A0=E5=88=87?= =?UTF-8?q?=E6=8D=A2chain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xterio-wallet/README.md | 8 +++++++- xterio-wallet/src/common/utils/const.ts | 4 ++-- xterio-wallet/src/contexts/index.tsx | 22 ++++++++++++++-------- xterio-wallet/src/contexts/pnWallet.ts | 3 ++- xterio-wallet/src/interfaces/types.ts | 2 ++ 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/xterio-wallet/README.md b/xterio-wallet/README.md index 82ee2a0..a8e3960 100644 --- a/xterio-wallet/README.md +++ b/xterio-wallet/README.md @@ -31,7 +31,11 @@ const config: IXterioWalletContextProps = { client_id:'', client_secret: '', redirect_uri:'', - env: Env.Dev + env: Env.Dev, + //是否在wallet内部初始化auth,default: true + enableAuthInit = true, + //是否显示快捷按钮wallet,default: false + showOpenWalletIcon = false, } createRoot(document.getElementById('root')!).render( @@ -179,6 +183,8 @@ aa wallet connection status #### `signMessage()` +#### `switchChain(_id?: number)` + ### 3.3 `useXterioTransaction(contract?, funcName?)` #### `state` diff --git a/xterio-wallet/src/common/utils/const.ts b/xterio-wallet/src/common/utils/const.ts index cbbf55f..d5cc4d0 100644 --- a/xterio-wallet/src/common/utils/const.ts +++ b/xterio-wallet/src/common/utils/const.ts @@ -14,13 +14,13 @@ export const EnvBaseURLConst: Record = { PN_APP_ID: '40ad8524-f844-496d-8de2-50a8a322d6ba' }, [Env.Staging]: { - PN_CHAIN_ID: 11155111, + PN_CHAIN_ID: 1637450, PN_PROJECT_ID: '6b4a0cd5-32c3-4641-a809-2bd9ac7a175f', PN_CLIENT_KEY: 'cU43QlI3GMvPqW4Ep0Z8BK4mXDkaHd8kgpQlr8NG', PN_APP_ID: '9cd6a325-3082-4e98-8803-82a66cd9e86f' }, [Env.Production]: { - PN_CHAIN_ID: 56, + PN_CHAIN_ID: 112358, PN_PROJECT_ID: 'fab00091-f966-437f-8ae9-12aa495f2828', PN_CLIENT_KEY: 'cif8thrddJ9Iz46tecZ9UiEQmjxRaKy42AuutAZj', PN_APP_ID: '926a55ad-1aad-4147-901e-ee66ff288e74' diff --git a/xterio-wallet/src/contexts/index.tsx b/xterio-wallet/src/contexts/index.tsx index d8782bc..2371d2f 100644 --- a/xterio-wallet/src/contexts/index.tsx +++ b/xterio-wallet/src/contexts/index.tsx @@ -15,7 +15,7 @@ const initState = { disconnectWallet: () => {}, obtainWallet: () => {} } -interface IWalletContextState extends Pick { +interface IWalletContextState extends Pick { userinfo: IUserInfo | undefined isLogin: boolean login(mode?: LoginType): Promise @@ -23,7 +23,7 @@ interface IWalletContextState extends Pick { const [mounted, setMounted] = useState() @@ -47,6 +48,7 @@ const WalletContextProvider: React.FC { - log('connect wallet') - await connectPnEoAAndAA(XterioAuthTokensManager.idToken) - }, [connectPnEoAAndAA]) + const connectWallet = useCallback( + async (chainId?: number) => { + log('connect wallet') + await connectPnEoAAndAA(XterioAuthTokensManager.idToken, chainId) + }, + [connectPnEoAAndAA] + ) const disconnectWallet = useCallback(async () => { log('disconnect wallet') @@ -194,11 +199,12 @@ const WalletContextProvider: React.FC {children} - {!!isPnLogin && ( + {showOpenWalletIcon && !!isPnLogin && (
Wallet
diff --git a/xterio-wallet/src/contexts/pnWallet.ts b/xterio-wallet/src/contexts/pnWallet.ts index 9fbe7e2..ddbc6f4 100644 --- a/xterio-wallet/src/contexts/pnWallet.ts +++ b/xterio-wallet/src/contexts/pnWallet.ts @@ -48,7 +48,7 @@ const supportChains: [Chain, ...Chain[]] = [ ] export const usePnWallet = (init_address?: string, _env?: Env): IPnWalletState => { - const { chainInfo, address, provider, signMessage, signTypedData } = useEthereum() + const { chainInfo, address, provider, signMessage, signTypedData, switchChain } = useEthereum() const { connect, connected, disconnect } = useConnect() const { erc4337, setERC4337 } = useCustomize() const { userInfo, getWalletIFrame: getWalletDom, openWallet: _openWallet } = useAuthCore() @@ -200,6 +200,7 @@ export const usePnWallet = (init_address?: string, _env?: Env): IPnWalletState = connectPnEoAAndAA, getWalletIFrame, openPnWallet, + switchChain, eoaAddress: address || init_address || '', pnAAWalletAddress, pnUserInfo: userInfo, diff --git a/xterio-wallet/src/interfaces/types.ts b/xterio-wallet/src/interfaces/types.ts index 9077ca8..7a15726 100644 --- a/xterio-wallet/src/interfaces/types.ts +++ b/xterio-wallet/src/interfaces/types.ts @@ -11,6 +11,7 @@ import type { Env, ISSoTokensParams } from '@xterio-sdk/auth' export interface IXterioWalletContextProps extends Partial { env?: Env enableAuthInit?: boolean + showOpenWalletIcon?: boolean } export type PnUserInfoType = import('@particle-network/auth-core').UserInfo | undefined @@ -28,6 +29,7 @@ export interface IPnWalletState { _eoaAddress?: string ) => Promise<{ aaAddress?: string; eoaAddress?: string; name?: string; version?: string }> connectPnEoAAndAA: (jwt?: string, _chainId?: number) => Promise + switchChain: (id: number | PrefixedHexString) => Promise getWalletIFrame: () => HTMLIFrameElement | null openPnWallet: () => void signMessage: (message: PrefixedHexString | string, uniq?: boolean) => Promise