From f45be65cf57ee587eae6856fed954e83793b3d43 Mon Sep 17 00:00:00 2001 From: thomasRalee Date: Wed, 18 Sep 2024 16:24:54 +0800 Subject: [PATCH] chore: magic oauth --- .../wallet-strategy/strategies/Magic.ts | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/packages/wallet-ts/src/strategies/wallet-strategy/strategies/Magic.ts b/packages/wallet-ts/src/strategies/wallet-strategy/strategies/Magic.ts index ec4eef74a..a7ad4ed69 100644 --- a/packages/wallet-ts/src/strategies/wallet-strategy/strategies/Magic.ts +++ b/packages/wallet-ts/src/strategies/wallet-strategy/strategies/Magic.ts @@ -115,7 +115,7 @@ export default class Magic async connectViaOauth(provider: MagicProvider) { return (this.magicWallet.oauth2 as any).loginWithRedirect({ provider: provider, - redirectURI: window.location.href, + redirectURI: window.location.origin, }) } @@ -137,27 +137,30 @@ export default class Magic if (!provider) { try { await (this.magicWallet.oauth2 as any).getRedirectResult() - const { publicAddress } = await this.magicWallet.user.getInfo() - - return [publicAddress || ''] - } catch (e: any) { + } catch { // fail silently } - } else { - try { - const { publicAddress } = await this.magicWallet.user.getInfo() + } - return [publicAddress || ''] - } catch (e: unknown) { - throw new WalletException(new Error((e as any).message), { - code: UnspecifiedErrorCode, - type: ErrorType.WalletError, - contextModule: WalletAction.GetAccounts, - }) + try { + const { publicAddress } = await this.magicWallet.user.getInfo() + + if (!publicAddress?.startsWith('inj')) { + const address = await (this.magicWallet.cosmos as any).changeAddress( + 'inj', + ) + + return [address || ''] } - } - return Promise.resolve([]) + return [publicAddress || ''] + } catch (e: unknown) { + throw new WalletException(new Error((e as any).message), { + code: UnspecifiedErrorCode, + type: ErrorType.WalletError, + contextModule: WalletAction.GetAccounts, + }) + } } // eslint-disable-next-line class-methods-use-this