diff --git a/packages/kit/src/views/Swap/Main/Swap/SwapContent.tsx b/packages/kit/src/views/Swap/Main/Swap/SwapContent.tsx index 7653026176f..bd57b00bc32 100644 --- a/packages/kit/src/views/Swap/Main/Swap/SwapContent.tsx +++ b/packages/kit/src/views/Swap/Main/Swap/SwapContent.tsx @@ -137,7 +137,7 @@ export const SwapContent = () => { const { wallet, network } = useActiveWalletAccount(); const swapMaintain = useAppSelector((s) => s.swapTransactions.swapMaintain); const { formattedAmounts } = useDerivedSwapState(); - + const quote = useAppSelector((s) => s.swap.quote); const isDisabled = !wallet || !network || swapMaintain; const onSelectInput = useCallback(() => { @@ -219,6 +219,7 @@ export const SwapContent = () => { onChange={onChangeOutput} onPress={onSelectOutput} containerProps={containerProps.lower} + extraData={quote?.quoteExtraData} /> {isDisabled ? ( diff --git a/packages/kit/src/views/Swap/components/ReceivingTokenInput/index.tsx b/packages/kit/src/views/Swap/components/ReceivingTokenInput/index.tsx index 456b7a605bb..3700b633489 100644 --- a/packages/kit/src/views/Swap/components/ReceivingTokenInput/index.tsx +++ b/packages/kit/src/views/Swap/components/ReceivingTokenInput/index.tsx @@ -1,7 +1,8 @@ import type { ComponentProps, FC, ReactElement } from 'react'; -import { useCallback, useEffect, useState } from 'react'; +import { useCallback, useEffect, useMemo, useState } from 'react'; import { useFocusEffect } from '@react-navigation/native'; +import BigNumber from 'bignumber.js'; import { useIntl } from 'react-intl'; import { StyleSheet, View } from 'react-native'; @@ -9,6 +10,7 @@ import { Box, CustomSkeleton, Icon, + Image, NumberInput, Pressable, Switch, @@ -36,6 +38,8 @@ import { } from '../../utils'; import { TokenDisplay } from '../TokenDisplay'; +import type { IQouterExtraData } from '../../quoter/socket'; + type TokenInputProps = { type: 'INPUT' | 'OUTPUT'; label?: string; @@ -44,6 +48,7 @@ type TokenInputProps = { onChange?: (text: string) => void; containerProps?: ComponentProps; isDisabled?: boolean; + extraData?: IQouterExtraData; }; const TokenInputReceivingAddress: FC = () => { @@ -389,6 +394,7 @@ const TokenInput: FC = ({ onPress, onChange, containerProps, + extraData, isDisabled, }) => { const intl = useIntl(); @@ -396,7 +402,42 @@ const TokenInput: FC = ({ const price = useTokenPrice(token); const loading = useAppSelector((s) => s.swap.loading); const independentField = useAppSelector((s) => s.swap.independentField); - + const extraDataContent = useMemo(() => { + if (!extraData?.socketBridgeExtraData?.arbRebateData) return null; + const { arbRebateData } = extraData.socketBridgeExtraData; + const { + amountInUsd, + amount, + asset: { decimals, logoURI }, + } = arbRebateData; + const amountParsed = new BigNumber(amount) + .shiftedBy(-decimals) + .decimalPlaces(4, BigNumber.ROUND_DOWN) + .toFixed(); + return ( + <> + {`+${amountParsed}`} + + + + {`($${amountInUsd.toFixed( + 2, + )})${intl.formatMessage({ + id: 'title__reward', + })}`} + + ); + }, [extraData?.socketBridgeExtraData, intl]); return ( @@ -455,6 +496,7 @@ const TokenInput: FC = ({ + {extraDataContent} ( diff --git a/packages/kit/src/views/Swap/quoter/index.ts b/packages/kit/src/views/Swap/quoter/index.ts index 699ae956823..92946727aa1 100644 --- a/packages/kit/src/views/Swap/quoter/index.ts +++ b/packages/kit/src/views/Swap/quoter/index.ts @@ -55,6 +55,7 @@ import type { TransactionDetails, TransactionProgress, } from '../typings'; +import type { IQouterExtraData } from './socket'; import type { AxiosResponse } from 'axios'; type TransactionOrder = { @@ -143,6 +144,7 @@ type FetchQuoteHttpResult = { estimatedPriceImpact?: string; onChainSatsPerVbyte?: string; notImpactBySlippage?: boolean; + quoterExtraData?: IQouterExtraData; }; type FetchQuoteHttpLimit = { @@ -387,6 +389,7 @@ export class SwapQuoter { estimatedPriceImpact: fetchQuote.estimatedPriceImpact, onChainSatsPerVbyte: fetchQuote.onChainSatsPerVbyte, notImpactBySlippage: fetchQuote.notImpactBySlippage, + quoteExtraData: fetchQuote.quoterExtraData, }; if (data.allowanceTarget && spendersAllowance) { diff --git a/packages/kit/src/views/Swap/quoter/socket.ts b/packages/kit/src/views/Swap/quoter/socket.ts index f77979a3518..850b482dd77 100644 --- a/packages/kit/src/views/Swap/quoter/socket.ts +++ b/packages/kit/src/views/Swap/quoter/socket.ts @@ -13,7 +13,7 @@ import type { } from '../typings'; import type { Axios } from 'axios'; -interface SocketAsset { +export interface SocketAsset { address: string; chainId: number; decimals: number; @@ -23,6 +23,20 @@ interface SocketAsset { symbol: string; } +export interface ISocketArbRebateData { + amount: string; + amountInUsd: number; + asset: SocketAsset; +} + +interface ISocketExtraData { + arbRebateData: ISocketArbRebateData; +} + +export interface IQouterExtraData { + socketBridgeExtraData?: ISocketExtraData; +} + interface SocketUserTxs { chainId: number; txType: string; @@ -48,6 +62,7 @@ export interface SocketRoute { usedDexName?: string; isOnlySwapRoute?: boolean; userTxs?: SocketUserTxs[]; + extraData?: ISocketExtraData; } export type SocketRouteStatus = diff --git a/packages/kit/src/views/Swap/typings.ts b/packages/kit/src/views/Swap/typings.ts index b3281d9b912..b423f788c5f 100644 --- a/packages/kit/src/views/Swap/typings.ts +++ b/packages/kit/src/views/Swap/typings.ts @@ -4,6 +4,7 @@ import type { Token } from '@onekeyhq/engine/src/types/token'; import type { IEncodedTx } from '@onekeyhq/engine/src/vaults/types'; import type { SendConfirmPayloadBase } from '../Send/types'; +import type { IQouterExtraData } from './quoter/socket'; export enum SwapRoutes { Swap = 'Swap', @@ -197,6 +198,7 @@ export type QuoteData = { estimatedPriceImpact?: string; onChainSatsPerVbyte?: string; notImpactBySlippage?: boolean; + quoteExtraData?: IQouterExtraData; }; type WrapperTransactionType = 'Withdraw' | 'Deposite';