Skip to content

Commit

Permalink
OK-34496: Confirm passphrase use enter key (#6397)
Browse files Browse the repository at this point in the history
* fix: Add token without symbol

* chore: replace google icon

* feat: confirm passphrase by enter key
  • Loading branch information
originalix authored Dec 23, 2024
1 parent 44126d6 commit 99e4617
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 45 deletions.
19 changes: 14 additions & 5 deletions packages/kit-bg/src/services/ServiceToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class ServiceToken extends ServiceBase {
}

resp.data.data.tokens.data = resp.data.data.tokens.data.map((token) => ({
...this.mergeTokenMetadataWithCustomData({
...this.mergeTokenMetadataWithCustomDataSync({
token,
customTokens,
networkId,
Expand All @@ -207,7 +207,7 @@ class ServiceToken extends ServiceBase {

resp.data.data.riskTokens.data = resp.data.data.riskTokens.data.map(
(token) => ({
...this.mergeTokenMetadataWithCustomData({
...this.mergeTokenMetadataWithCustomDataSync({
token,
customTokens,
networkId,
Expand All @@ -220,7 +220,7 @@ class ServiceToken extends ServiceBase {

resp.data.data.smallBalanceTokens.data =
resp.data.data.smallBalanceTokens.data.map((token) => ({
...this.mergeTokenMetadataWithCustomData({
...this.mergeTokenMetadataWithCustomDataSync({
token,
customTokens,
networkId,
Expand Down Expand Up @@ -287,7 +287,16 @@ class ServiceToken extends ServiceBase {
return resp.data.data;
}

private mergeTokenMetadataWithCustomData<T extends IToken>({
@backgroundMethod()
async mergeTokenMetadataWithCustomData<T extends IToken>(params: {
token: T;
customTokens: IAccountToken[];
networkId: string;
}): Promise<T> {
return Promise.resolve(this.mergeTokenMetadataWithCustomDataSync(params));
}

private mergeTokenMetadataWithCustomDataSync<T extends IToken>({
token,
customTokens,
networkId,
Expand Down Expand Up @@ -521,7 +530,7 @@ class ServiceToken extends ServiceBase {
networkId,
});

tokenInfo = this.mergeTokenMetadataWithCustomData({
tokenInfo = this.mergeTokenMetadataWithCustomDataSync({
token: tokenInfo,
customTokens,
networkId,
Expand Down
73 changes: 38 additions & 35 deletions packages/kit/src/components/Hardware/Hardware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
useMedia,
} from '@onekeyhq/components';
import { ETranslations } from '@onekeyhq/shared/src/locale';
import platformEnv from '@onekeyhq/shared/src/platformEnv';

import { SHOW_CLOSE_ACTION_MIN_DURATION } from '../../provider/Container/HardwareUiStateContainer/constants';
import { isPassphraseValid } from '../../utils/passphraseUtils';
Expand Down Expand Up @@ -349,6 +350,42 @@ export function EnterPhase({
const [secureEntry1, setSecureEntry1] = useState(true);
const [secureEntry2, setSecureEntry2] = useState(true);

const handleSubmit = form.handleSubmit(async () => {
const values = form.getValues();
if (
!isSingleInput &&
(values.passphrase || '') !== (values.confirmPassphrase || '')
) {
Toast.error({
title: intl.formatMessage({
id: ETranslations.feedback_passphrase_not_matched,
}),
});
return;
}
const passphrase = values.passphrase || '';
onConfirm({ passphrase, save: true });
});

const handleKeyPress = useCallback(
async (event: KeyboardEvent) => {
if (event.key === 'Enter') {
void handleSubmit();
}
},
[handleSubmit],
);

useEffect(() => {
if (platformEnv.isRuntimeBrowser && typeof document !== 'undefined') {
document.addEventListener('keypress', handleKeyPress);
return () => {
document.removeEventListener('keypress', handleKeyPress);
};
}
return undefined;
}, [handleKeyPress]);

return (
<Stack>
<Stack pb="$5">
Expand Down Expand Up @@ -443,41 +480,7 @@ export function EnterPhase({
} as any
}
variant="primary"
onPress={form.handleSubmit(async () => {
const values = form.getValues();
if (
!isSingleInput &&
(values.passphrase || '') !== (values.confirmPassphrase || '')
) {
Toast.error({
title: intl.formatMessage({
id: ETranslations.feedback_passphrase_not_matched,
}),
});
return;
}
// allow empty passphrase
const passphrase = values.passphrase || '';
onConfirm({ passphrase, save: true });

// Dialog.show({
// icon: 'CheckboxSolid',
// title: 'Keep Your Wallet Accessible?',
// description:
// 'Save this wallet to your device to maintain access after the app is closed. Unsaved wallets will be removed automatically.',
// onConfirm: () => {
// onConfirm({ passphrase: values.passphrase, save: true });
// },
// onConfirmText: 'Save Wallet',
// confirmButtonProps: {
// variant: 'secondary',
// },
// onCancel: () => {
// onConfirm({ passphrase: values.passphrase, save: false });
// },
// onCancelText: "Don't Save",
// });
})}
onPress={handleSubmit}
>
{intl.formatMessage({ id: ETranslations.global_confirm })}
</Button>
Expand Down
10 changes: 9 additions & 1 deletion packages/kit/src/views/AssetList/hooks/useTokenManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ export function useTokenManagement({
allNetworkAccountId: isAllNetwork ? accountId : undefined,
}),
]);
const allTokens = [...tokenList.tokens, ...customTokens];
const allTokens = await Promise.all(
[...tokenList.tokens, ...customTokens].map((token) =>
backgroundApiProxy.serviceToken.mergeTokenMetadataWithCustomData({
token,
customTokens,
networkId,
}),
),
);
const uniqueTokens = allTokens.filter(
(token, index, self) =>
index ===
Expand Down
5 changes: 1 addition & 4 deletions packages/kit/src/views/Discovery/pages/SearchModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ function SearchModal() {
setSearchList([]);
return;
}
const logo =
await backgroundApiProxy.serviceDiscovery.buildWebsiteIconUrl(
'https://google.com',
);
const logo = 'https://uni.onekey-asset.com/static/logo/google.png';
setSearchList([
{
dappId: SEARCH_ITEM_ID,
Expand Down

0 comments on commit 99e4617

Please sign in to comment.