diff --git a/apps/mobile/src/components/AccountSwitcher/AccountsPanel.tsx b/apps/mobile/src/components/AccountSwitcher/AccountsPanel.tsx index 74c0db8b7..b9c509c31 100644 --- a/apps/mobile/src/components/AccountSwitcher/AccountsPanel.tsx +++ b/apps/mobile/src/components/AccountSwitcher/AccountsPanel.tsx @@ -80,7 +80,7 @@ AccountSwitcherAopProps<{ containerStyle?: StyleProp; linearContainerProps?: React.ComponentProps; onSwitchSceneAccount?: (ctx: { - switchAction: () => void; + switchAction: () => Promise; sceneAccount: Account; }) => void; }>) { @@ -149,12 +149,12 @@ AccountSwitcherAopProps<{ >( async account => { if (typeof onSwitchSceneAccount === 'function') { - const switchAction = () => { - switchSceneAction(account); + const switchAction = async () => { + await switchSceneAction(account); }; onSwitchSceneAccount({ sceneAccount: account, switchAction }); } else { - switchSceneAction(account); + await switchSceneAction(account); } }, [switchSceneAction, onSwitchSceneAccount], diff --git a/apps/mobile/src/components/AccountSwitcher/Modal.tsx b/apps/mobile/src/components/AccountSwitcher/Modal.tsx index c0298c6af..8597aff98 100644 --- a/apps/mobile/src/components/AccountSwitcher/Modal.tsx +++ b/apps/mobile/src/components/AccountSwitcher/Modal.tsx @@ -127,10 +127,8 @@ const getModalStyle = createGetStyles2024(ctx => { export function AccountSwitcherModalInDappWebView({ activeDappId, forScene, - inScreen = false, }: AccountSwitcherAopProps<{ activeDappId?: DappInfo['origin']; - inScreen?: boolean; }>) { const { isVisible, toggleSceneVisible } = useAccountSceneVisible(forScene); @@ -183,10 +181,10 @@ export function AccountSwitcherModalInDappWebView({ { + onSwitchSceneAccount={async ctx => { if (!activeDappId) return; setDappCurrentAccount(activeDappId, ctx.sceneAccount); - ctx.switchAction(); + await ctx.switchAction(); }} /> diff --git a/apps/mobile/src/components/WebView/DappWebViewControl2/WebViewHeaderRight.tsx b/apps/mobile/src/components/WebView/DappWebViewControl2/WebViewHeaderRight.tsx index ce4e8803a..7325e33f3 100644 --- a/apps/mobile/src/components/WebView/DappWebViewControl2/WebViewHeaderRight.tsx +++ b/apps/mobile/src/components/WebView/DappWebViewControl2/WebViewHeaderRight.tsx @@ -1,7 +1,7 @@ import TouchableView from '@/components/Touchable/TouchableView'; import { createGetStyles2024 } from '@/utils/styles'; import { ScreenLayouts2 } from '@/constant/layout'; -import { useWalletBrandLogo } from '@/hooks/account'; +import { useCurrentAccount, useWalletBrandLogo } from '@/hooks/account'; import { useAccountSceneVisible } from '@/components/AccountSwitcher/hooks'; import { DappInfo } from '@/core/services/dappService'; @@ -13,12 +13,7 @@ import { import { useEffect } from 'react'; import { WalletIcon } from '@/components2024/WalletIcon/WalletIcon'; -export function WebViewHeaderRight({ - activeDapp, -}: { - activeDapp?: DappInfo | null; -}) { - // const { currentAccount } = useCurrentAccount({ disableAutoFetch: true }); +export function WebViewHeaderRight() { const { finalSceneCurrentAccount } = useSceneAccountInfo({ forScene: '@ActiveDappWebViewModal', }); diff --git a/apps/mobile/src/screens/Dapps/DappsScreen/components/WebViewsStub.tsx b/apps/mobile/src/screens/Dapps/DappsScreen/components/WebViewsStub.tsx index 40dd912e9..cedeed081 100644 --- a/apps/mobile/src/screens/Dapps/DappsScreen/components/WebViewsStub.tsx +++ b/apps/mobile/src/screens/Dapps/DappsScreen/components/WebViewsStub.tsx @@ -427,7 +427,7 @@ export function OpenedDappWebViewStub() { allowsInlineMediaPlayback: true, disableJsPromptLike: !isActiveDapp, }} - headerRight={} + headerRight={} onPressHeaderLeftClose={ctx => { hideDappSheetModal(ctx); }} diff --git a/apps/mobile/src/screens/Dapps/hooks/useDappView.ts b/apps/mobile/src/screens/Dapps/hooks/useDappView.ts index 544e58eab..63ac8ebff 100644 --- a/apps/mobile/src/screens/Dapps/hooks/useDappView.ts +++ b/apps/mobile/src/screens/Dapps/hooks/useDappView.ts @@ -156,14 +156,9 @@ const useDappLastUsedAccount = () => { (dapp: DappInfo) => { if (!dapp.currentAccount) return; - if (!isSameAccount(dapp.currentAccount, finalSceneCurrentAccount)) { - switchSceneCurrentAccount( - '@ActiveDappWebViewModal', - dapp.currentAccount, - ); - } + switchSceneCurrentAccount('@ActiveDappWebViewModal', dapp.currentAccount); }, - [switchSceneCurrentAccount, finalSceneCurrentAccount], + [switchSceneCurrentAccount], ); const inactivate = useCallback(() => { @@ -171,6 +166,7 @@ const useDappLastUsedAccount = () => { }, [switchSceneCurrentAccount]); return { + finalSceneCurrentAccount, activate, inactivate, }; @@ -199,13 +195,9 @@ export function useOpenDappView() { globalSetActiveDappState({ dappOrigin: origin }); _setActiveDappOrigin(origin); - if (!origin) { - inactivate(); - } else if (dapps[origin]) { - activate(dapps[origin]); - } + if (!origin) inactivate(); }, - [_setActiveDappOrigin, activate, inactivate, dapps], + [_setActiveDappOrigin, inactivate], ); const { toggleShowSheetModal } = useActiveViewSheetModalRefs(); @@ -408,6 +400,8 @@ export function useOpenDappView() { setActiveDappOrigin(item.origin); } + activate(dapps[item.origin]); + return true; }, [ @@ -416,6 +410,7 @@ export function useOpenDappView() { addDapp, setActiveDappOrigin, toggleShowSheetModal, + activate, ], );