Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Replace dApp connection list item with static UI component #6413

Draft
wants to merge 1 commit into
base: x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@ import backgroundApiProxy from '@onekeyhq/kit/src/background/instance/background
import {
AccountSelectorProviderMirror,
NetworkSelectorTriggerDappConnection,
NetworkSelectorTriggerDappConnectionCmp,
} from '@onekeyhq/kit/src/components/AccountSelector';
import { AccountSelectorTriggerDappConnection } from '@onekeyhq/kit/src/components/AccountSelector/AccountSelectorTrigger/AccountSelectorTriggerDApp';
import {
AccountSelectorTriggerDappConnection,
AccountSelectorTriggerDappConnectionCmp,
} from '@onekeyhq/kit/src/components/AccountSelector/AccountSelectorTrigger/AccountSelectorTriggerDApp';
import useDappQuery from '@onekeyhq/kit/src/hooks/useDappQuery';
import { usePromiseResult } from '@onekeyhq/kit/src/hooks/usePromiseResult';
import type { IAccountSelectorAvailableNetworksMap } from '@onekeyhq/kit/src/states/jotai/contexts/accountSelector';
import {
useAccountSelectorActions,
useAccountSelectorSyncLoadingAtom,
} from '@onekeyhq/kit/src/states/jotai/contexts/accountSelector';
import type { IDBIndexedAccount } from '@onekeyhq/kit-bg/src/dbs/local/types';
import { getNetworkImplsFromDappScope } from '@onekeyhq/shared/src/background/backgroundUtils';
import { ETranslations } from '@onekeyhq/shared/src/locale';
import platformEnv from '@onekeyhq/shared/src/platformEnv';
import accountUtils from '@onekeyhq/shared/src/utils/accountUtils';
import timerUtils from '@onekeyhq/shared/src/utils/timerUtils';
import { EAccountSelectorSceneName } from '@onekeyhq/shared/types';

Expand Down Expand Up @@ -282,25 +288,6 @@ function DAppAccountListStandAloneItem({
);
}

function DAppAccountListStandAloneItemForHomeScene() {
const intl = useIntl();
return (
<YStack gap="$2" testID="DAppAccountListStandAloneItem">
<SizableText size="$headingMd" color="$text">
{intl.formatMessage({ id: ETranslations.global_accounts })}
</SizableText>
<AccountSelectorProviderMirror
config={{
sceneName: EAccountSelectorSceneName.home,
}}
enabledNum={[0]}
>
<DAppAccountListItem initFromHome={false} num={0} readonly />
</AccountSelectorProviderMirror>
</YStack>
);
}

