Skip to content

Commit

Permalink
Merge pull request #874 from ambrosus/AMB-5132
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturHoncharuk authored Dec 11, 2024
2 parents dc218d1 + 848d4df commit 74d7674
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
18 changes: 14 additions & 4 deletions src/features/bridge/context/Bridge.Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,18 @@ export const BridgeContext = () => {
return selectedTokenPairs ? selectedTokenPairs[1] : DEFAULT_TOKEN_TO;
}, [selectedTokenPairs]);

const decimals = useMemo(
() =>
fromData.value.id === 'amb'
? selectedTokenDestination.decimals
: selectedTokenFrom.decimals,
[
fromData.value.id,
selectedTokenDestination.decimals,
selectedTokenFrom.decimals
]
);

const processBridge = useCallback(
async (getOnlyGasFee: boolean, bridgeFee: FeeData) => {
try {
Expand All @@ -229,10 +241,7 @@ export const BridgeContext = () => {
tokenFrom: selectedTokenFrom,
tokenTo: selectedTokenDestination,
selectedAccount: wallet,
amountTokens: formatUnits(
bridgeFee.amount,
selectedTokenFrom.decimals
),
amountTokens: formatUnits(bridgeFee.amount, decimals),
feeData: bridgeFee,
gasFee: getOnlyGasFee
};
Expand All @@ -257,6 +266,7 @@ export const BridgeContext = () => {
[
bridgeConfig,
bridgeErrorHandler,
decimals,
fromData.value.id,
selectedTokenDestination,
selectedTokenFrom,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
import { NumberUtils } from '@utils/number';
import { formatUnits } from 'ethers/lib/utils';
import React from 'react';
import { View } from 'react-native';
import { Row, Spacer, Text } from '@components/base';
import { TokenLogo } from '@components/modular';
import { COLORS } from '@constants/colors';
import { scale } from '@utils/scaling';
import React from 'react';
import { DataToPreviewModel } from '@models/Bridge';
import { NumberUtils } from '@utils/number';
import { formatUnits } from 'ethers/lib/utils';

export const PreviewDataItem = ({
item
}: {
interface PreviewDataItemProps {
item: {
name?: string;
index: number;
item: DataToPreviewModel;
};
}) => {
const { item: renderItem, index } = item;
}

export const PreviewDataItem = ({ item }: PreviewDataItemProps) => {
const {
index,
item: {
name,
symbol,
crypto: { amount, decimals }
}
} = item;

const amountToRender = NumberUtils.limitDecimalCount(
formatUnits(renderItem.crypto.amount, renderItem.crypto.decimals),
formatUnits(amount, decimals),
5
);

Expand All @@ -34,13 +41,13 @@ export const PreviewDataItem = ({
justifyContent: 'space-between'
}}
>
<Text>{renderItem.name}</Text>
<Text>{name}</Text>
<Row>
{isFirst && <TokenLogo token={renderItem.symbol} scale={0.5} />}
{isFirst && <TokenLogo token={symbol} scale={0.5} />}
<Spacer horizontal value={10} />
<Text
color={COLORS.neutral800}
>{`${amountToRender} ${renderItem.symbol}`}</Text>
>{`${amountToRender} ${symbol}`}</Text>
</Row>
</View>
<Spacer value={scale(16)} />
Expand Down
17 changes: 15 additions & 2 deletions src/features/bridge/templates/BridgeForm/BridgeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,27 @@ export const BridgeForm = () => {
setSelectedTokenPairs(tokenPair);
tokenSelectRef?.current?.dismiss();
};

const decimals = useMemo(
() =>
fromData.value.id === 'amb'
? selectedTokenDestination.decimals
: selectedTokenFrom.decimals,
[
fromData.value.id,
selectedTokenDestination.decimals,
selectedTokenFrom.decimals
]
);

const parseBridgePreviewData = useCallback(
(feeData: FeeData, gasFee: BigNumberish) => {
return [
{
name: t('bridge.preview.receive'),
crypto: {
amount: feeData?.amount ?? BigNumber.from(0),
decimals: selectedTokenFrom.decimals
decimals
},
symbol: selectedTokenFrom.symbol
},
Expand Down Expand Up @@ -152,9 +165,9 @@ export const BridgeForm = () => {
];
},
[
decimals,
networkNativeToken?.decimals,
networkNativeToken.symbol,
selectedTokenFrom.decimals,
selectedTokenFrom.symbol,
t
]
Expand Down

0 comments on commit 74d7674

Please sign in to comment.