From eff2fe47802caa95ccc846a5c4a378ce1861eda3 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Sun, 20 Jun 2021 13:51:45 +0800 Subject: [PATCH] fix: firefox does not connect correctly close jira-42 (#3413) * fix: firefox does not connect correctly close jira-42 * Update packages/maskbook/src/extension/background-script/EthereumServices/send.ts Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com> --- .../options-page/DashboardComponents/ProfileBox.tsx | 13 ++++++++++--- packages/maskbook/src/plugins/Wallet/settings.ts | 4 +++- packages/maskbook/src/social-network/ui.ts | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/maskbook/src/extension/options-page/DashboardComponents/ProfileBox.tsx b/packages/maskbook/src/extension/options-page/DashboardComponents/ProfileBox.tsx index 06b450ea75fd..60f9a4d2e630 100644 --- a/packages/maskbook/src/extension/options-page/DashboardComponents/ProfileBox.tsx +++ b/packages/maskbook/src/extension/options-page/DashboardComponents/ProfileBox.tsx @@ -1,5 +1,5 @@ import type { Persona } from '../../../database' -import { definedSocialNetworkUIs, loadSocialNetworkUI } from '../../../social-network' +import { definedSocialNetworkUIs, loadSocialNetworkUI, loadSocialNetworkUISync } from '../../../social-network' import ProviderLine, { ProviderLineProps } from './ProviderLine' import { currentSetupGuideStatus } from '../../../settings/settings' @@ -11,6 +11,7 @@ import { delay } from '../../../utils/utils' import { SetupGuideStep } from '../../../components/InjectedComponents/SetupGuide' import { Flags } from '../../../utils/flags' import { requestSNSAdaptorPermission } from '../../../social-network/utils/permissions' +import { useEffect } from 'react' interface ProfileBoxProps { persona: Persona | null @@ -35,8 +36,13 @@ export default function ProfileBox({ persona, ProviderLineProps }: ProfileBoxPro .filter((x) => x) const [detachProfile, , setDetachProfile] = useModal(DashboardPersonaUnlinkConfirmDialog) + useEffect(() => { + providers.forEach((provider) => loadSocialNetworkUI(provider.internalName)) + }, [providers]) + const onConnect = async (provider: typeof providers[0]) => { - const ui = await loadSocialNetworkUI(provider.internalName) + const ui = loadSocialNetworkUISync(provider.internalName) + if (!ui) throw new Error('This process must be sync') // TODO: what if it does not have a (single?) home page? (e.g. mastdon) // TODO: maybe add a new action "onConnect"? const home = ui.utils.getHomePage?.() @@ -65,7 +71,8 @@ export default function ProfileBox({ persona, ProviderLineProps }: ProfileBoxPro key={index} onAction={() => (provider.connected ? onDisconnect(provider) : onConnect(provider))} {...provider} - {...ProviderLineProps}> + {...ProviderLineProps} + /> ))} {detachProfile} diff --git a/packages/maskbook/src/plugins/Wallet/settings.ts b/packages/maskbook/src/plugins/Wallet/settings.ts index 15f8ba9efac6..8fc0e00217a8 100644 --- a/packages/maskbook/src/plugins/Wallet/settings.ts +++ b/packages/maskbook/src/plugins/Wallet/settings.ts @@ -120,4 +120,6 @@ export const currentGasNowSettings = createGlobalSettings( (a: GasNow | null, b: GasNow | null) => isEqual(a, b), ) -connectGasNow() +try { + connectGasNow() +} catch {} diff --git a/packages/maskbook/src/social-network/ui.ts b/packages/maskbook/src/social-network/ui.ts index 785b6a54f84f..6315ee152bd1 100644 --- a/packages/maskbook/src/social-network/ui.ts +++ b/packages/maskbook/src/social-network/ui.ts @@ -162,3 +162,7 @@ export async function loadSocialNetworkUI(identifier: string): Promise