function WalletConnectAccountTriggerList({
sceneUrl,
sessionAccountsInfo,
Expand Down Expand Up @@ -356,9 +343,75 @@ function WalletConnectAccountTriggerList({
);
}

const StaticDAppConnectionInfoAloneItem = ({
networkId,
accountId,
}: {
networkId: string;
accountId: string;
}) => {
const intl = useIntl();
const { result, isLoading } = usePromiseResult(async () => {
const [network, account, wallet] = await Promise.all([
backgroundApiProxy.serviceNetwork.getNetworkSafe({
networkId,
}),
backgroundApiProxy.serviceAccount.getAccount({
accountId,
networkId,
}),
backgroundApiProxy.serviceAccount.getWallet({
walletId: accountUtils.getWalletIdFromAccountId({ accountId }),
}),
]);
let indexedAccount: IDBIndexedAccount | undefined;
if (account.indexedAccountId) {
indexedAccount =
await backgroundApiProxy.serviceAccount.getIndexedAccount({
id: account.indexedAccountId,
});
}

originalix marked this conversation as resolved.
Show resolved Hide resolved
return { network, account, wallet, indexedAccount };
}, [networkId, accountId]);
return (
<YStack gap="$2">
<SizableText size="$headingMd" color="$text">
{intl.formatMessage({ id: ETranslations.global_accounts })}
</SizableText>
<YGroup
bg="$bg"
borderRadius="$3"
borderColor="$borderSubdued"
borderWidth={StyleSheet.hairlineWidth}
separator={<Divider />}
disabled
overflow="hidden"
>
<YGroup.Item>
<NetworkSelectorTriggerDappConnectionCmp
isLoading={isLoading}
network={result?.network}
triggerDisabled
/>
</YGroup.Item>
<YGroup.Item>
<AccountSelectorTriggerDappConnectionCmp
isLoading={isLoading}
account={result?.account}
wallet={result?.wallet}
indexedAccount={result?.indexedAccount}
triggerDisabled
/>
</YGroup.Item>
</YGroup>
</YStack>
);
originalix marked this conversation as resolved.
Show resolved Hide resolved
};

export {
DAppAccountListItem,
DAppAccountListStandAloneItem,
DAppAccountListStandAloneItemForHomeScene,
WalletConnectAccountTriggerList,
StaticDAppConnectionInfoAloneItem,
};
102 changes: 7 additions & 95 deletions packages/kit/src/views/DAppConnection/pages/SignMessageModal.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
import { useCallback, useEffect, useMemo, useState } from 'react';

import { useIntl } from 'react-intl';
import { StyleSheet } from 'react-native';

import type { IAlertProps } from '@onekeyhq/components';
import {
Divider,
Page,
SizableText,
YGroup,
YStack,
} from '@onekeyhq/components';
import { Page } from '@onekeyhq/components';
import type { IUnsignedMessage } from '@onekeyhq/core/src/types';
import { NetworkSelectorTriggerDappConnectionCmp } from '@onekeyhq/kit/src/components/AccountSelector';
import { AccountSelectorTriggerDappConnectionCmp } from '@onekeyhq/kit/src/components/AccountSelector/AccountSelectorTrigger/AccountSelectorTriggerDApp';
import type { IDBIndexedAccount } from '@onekeyhq/kit-bg/src/dbs/local/types';
import { ETranslations } from '@onekeyhq/shared/src/locale';
import platformEnv from '@onekeyhq/shared/src/platformEnv';
import {
isPrimaryTypeOrderSign,
isPrimaryTypePermitSign,
} from '@onekeyhq/shared/src/signMessage';
import accountUtils from '@onekeyhq/shared/src/utils/accountUtils';
import {
validateSignMessageData,
validateTypedSignMessageDataV1,
Expand All @@ -36,7 +25,7 @@ import backgroundApiProxy from '../../../background/instance/backgroundApiProxy'
import useDappApproveAction from '../../../hooks/useDappApproveAction';
import useDappQuery from '../../../hooks/useDappQuery';
import { usePromiseResult } from '../../../hooks/usePromiseResult';
import { DAppAccountListStandAloneItem } from '../components/DAppAccountList';
import { StaticDAppConnectionInfoAloneItem } from '../components/DAppAccountList';
import { DAppSignMessageContent } from '../components/DAppRequestContent';
import {
DAppRequestFooter,
Expand All @@ -46,87 +35,14 @@ import { useRiskDetection } from '../hooks/useRiskDetection';

import DappOpenModalPage from './DappOpenModalPage';

const WalletAccountListItem = ({
networkId,
accountId,
}: {
networkId: string;
accountId: string;
}) => {
const intl = useIntl();
const { result, isLoading } = usePromiseResult(async () => {
const [network, account, wallet] = await Promise.all([
backgroundApiProxy.serviceNetwork.getNetworkSafe({
networkId,
}),
backgroundApiProxy.serviceAccount.getAccount({
accountId,
networkId,
}),
backgroundApiProxy.serviceAccount.getWallet({
walletId: accountUtils.getWalletIdFromAccountId({ accountId }),
}),
]);
let indexedAccount: IDBIndexedAccount | undefined;
if (account.indexedAccountId) {
indexedAccount =
await backgroundApiProxy.serviceAccount.getIndexedAccount({
id: account.indexedAccountId,
});
}

return { network, account, wallet, indexedAccount };
}, [networkId, accountId]);
return (
<YStack gap="$2">
<SizableText size="$headingMd" color="$text">
{intl.formatMessage({ id: ETranslations.global_accounts })}
</SizableText>
<YGroup
bg="$bg"
borderRadius="$3"
borderColor="$borderSubdued"
borderWidth={StyleSheet.hairlineWidth}
separator={<Divider />}
disabled
overflow="hidden"
>
<YGroup.Item>
<NetworkSelectorTriggerDappConnectionCmp
isLoading={isLoading}
network={result?.network}
triggerDisabled
/>
</YGroup.Item>
<YGroup.Item>
<AccountSelectorTriggerDappConnectionCmp
isLoading={isLoading}
account={result?.account}
wallet={result?.wallet}
indexedAccount={result?.indexedAccount}
triggerDisabled
/>
</YGroup.Item>
</YGroup>
</YStack>
);
};

function SignMessageModal() {
const intl = useIntl();
const [isLoading, setIsLoading] = useState(false);
const {
$sourceInfo,
unsignedMessage,
accountId,
networkId,
walletInternalSign,
} = useDappQuery<{
const { $sourceInfo, unsignedMessage, accountId, networkId } = useDappQuery<{
unsignedMessage: IUnsignedMessage;
accountId: string;
networkId: string;
indexedAccountId: string;
walletInternalSign?: boolean;
}>();

const dappApprove = useDappApproveAction({
Expand Down Expand Up @@ -291,14 +207,10 @@ function SignMessageModal() {
signMessageAlertProps={getSignMessageAlertProps()}
fullScreen={!platformEnv.isNativeIOS}
>
{walletInternalSign ? (
<WalletAccountListItem
accountId={accountId}
networkId={networkId}
/>
) : (
<DAppAccountListStandAloneItem readonly />
)}
<StaticDAppConnectionInfoAloneItem
accountId={accountId}
networkId={networkId}
/>
<DAppSignMessageContent unsignedMessage={unsignedMessage} />
</DAppRequestLayout>
</Page.Body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import type {
} from '@onekeyhq/shared/src/routes';
import { EDAppModalPageStatus } from '@onekeyhq/shared/types/dappConnection';

import {
DAppAccountListStandAloneItem,
DAppAccountListStandAloneItemForHomeScene,
} from '../../../DAppConnection/components/DAppAccountList';
import { StaticDAppConnectionInfoAloneItem } from '../../../DAppConnection/components/DAppAccountList';
import { DAppRequestedPermissionContent } from '../../../DAppConnection/components/DAppRequestContent';
import {
DAppRequestFooter,
Expand Down Expand Up @@ -236,11 +233,10 @@ function LnurlAuthModal() {
origin={origin ?? ''}
urlSecurityInfo={urlSecurityInfo}
>
{isSendFlow ? (
<DAppAccountListStandAloneItemForHomeScene />
) : (
<DAppAccountListStandAloneItem readonly />
)}
<StaticDAppConnectionInfoAloneItem
accountId={accountId}
networkId={networkId}
/>
{renderRequestPermissions()}
</DAppRequestLayout>
</Page.Body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ import type {
import { EDAppModalPageStatus } from '@onekeyhq/shared/types/dappConnection';
import type { ILNURLPaymentInfo } from '@onekeyhq/shared/types/lightning';

import {
DAppAccountListStandAloneItem,
DAppAccountListStandAloneItemForHomeScene,
} from '../../../DAppConnection/components/DAppAccountList';
import { StaticDAppConnectionInfoAloneItem } from '../../../DAppConnection/components/DAppAccountList';
import {
DAppRequestFooter,
DAppRequestLayout,
Expand Down Expand Up @@ -218,11 +215,10 @@ function LnurlPayRequestModal() {
origin={origin ?? ''}
urlSecurityInfo={urlSecurityInfo}
>
{routeParams.isSendFlow ? (
<DAppAccountListStandAloneItemForHomeScene />
) : (
<DAppAccountListStandAloneItem readonly />
)}
<StaticDAppConnectionInfoAloneItem
accountId={accountId}
networkId={networkId}
/>
<LNSendPaymentForm
accountId={accountId}
networkId={networkId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import type {
} from '@onekeyhq/shared/src/routes';
import { EDAppModalPageStatus } from '@onekeyhq/shared/types/dappConnection';

import {
DAppAccountListStandAloneItem,
DAppAccountListStandAloneItemForHomeScene,
} from '../../../DAppConnection/components/DAppAccountList';
import { StaticDAppConnectionInfoAloneItem } from '../../../DAppConnection/components/DAppAccountList';
import {
DAppRequestFooter,
DAppRequestLayout,
Expand Down Expand Up @@ -162,11 +159,10 @@ function LnurlWithdrawModal() {
origin={origin ?? ''}
urlSecurityInfo={urlSecurityInfo}
>
{isSendFlow ? (
<DAppAccountListStandAloneItemForHomeScene />
) : (
<DAppAccountListStandAloneItem readonly />
)}
<StaticDAppConnectionInfoAloneItem
accountId={accountId}
networkId={networkId}
/>
<LNMakeInvoiceForm
accountId={accountId}
networkId={networkId}
Expand Down
Loading