Skip to content

Commit

Permalink
update poolpair screens
Browse files Browse the repository at this point in the history
  • Loading branch information
nattadex committed Jul 19, 2024
1 parent 46e6738 commit 0a8b1f9
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 23 deletions.
72 changes: 72 additions & 0 deletions mobile-app/app/api/token/dusdt_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,75 @@ export function dusdt_converter_token(token: any) {
}
return { ...token, displaySymbol: "csUSDT" };
}

export function dusdt_converter_pool_pair(availablePairs: any) {
if (availablePairs.length > 1) {
return availablePairs.map((pair: any) => {
const updatedPair = {
...pair,
data: {
...pair.data,
symbol: pair.data.symbol.replace(/dUSDT/g, "csUSDT"),
displaySymbol: pair.data.displaySymbol.replace(/dUSDT/g, "csUSDT"),
tokenA: {
...pair.data.tokenA,
symbol:
pair.data.tokenA.symbol === "dUSDT"
? "csUSDT"
: pair.data.tokenA.symbol,
displaySymbol:
pair.data.tokenA.displaySymbol === "dUSDT"
? "csUSDT"
: pair.data.tokenA.displaySymbol,
},
tokenB: {
...pair.data.tokenB,
symbol:
pair.data.tokenB.symbol === "dUSDT"
? "csUSDT"
: pair.data.tokenB.symbol,
displaySymbol:
pair.data.tokenB.displaySymbol === "dUSDT"
? "csUSDT"
: pair.data.tokenB.displaySymbol,
},
},
};
return updatedPair;
});
} else {
return {
...availablePairs,
data: {
...availablePairs.data,
symbol: availablePairs.data.symbol.replace(/dUSDT/g, "csUSDT"),
displaySymbol: availablePairs.data.displaySymbol.replace(
/dUSDT/g,
"csUSDT",
),
tokenA: {
...availablePairs.data.tokenA,
symbol:
availablePairs.data.tokenA.symbol === "dUSDT"
? "csUSDT"
: availablePairs.data.tokenA.symbol,
displaySymbol:
availablePairs.data.tokenA.displaySymbol === "dUSDT"
? "csUSDT"
: availablePairs.data.tokenA.displaySymbol,
},
tokenB: {
...availablePairs.data.tokenB,
symbol:
availablePairs.data.tokenB.symbol === "dUSDT"
? "csUSDT"
: availablePairs.data.tokenB.symbol,
displaySymbol:
availablePairs.data.tokenB.displaySymbol === "dUSDT"
? "csUSDT"
: availablePairs.data.tokenB.displaySymbol,
},
},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { useDeFiScanContext } from "@shared-contexts/DeFiScanContext";
import { useToast } from "react-native-toast-notifications";
import { openURL } from "@api/linking";
import { ScreenName } from "@screens/enum";
import { dusdt_converter_pool_pair } from "@api/token/dusdt_converter";
import { useYourPoolPairAmountBreakdown } from "./hook/YourPoolPairAmountBreakdown";
import { useFavouritePoolpairContext } from "../../../../contexts/FavouritePoolpairContext";
import { DexParamList } from "./DexNavigator";
Expand All @@ -44,11 +45,11 @@ type Props = StackScreenProps<DexParamList, "PoolPairDetailsScreen">;

export function PoolPairDetailsScreen({ route }: Props): JSX.Element {
const { id } = route.params;
const poolPair = useSelector((state: RootState) =>
poolPairSelector(state.wallet, id)
const poolPair = dusdt_converter_pool_pair(
useSelector((state: RootState) => poolPairSelector(state.wallet, id)),
);
const tokens = useSelector((state: RootState) =>
tokensSelector(state.wallet)
tokensSelector(state.wallet),
);
const { getTokenUrl } = useDeFiScanContext();
const navigation = useNavigation<NavigationProp<DexParamList>>();
Expand All @@ -72,7 +73,7 @@ export function PoolPairDetailsScreen({ route }: Props): JSX.Element {
headerTitle: translate(
"screens/PoolPairDetailsScreen",
"{{poolPair}} Pool",
{ poolPair: poolPair.data.displaySymbol }
{ poolPair: poolPair.data.displaySymbol },
),
});
}, [navigation]);
Expand Down Expand Up @@ -245,7 +246,7 @@ function Header(props: {
isFavouritePair={props.isFavouritePair}
onPress={() => {
showToast(
props.isFavouritePair ? "UNSET_FAVOURITE" : "SET_FAVOURITE"
props.isFavouritePair ? "UNSET_FAVOURITE" : "SET_FAVOURITE",
);
props.setFavouritePair(props.poolPairId);
}}
Expand Down Expand Up @@ -291,8 +292,8 @@ function PoolPairDetail({ poolPair }: { poolPair: DexItem }): JSX.Element {
getTokenPrice(
poolPair.data.symbol,
new BigNumber(poolPair.data.totalLiquidity.token),
true
)
true,
),
),
usdTextStyle: tailwind("text-sm"),
usdContainerStyle: tailwind("pt-1"),
Expand All @@ -304,7 +305,7 @@ function PoolPairDetail({ poolPair }: { poolPair: DexItem }): JSX.Element {
value: translate(
"screens/PoolPairDetailsScreen",
"Pooled {{symbol}}",
{ symbol: poolPair.data.tokenA.displaySymbol }
{ symbol: poolPair.data.tokenA.displaySymbol },
),
testID: "pooled_tokenA",
}}
Expand All @@ -313,7 +314,7 @@ function PoolPairDetail({ poolPair }: { poolPair: DexItem }): JSX.Element {
suffix: ` ${poolPair.data.tokenA.displaySymbol}`,
usdAmount: getTokenPrice(
poolPair.data.tokenA.symbol,
new BigNumber(poolPair.data.tokenA.reserve)
new BigNumber(poolPair.data.tokenA.reserve),
),
usdTextStyle: tailwind("text-sm"),
usdContainerStyle: tailwind("pt-1"),
Expand All @@ -325,7 +326,7 @@ function PoolPairDetail({ poolPair }: { poolPair: DexItem }): JSX.Element {
value: translate(
"screens/PoolPairDetailsScreen",
"Pooled {{symbol}}",
{ symbol: poolPair.data.tokenB.displaySymbol }
{ symbol: poolPair.data.tokenB.displaySymbol },
),
testID: "pooled_tokenB",
}}
Expand All @@ -334,7 +335,7 @@ function PoolPairDetail({ poolPair }: { poolPair: DexItem }): JSX.Element {
suffix: ` ${poolPair.data.tokenB.displaySymbol}`,
usdAmount: getTokenPrice(
poolPair.data.tokenB.symbol,
new BigNumber(poolPair.data.tokenB.reserve)
new BigNumber(poolPair.data.tokenB.reserve),
),
usdTextStyle: tailwind("text-sm"),
usdContainerStyle: tailwind("pt-1"),
Expand Down Expand Up @@ -366,7 +367,7 @@ function PriceRateDetail({ poolPair }: { poolPair: DexItem }): JSX.Element {
suffix: ` ${poolPair.data.tokenB.displaySymbol}`,
usdAmount: getTokenPrice(
poolPair.data.tokenB.symbol,
new BigNumber(poolPair.data.priceRatio.ba)
new BigNumber(poolPair.data.priceRatio.ba),
),
usdTextStyle: tailwind("text-sm"),
usdContainerStyle: tailwind("pt-1"),
Expand All @@ -385,7 +386,7 @@ function PriceRateDetail({ poolPair }: { poolPair: DexItem }): JSX.Element {
suffix: ` ${poolPair.data.tokenA.displaySymbol}`,
usdAmount: getTokenPrice(
poolPair.data.tokenA.symbol,
new BigNumber(poolPair.data.priceRatio.ab)
new BigNumber(poolPair.data.priceRatio.ab),
),
usdTextStyle: tailwind("text-sm"),
usdContainerStyle: tailwind("pt-1"),
Expand All @@ -405,7 +406,7 @@ function YourPoolPairTokenBreakdown(props: {
}): JSX.Element {
const { getTokenPrice } = useTokenPrice();
const { tokenATotal, tokenBTotal } = useYourPoolPairAmountBreakdown(
props.yourLpToken
props.yourLpToken,
);

return (
Expand All @@ -424,7 +425,7 @@ function YourPoolPairTokenBreakdown(props: {
usdAmount: getTokenPrice(
props.yourLpToken.symbol,
new BigNumber(props.yourLpToken.amount),
true
true,
),
usdTextStyle: tailwind("text-sm"),
usdContainerStyle: tailwind("pt-1"),
Expand All @@ -436,15 +437,15 @@ function YourPoolPairTokenBreakdown(props: {
value: translate(
"screens/PoolPairDetailsScreen",
"Tokens in {{symbol}}",
{ symbol: props.tokenADisplaySymbol }
{ symbol: props.tokenADisplaySymbol },
),
testID: "your_lp_tokenA",
}}
rhs={{
value: tokenATotal.toFixed(8),
usdAmount: getTokenPrice(
props.tokenASymbol,
new BigNumber(tokenATotal)
new BigNumber(tokenATotal),
),
usdTextStyle: tailwind("text-sm"),
usdContainerStyle: tailwind("pt-1"),
Expand All @@ -456,15 +457,15 @@ function YourPoolPairTokenBreakdown(props: {
value: translate(
"screens/PoolPairDetailsScreen",
"Tokens in {{symbol}}",
{ symbol: props.tokenBDisplaySymbol }
{ symbol: props.tokenBDisplaySymbol },
),
testID: "your_lp_tokenB",
}}
rhs={{
value: tokenBTotal.toFixed(8),
usdAmount: getTokenPrice(
props.tokenBSymbol,
new BigNumber(tokenBTotal)
new BigNumber(tokenBTotal),
),
usdTextStyle: tailwind("text-sm"),
usdContainerStyle: tailwind("pt-1"),
Expand Down Expand Up @@ -520,7 +521,7 @@ function APRDetail(props: {
{translate(
"screens/PoolPairDetailsScreen",
"{{percentage}}% in rewards",
{ percentage: val }
{ percentage: val },
)}
</ThemedTextV2>
)}
Expand All @@ -539,7 +540,7 @@ function APRDetail(props: {
{translate(
"screens/PoolPairDetailsScreen",
"{{percentage}}% in commissions",
{ percentage: val }
{ percentage: val },
)}
</ThemedTextV2>
)}
Expand Down Expand Up @@ -579,7 +580,7 @@ function PoolPairActionSection({
onPress={() =>
onAdd(
pair.data,
walletToken ?? (pair.data as unknown as WalletToken)
walletToken ?? (pair.data as unknown as WalletToken),
)
}
isLast={walletToken === undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useTokenPrice } from "@screens/AppNavigator/screens/Portfolio/hooks/Tok
import { useToast } from "react-native-toast-notifications";
import { useFavouritePoolpairContext } from "@contexts/FavouritePoolpairContext";
import { Delayed } from "@components/Delayed";
import { dusdt_converter_pool_pair } from "@api/token/dusdt_converter";
import { DexScrollable } from "../DexScrollable";
import { TotalValueLocked } from "../TotalValueLocked";

Expand Down Expand Up @@ -245,7 +246,7 @@ function PoolCard({
const poolPairData = pairs.find(
(pr) => pr.data.symbol === (yourPair as AddressToken).symbol,
);
const mappedPair = poolPairData?.data;
const mappedPair = dusdt_converter_pool_pair(poolPairData)?.data;

const [symbolA, symbolB] =
mappedPair?.tokenA != null && mappedPair?.tokenB != null
Expand Down

0 comments on commit 0a8b1f9

Please sign in to comment.