Skip to content

Commit

Permalink
fix(chore): bug fix for transferdomain (#4063)
Browse files Browse the repository at this point in the history
* refactore transferdomain provider

* fix(ui-ux): fixed icon for evm DFI on swap token listing

* fix convert screen provider issue

* added chainId in evm provider

* added nonce in td request

* fix(chore): updated evm tokenId and fixed DFI evm icon and balance inconsistancy

* updated dfi name

* updated EVM suffix names

* chore

* removed (EVM) for DFI token

* Balance details screen for EVM token

* fixed evm dif related bugs
  • Loading branch information
fullstackninja864 authored Oct 16, 2023
1 parent 566af72 commit 21c99d2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface TokenBreakdownDetailProps {
}

export function TokenBreakdownDetailsV2(
props: TokenBreakdownDetailProps
props: TokenBreakdownDetailProps,
): JSX.Element {
const { denominationCurrency } = useDenominationCurrency();
const lockedToken = (useTokenLockedBalance({
Expand All @@ -46,17 +46,17 @@ export function TokenBreakdownDetailsV2(
};
const loanTokens = useSelector((state: RootState) => state.loans.loanTokens);
const collateralTokens = useSelector(
(state: RootState) => state.loans.collateralTokens
(state: RootState) => state.loans.collateralTokens,
);
const hasLockedBalance = useMemo((): boolean => {
return (
collateralTokens.some(
(collateralToken) =>
collateralToken.token.displaySymbol === props.token.displaySymbol
collateralToken.token.displaySymbol === props.token.displaySymbol,
) ||
loanTokens.some(
(loanToken) =>
loanToken.token.displaySymbol === props.token.displaySymbol
loanToken.token.displaySymbol === props.token.displaySymbol,
)
);
}, [props.token]);
Expand All @@ -65,7 +65,7 @@ export function TokenBreakdownDetailsV2(
// LP token calculations
const { poolpairs: pairs } = useSelector((state: RootState) => state.wallet);
const poolPairData = pairs.find(
(pr) => pr.data.symbol === (props.token as AddressToken).symbol
(pr) => pr.data.symbol === (props.token as AddressToken).symbol,
);
const mappedPair = poolPairData?.data;
const toRemove = new BigNumber(1)
Expand All @@ -81,7 +81,7 @@ export function TokenBreakdownDetailsV2(
const getUSDValue = (
amount: BigNumber,
symbol: string,
isLPs: boolean = false
isLPs: boolean = false,
): BigNumber => {
return getTokenPrice(symbol, amount, isLPs);
};
Expand Down Expand Up @@ -166,6 +166,7 @@ export function TokenBreakdownDetailsV2(

{/* To display options for DFI UTXO and Token */}
{props.token.displaySymbol === "DFI" &&
props.token.id !== "0_evm" &&
props.dfiUtxo !== undefined &&
props.dfiToken !== undefined && (
<View style={tailwind("pb-4")}>
Expand Down Expand Up @@ -211,8 +212,8 @@ export function TokenBreakdownDetailsV2(
getTokenPrice(
props.token.symbol,
new BigNumber(props.token.amount),
true
)
true,
),
)}
label=""
hasFetchedToken={props.hasFetchedToken}
Expand All @@ -233,7 +234,7 @@ export function TokenBreakdownDetailsV2(
label={translate(
"components/DFIBalanceCard",
"Tokens in {{token}}",
{ token: props.pair.tokenA.displaySymbol }
{ token: props.pair.tokenA.displaySymbol },
)}
hasFetchedToken={props.hasFetchedToken}
/>
Expand All @@ -242,8 +243,8 @@ export function TokenBreakdownDetailsV2(
amount={getPrecisedCurrencyValue(
getUSDValue(
new BigNumber(tokenATotal),
props.pair.tokenA.symbol
)
props.pair.tokenA.symbol,
),
)}
label=""
hasFetchedToken={props.hasFetchedToken}
Expand All @@ -263,14 +264,14 @@ export function TokenBreakdownDetailsV2(
label={translate(
"components/DFIBalanceCard",
"Tokens in {{token}}",
{ token: props.pair.tokenB.displaySymbol }
{ token: props.pair.tokenB.displaySymbol },
)}
hasFetchedToken={props.hasFetchedToken}
/>
<TokenBreakdownDetailsRow
testID={`tokens_in_${props.pair.symbol}_${props.pair.tokenB.displaySymbol}_usd`}
amount={getPrecisedCurrencyValue(
getUSDValue(new BigNumber(tokenBTotal), props.pair.tokenB.symbol)
getUSDValue(new BigNumber(tokenBTotal), props.pair.tokenB.symbol),
)}
label=""
hasFetchedToken={props.hasFetchedToken}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ export function ConvertScreen(props: Props): JSX.Element {
) {
// If from:DFI-UTXO -> to: utxosToAccount
updatedConvertDirection = ConvertDirection.utxosToAccount;
} else if (
sourceToken.tokenId === "0" &&
listType === TokenListType.To &&
item.tokenId === "0_evm"
) {
updatedConvertDirection = ConvertDirection.dvmToEvm;
}

let updatedTargetToken: SelectionToken | undefined;
Expand Down Expand Up @@ -331,6 +337,7 @@ export function ConvertScreen(props: Props): JSX.Element {
targetToken: updatedTargetToken,
convertDirection: updatedConvertDirection,
},
key: updatedTargetToken?.tokenId,
merge: true,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,14 @@ async function send(
: ConvertDirection.evmToDvm;
const isEvmToDvm = sendDirection === ConvertDirection.evmToDvm;
const tokenId = token.id === "0_unified" ? "0" : token.id;
const sourceTokenId = isEvmToDvm ? `${tokenId}_evm` : tokenId;
const targetTokenId = isEvmToDvm ? tokenId : `${tokenId}_evm`;
const sourceTokenId =
isEvmToDvm && !tokenId.includes("_evm")
? `${tokenId}_evm`
: tokenId;
const targetTokenId =
!isEvmToDvm && !tokenId.includes("_evm")
? `${tokenId}_evm`
: tokenId;
const dvmAddress = isEvmToDvm
? address
: await account.getAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function TokenDetailScreen({ route, navigation }: Props): JSX.Element {
route.params.token,
);

const { dvmTokens } = useTokenBalance();
const { dvmTokens, evmTokens } = useTokenBalance();

// usdAmount for crypto tokens, undefined for DFI token
const { usdAmount } = route.params.token;
Expand Down Expand Up @@ -201,7 +201,7 @@ export function TokenDetailScreen({ route, navigation }: Props): JSX.Element {
usdAmount={usdAmount ?? new BigNumber(0)}
pair={pair}
/>
{token.symbol === "DFI" && (
{token.symbol === "DFI" && token.id !== "0_evm" && (
<ThemedViewV2
dark={tailwind("border-mono-dark-v2-300")}
light={tailwind("border-mono-light-v2-300")}
Expand Down Expand Up @@ -267,7 +267,7 @@ export function TokenDetailScreen({ route, navigation }: Props): JSX.Element {
</>
)}

{token.symbol === "DFI" && (
{token.symbol === "DFI" && token.id !== "0_evm" && (
<TokenActionRow
icon="swap-calls"
iconType="MaterialIcons"
Expand Down Expand Up @@ -302,7 +302,47 @@ export function TokenDetailScreen({ route, navigation }: Props): JSX.Element {
title={translate(
"screens/TokenDetailScreen",
"Convert to {{symbol}}",
{ symbol: `${token.id === "0_utxo" ? "Token" : "UTXO"}` },
{ symbol: "Token/UTXO" },
)}
/>
)}

{token.id === "0_evm" && (
<TokenActionRow
icon="swap-calls"
iconType="MaterialIcons"
onPress={() => {
const convertDirection: ConvertDirection =
domain === DomainType.DVM
? ConvertDirection.dvmToEvm
: ConvertDirection.evmToDvm;

const evmToken = evmTokens.find(
(token) => token.tokenId === "0_evm",
);
const dfiToken = dvmTokens.find(
(token) => token.tokenId === "0",
);
const [sourceToken, targetToken] =
convertDirection === ConvertDirection.evmToDvm
? [evmToken, dfiToken]
: [dfiToken, evmToken];

navigation.navigate({
name: "ConvertScreen",
params: {
sourceToken,
targetToken,
convertDirection,
},
merge: true,
});
}}
testID="convert_button"
title={translate(
"screens/TokenDetailScreen",
"Convert to {{symbol}}",
{ symbol: "Token" },
)}
/>
)}
Expand Down

0 comments on commit 21c99d2

Please sign in to comment.