From 7e7caec698ef1cfd626b3e70340d0d8d4159b1ae Mon Sep 17 00:00:00 2001 From: thomasRalee Date: Mon, 16 Sep 2024 18:13:34 +0800 Subject: [PATCH] feat: magic --- layer/store/wallet.ts | 40 +++++++++++++++++++-------------- layer/utils/constant/setup.ts | 1 + layer/wallet/wallet-strategy.ts | 10 +++------ 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/layer/store/wallet.ts b/layer/store/wallet.ts index d4ae3c0..74165aa 100644 --- a/layer/store/wallet.ts +++ b/layer/store/wallet.ts @@ -238,9 +238,9 @@ export const useSharedWalletStore = defineStore('sharedWallet', { walletStore.walletConnectStatus = WalletConnectStatus.idle await walletStrategy.setWallet(walletStore.wallet) - // if (walletStore.wallet === Wallet.Magic && !walletStore.isUserConnected) { - // await walletStore.connectMagic() - // } + if (walletStore.wallet === Wallet.Magic && !walletStore.isUserConnected) { + await walletStore.connectMagic() + } if (walletStore.isAutoSignEnabled) { walletStore.connectWallet(Wallet.PrivateKey, { @@ -675,24 +675,30 @@ export const useSharedWalletStore = defineStore('sharedWallet', { await walletStore.connectWallet(Wallet.Magic) - const addresses = await getAddresses({ email, provider }) + try { + const addresses = await getAddresses({ email, provider }) - if (!addresses.length) { - return - } + if (!addresses.length) { + return + } - const [address] = addresses - const session = await walletStrategy.getSessionOrConfirm(address) + const [address] = addresses + const session = await walletStrategy.getSessionOrConfirm(address) - walletStore.$patch({ - address, - addresses, - addressConfirmation: await walletStrategy.getSessionOrConfirm(address), - injectiveAddress: address, - session - }) + walletStore.$patch({ + address, + addresses, + addressConfirmation: await walletStrategy.getSessionOrConfirm( + address + ), + injectiveAddress: address, + session + }) - await walletStore.onConnect() + await walletStore.onConnect() + } catch { + walletStore.walletConnectStatus = WalletConnectStatus.idle + } }, async connectAddress(injectiveAddress: string) { diff --git a/layer/utils/constant/setup.ts b/layer/utils/constant/setup.ts index c888cdd..95bd14e 100644 --- a/layer/utils/constant/setup.ts +++ b/layer/utils/constant/setup.ts @@ -133,6 +133,7 @@ export const PROXY_DETECTION_API_KEY = import.meta.env.VITE_PROXY_DETECTION_API_KEY || '' export const HOTJAR_KEY = import.meta.env.VITE_HOTJAR_KEY_DEV as string export const MIXPANEL_KEY = import.meta.env.VITE_MIXPANEL_KEY || '' +export const MAGIC_APK_KEY = import.meta.env.VITE_MAGIC_APK_KEY || '' export const GOOGLE_MAPS_KEY = import.meta.env.VITE_GOOGLE_MAPS_KEY || '' export const VPN_CHECKS_ENABLED: boolean = diff --git a/layer/wallet/wallet-strategy.ts b/layer/wallet/wallet-strategy.ts index 5c84384..8cfc968 100644 --- a/layer/wallet/wallet-strategy.ts +++ b/layer/wallet/wallet-strategy.ts @@ -3,6 +3,7 @@ import { CHAIN_ID, IS_MAINNET, ALCHEMY_KEY, + MAGIC_APK_KEY, ETHEREUM_CHAIN_ID, ALCHEMY_SEPOLIA_KEY } from './../utils/constant' @@ -14,11 +15,6 @@ import { WALLET_CONNECT_PROJECT_ID } from './../utils/constant' -console.log(ENDPOINTS.rpc) - -const HUNTER_API = 'pk_live_8D40A7E251F283ED' -const INJECTIVE_API = 'pk_live_E1CB10CF489E800D' - export const walletStrategy = new WalletStrategy({ chainId: CHAIN_ID, ethereumOptions: { @@ -28,8 +24,8 @@ export const walletStrategy = new WalletStrategy({ options: { metadata: { magic: { - rpcEndpoint: ENDPOINTS.rpc as string, - apiKey: INJECTIVE_API + apiKey: MAGIC_APK_KEY as string, + rpcEndpoint: ENDPOINTS.rpc as string }, name: APP_NAME, url: APP_BASE_URL,