Skip to content

Commit

Permalink
fix:Merge branch 'x' into fix/passcode
Browse files Browse the repository at this point in the history
  • Loading branch information
ezailWang committed Dec 23, 2024
2 parents fc4c6a9 + 7c70803 commit d313725
Show file tree
Hide file tree
Showing 38 changed files with 231 additions and 185 deletions.
69 changes: 14 additions & 55 deletions packages/components/src/actions/Toast/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ import { useMedia } from 'tamagui';
import { dismissKeyboard } from '@onekeyhq/shared/src/keyboard';
import platformEnv from '@onekeyhq/shared/src/platformEnv';

import { AnchorSizableText } from '../../content/AnchorSizableText';
import { Portal } from '../../hocs';
import {
Anchor,
Icon,
SizableText,
View,
XStack,
YStack,
} from '../../primitives';
import { Icon, View, XStack, YStack } from '../../primitives';

import { ShowCustom, ShowToasterClose } from './ShowCustom';
import { showMessage } from './showMessage';
Expand Down Expand Up @@ -48,7 +42,6 @@ const iconMap = {
warning: <Icon name="ErrorSolid" color="$iconCaution" size="$5" />,
};

const urlRegex = /<url(?:\s+[^>]*?)?>(.*?)<\/url>/g;
const RenderLines = ({
size,
children: text,
Expand All @@ -69,52 +62,18 @@ const RenderLines = ({

return (
<YStack>
{lines.map((line, index) => {
const hasUrl = urlRegex.test(line);
if (!hasUrl) {
return (
<SizableText
key={index}
color={color}
textTransform="none"
userSelect="none"
size={size}
wordWrap="break-word"
>
{line}
</SizableText>
);
}
const parts = line.split(urlRegex);
const hrefMatch = line.match(/href="(.*?)"/);
return (
<SizableText
key={index}
color={color}
textTransform="none"
userSelect="none"
size={size}
wordWrap="break-word"
>
{parts.map((part, partIndex) => {
if (partIndex % 2 === 1) {
return (
<Anchor
key={partIndex}
href={hrefMatch?.[1]}
target="_blank"
size={size}
color="$textInfo"
>
{part}
</Anchor>
);
}
return part;
})}
</SizableText>
);
})}
{lines.map((line, index) => (
<AnchorSizableText
key={index}
color={color}
textTransform="none"
userSelect="none"
size={size}
wordWrap="break-word"
>
{line}
</AnchorSizableText>
))}
</YStack>
);
};
Expand Down
46 changes: 46 additions & 0 deletions packages/components/src/content/AnchorSizableText/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Anchor, SizableText } from '../../primitives';

import type { IAnchorProps, ISizableTextProps } from '../../primitives';

export interface IAnchorSizableTextProps extends ISizableTextProps {
anchorRegExp?: RegExp;
hrefRegExp?: RegExp;
anchorProps?: IAnchorProps;
}

export function AnchorSizableText({
anchorRegExp = /<url(?:\s+[^>]*?)?>(.*?)<\/url>/g,
hrefRegExp = /href="(.*?)"/,
children,
anchorProps,
...props
}: IAnchorSizableTextProps) {
const line = children as string;
const isAnchor = anchorRegExp.test(line);
if (isAnchor) {
const parts = line.split(anchorRegExp);
const hrefMatch = line.match(/href="(.*?)"/);
return (
<SizableText {...props}>
{parts.map((part, partIndex) => {
if (partIndex === 1) {
return (
<Anchor
{...props}
target="_blank"
color="$textInfo"
{...anchorProps}
key={partIndex}
href={hrefMatch?.[1]}
>
{part}
</Anchor>
);
}
return part;
})}
</SizableText>
);
}
return <SizableText {...props}>{line}</SizableText>;
}
1 change: 1 addition & 0 deletions packages/components/src/content/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './AnchorSizableText';
export * from './Badge';
export * from './HeightTransition';
export * from './LinearGradient';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ function TabSubStackNavigator({
component={component}
options={({ navigation }: { navigation: any }) => ({
freezeOnBlur: true,
headerShown,
title: translationId
? intl.formatMessage({
id: translationId,
})
: '',
...makeTabScreenOptions({ navigation, bgColor, titleColor }),
headerShown,
})}
/>
))}
Expand Down
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
34 changes: 1 addition & 33 deletions packages/kit/src/components/TradingView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,27 @@ interface IBaseTradingViewProps {
identifier: string;
baseToken: string;
targetToken: string;
onLoadEnd: () => void;
}

export type ITradingViewProps = IBaseTradingViewProps & IStackStyle;

function Loading() {
return (
<Stack flex={1} alignContent="center" justifyContent="center">
<Spinner size="large" />
</Stack>
);
}

export function TradingView(props: ITradingViewProps & WebViewProps) {
const [restProps, style] = usePropsAndStyle(props);
const { targetToken, identifier, baseToken, ...otherProps } =
restProps as IBaseTradingViewProps;
const [showLoading, changeShowLoading] = useState(true);
const tradingViewProps = useTradingViewProps({
targetToken,
identifier,
baseToken,
});
const onLoadEnd = useCallback(() => {
changeShowLoading(false);
}, []);
return (
<Stack bg="$bgApp" style={style as ViewStyle}>
<WebView
tradingViewProps={tradingViewProps}
style={{ flex: 1 }}
onLoadEnd={onLoadEnd}
{...otherProps}
/>
<AnimatePresence>
{showLoading ? (
<Stack
bg="$bgApp"
position="absolute"
top={0}
left={0}
right={0}
bottom={0}
opacity={1}
flex={1}
animation="quick"
exitStyle={{
opacity: 0,
}}
>
<Loading />
</Stack>
) : null}
</AnimatePresence>
</Stack>
);
}
1 change: 1 addition & 0 deletions packages/kit/src/routes/Tab/Discovery/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const discoveryRouters: ITabSubNavigatorConfig<any, any>[] = [
{
name: ETabDiscoveryRoutes.TabDiscovery,
rewrite: '/',
headerShown: !platformEnv.isNative,
component:
platformEnv.isNative && !platformEnv.isNativeIOSPad
? Browser
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/routes/Tab/Earn/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ITabSubNavigatorConfig } from '@onekeyhq/components';
import platformEnv from '@onekeyhq/shared/src/platformEnv';
import { ETabEarnRoutes } from '@onekeyhq/shared/src/routes';

import { LazyLoadRootTabPage } from '../../../components/LazyLoadPage';
Expand All @@ -12,5 +13,6 @@ export const earnRouters: ITabSubNavigatorConfig<any, any>[] = [
rewrite: '/',
name: ETabEarnRoutes.EarnHome,
component: EarnHome,
headerShown: !platformEnv.isNative,
},
];
Loading

0 comments on commit d313725

Please sign in to comment.