Skip to content

Commit

Permalink
fix: swap add deriveType Select (#6345)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezailWang authored Dec 13, 2024
1 parent 41fba93 commit 4c8131a
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,16 @@ function DeriveTypeSelectorTriggerIconRenderer({
label,
autoShowLabel,
onPress,
iconProps,
labelProps,
containerProps,
}: {
label?: string | undefined;
autoShowLabel?: boolean;
onPress?: (event: GestureResponderEvent) => void;
iconProps?: ComponentProps<typeof Icon>;
labelProps?: ComponentProps<typeof SizableText>;
containerProps?: ComponentProps<typeof XStack>;
}) {
const media = useMedia();
const hitSlop = platformEnv.isNative
Expand Down Expand Up @@ -243,10 +249,22 @@ function DeriveTypeSelectorTriggerIconRenderer({
hitSlop={hitSlop}
onPress={onPress}
focusable
{...containerProps}
>
<Icon name="BranchesOutline" color="$iconSubdued" size="$4.5" />
<Icon
name="BranchesOutline"
color="$iconSubdued"
size="$4.5"
{...iconProps}
/>
{media.gtSm && autoShowLabel ? (
<SizableText pl="$2" pr="$1" size="$bodyMd" color="$textSubdued">
<SizableText
pl="$2"
pr="$1"
size="$bodyMd"
color="$textSubdued"
{...labelProps}
>
{label}
</SizableText>
) : null}
Expand All @@ -269,6 +287,27 @@ export function DeriveTypeSelectorTriggerForHome({ num }: { num: number }) {
);
}

export function DeriveTypeSelectorTriggerForSwap({ num }: { num: number }) {
return (
<DeriveTypeSelectorTrigger
renderTrigger={({ label, onPress }) => (
<DeriveTypeSelectorTriggerIconRenderer
label={label}
autoShowLabel
onPress={onPress}
iconProps={{
size: '$4',
}}
labelProps={{
pl: '$1',
}}
/>
)}
num={num}
/>
);
}

export function DeriveTypeSelectorTriggerForDapp({
num,
focusedWalletId,
Expand Down
26 changes: 16 additions & 10 deletions packages/kit/src/states/jotai/contexts/swap/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ETranslations } from '@onekeyhq/shared/src/locale';
import { appLocale } from '@onekeyhq/shared/src/locale/appLocale';
import accountUtils from '@onekeyhq/shared/src/utils/accountUtils';
import { memoFn } from '@onekeyhq/shared/src/utils/cacheUtils';
import networkUtils from '@onekeyhq/shared/src/utils/networkUtils';
import { numberFormat } from '@onekeyhq/shared/src/utils/numberUtils';
import { equalTokenNoCaseSensitive } from '@onekeyhq/shared/src/utils/tokenUtils';
import {
Expand Down Expand Up @@ -1281,16 +1282,21 @@ class ContentJotaiActionsSwap extends ContextJotaiActionsBase {
let accountId: string | undefined;
if (type === ESwapDirectionType.TO) {
// fetch to Token balance use FromAccount id
const toAccountInfos =
await backgroundApiProxy.serviceStaking.getEarnAccount({
accountId: swapAddressInfo.accountInfo?.account?.id ?? '',
networkId: token?.networkId ?? '',
indexedAccountId: swapAddressInfo.accountInfo?.indexedAccount?.id,
});
if (toAccountInfos) {
accountAddress = toAccountInfos.accountAddress;
accountNetworkId = toAccountInfos.networkId;
accountId = toAccountInfos.accountId;
if (
token?.networkId &&
!networkUtils.isAllNetwork({ networkId: token?.networkId })
) {
const toAccountInfos =
await backgroundApiProxy.serviceStaking.getEarnAccount({
accountId: swapAddressInfo.accountInfo?.account?.id ?? '',
networkId: token.networkId,
indexedAccountId: swapAddressInfo.accountInfo?.indexedAccount?.id,
});
if (toAccountInfos) {
accountAddress = toAccountInfos.accountAddress;
accountNetworkId = toAccountInfos.networkId;
accountId = toAccountInfos.accountId;
}
}
} else {
accountAddress = swapAddressInfo.address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function TokenDetailsHeader(props: IProps) {
logoURI: tokenInfo.logoURI,
networkLogoURI: network?.logoURI,
},
importDeriveType: deriveType,
...(actionType && {
swapTabSwitchType: actionType,
}),
Expand All @@ -126,6 +127,7 @@ function TokenDetailsHeader(props: IProps) {
tokenInfo.logoURI,
tokenInfo.name,
tokenInfo.symbol,
deriveType,
],
);

Expand Down
4 changes: 4 additions & 0 deletions packages/kit/src/views/Swap/hooks/useSwapAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useRouteIsFocused as useIsFocused } from '@onekeyhq/kit/src/hooks/useRo
import { useSettingsAtom } from '@onekeyhq/kit-bg/src/states/jotai/atoms';
import { ETabRoutes } from '@onekeyhq/shared/src/routes';
import accountUtils from '@onekeyhq/shared/src/utils/accountUtils';
import networkUtils from '@onekeyhq/shared/src/utils/networkUtils';
import type { ISwapToken } from '@onekeyhq/shared/types/swap/types';
import { ESwapDirectionType } from '@onekeyhq/shared/types/swap/types';

Expand Down Expand Up @@ -243,6 +244,9 @@ export function useSwapRecipientAddressInfo(enable: boolean) {
}
if (
swapToAddressInfo.networkId &&
!networkUtils.isAllNetwork({
networkId: swapToAddressInfo.networkId,
}) &&
fromAccountInfo.accountInfo?.account?.id &&
fromAccountInfo.accountInfo?.indexedAccount?.id
) {
Expand Down
Loading

0 comments on commit 4c8131a

Please sign in to comment.