Skip to content

Commit d7e3f5f

Browse files
authored
[GSW-2373] Portfolio Assets (#779)
* fix: [GSW-2373] Portfolio Wallet Balance * fix: [GSW-2373] Portfolio Asset List * refactor: [GSW-2373] remove redundant null check for tokenPrice
1 parent 2f609a7 commit d7e3f5f

File tree

2 files changed

+91
-35
lines changed

2 files changed

+91
-35
lines changed

packages/web/src/layouts/portfolio/containers/asset-list-container/AssetListContainer.tsx

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,20 @@ const AssetListContainer: React.FC = () => {
170170
return [gnot, wugnot, gns]
171171
.map(item => {
172172
const tokenPrice = balances[item.priceID];
173-
if (!tokenPrice || tokenPrice === null || Number.isNaN(tokenPrice)) {
174-
return {
175-
price: "-",
176-
balance: "-",
177-
...item,
178-
tokenPrice: tokenPrice || 0,
179-
sortPrice: "-",
180-
};
181-
}
182173

183174
const price = (() => {
184-
if (isSwitchNetwork || !tokenPrices[checkGnotPath(item?.path)]?.usd || !balances[item.priceID]) return "-";
175+
if (!connected || isSwitchNetwork) {
176+
return "-";
177+
}
178+
179+
if (
180+
!tokenPrice ||
181+
Number.isNaN(tokenPrice) ||
182+
!tokenPrices[checkGnotPath(item?.path)]?.usd ||
183+
!balances[item.priceID]
184+
) {
185+
return "$0";
186+
}
185187

186188
return formatPrice(
187189
BigNumber(tokenPrice)
@@ -213,26 +215,38 @@ const AssetListContainer: React.FC = () => {
213215
.filter(asset => invisibleZeroBalance === false || filterZeroBalance(asset))
214216
.filter(asset => filterKeyword(asset, keyword))
215217
.filter(asset => filterType(asset, assetType));
216-
}, [balances, displayBalanceMap, invisibleZeroBalance, isSwitchNetwork, tokenPrices, tokens, keyword, assetType]);
218+
}, [
219+
balances,
220+
displayBalanceMap,
221+
invisibleZeroBalance,
222+
isSwitchNetwork,
223+
tokenPrices,
224+
tokens,
225+
keyword,
226+
assetType,
227+
connected,
228+
]);
217229

218230
const filteredTokens = useMemo(() => {
219231
const COLLAPSED_LENGTH = 15;
220232
let mappedTokens: SortedProps[] = tokens
221233
.filter(item => item.path !== GNOT_TOKEN.path && item.path !== GNS_TOKEN.path && item.path !== WUGNOT_TOKEN.path)
222234
.map(item => {
223235
const tokenPrice = balances[item.priceID];
224-
if (!tokenPrice || Number.isNaN(tokenPrice)) {
225-
return {
226-
price: "-",
227-
balance: "-",
228-
...item,
229-
tokenPrice: tokenPrice || 0,
230-
sortPrice: "-",
231-
};
232-
}
233236

234237
const price = (() => {
235-
if (isSwitchNetwork || !tokenPrices[checkGnotPath(item?.path)]?.usd || !balances[item.priceID]) return "-";
238+
if (!connected || isSwitchNetwork) {
239+
return "-";
240+
}
241+
242+
if (
243+
!tokenPrice ||
244+
Number.isNaN(tokenPrice) ||
245+
!tokenPrices[checkGnotPath(item?.path)]?.usd ||
246+
!balances[item.priceID]
247+
) {
248+
return "$0";
249+
}
236250

237251
return formatPrice(
238252
BigNumber(tokenPrice)
@@ -252,6 +266,7 @@ const AssetListContainer: React.FC = () => {
252266
decimals: item.decimals,
253267
});
254268
})();
269+
255270
return {
256271
...item,
257272
price: price,
@@ -318,7 +333,9 @@ const AssetListContainer: React.FC = () => {
318333
assetType,
319334
keyword,
320335
isSwitchNetwork,
336+
connected,
321337
]);
338+
322339
const changeAssetType = useCallback((newType: string) => {
323340
switch (newType) {
324341
case ASSET_FILTER_TYPE.ALL:

packages/web/src/layouts/portfolio/containers/wallet-balance-container/WalletBalanceContainer.tsx

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ import WalletBalance from "../../components/wallet-balance/WalletBalance";
3434
import useSendAsset from "@hooks/wallet/data/useSendAsset";
3535
import { BROADCAST_ERROR_VALUE } from "@common/errors/broadcast/broadcast-error";
3636
import { useGnoswapContext } from "@hooks/common/use-gnoswap-context";
37+
import { BalanceSummaryInfo } from "@layouts/portfolio/components/wallet-balance/wallet-balance-summary/wallet-balance-summary-info/WalletBalanceSummaryInfo";
38+
import { BalanceDetailInfo } from "@layouts/portfolio/components/wallet-balance/wallet-balance-detail/WalletBalanceDetail";
3739

3840
const WalletBalanceContainer: React.FC = () => {
3941
const { rpcProvider } = useGnoswapContext();
@@ -250,24 +252,61 @@ const WalletBalanceContainer: React.FC = () => {
250252
);
251253
closeWithdraw();
252254
};
255+
256+
const balanceSummaryInfo: BalanceSummaryInfo = React.useMemo(() => {
257+
if (!connected || isSwitchNetwork) {
258+
return {
259+
amount: "-",
260+
changeRate: "-",
261+
loading: false,
262+
};
263+
}
264+
265+
return {
266+
amount: sumTotalBalance,
267+
changeRate: "0.0%",
268+
loading: loadingTotalBalance,
269+
};
270+
}, [connected, isSwitchNetwork, sumTotalBalance, loadingTotalBalance]);
271+
272+
const balanceDetailInfo: BalanceDetailInfo = React.useMemo(() => {
273+
if (!connected || isSwitchNetwork) {
274+
return {
275+
availableBalance: "-",
276+
claimableRewards: "-",
277+
stakedLP: "-",
278+
unstakedLP: "-",
279+
loadingBalance: false,
280+
loadingPositions: false,
281+
totalClaimedRewards: "-",
282+
};
283+
}
284+
return {
285+
availableBalance: `${availableBalanceStr}`,
286+
claimableRewards: `${claimableRewards}`,
287+
stakedLP: `${stakedBalance}`,
288+
unstakedLP: `${unStakedBalance}`,
289+
loadingBalance: loadingTotalBalance,
290+
loadingPositions: loadingTotalBalance,
291+
totalClaimedRewards: `${totalClaimedRewards}`,
292+
};
293+
}, [
294+
connected,
295+
isSwitchNetwork,
296+
availableBalanceStr,
297+
claimableRewards,
298+
stakedBalance,
299+
unStakedBalance,
300+
loadingTotalBalance,
301+
totalClaimedRewards,
302+
]);
303+
253304
return (
254305
<>
255306
<WalletBalance
256307
connected={connected}
257-
balanceSummaryInfo={{
258-
amount: isSwitchNetwork ? "$0" : sumTotalBalance,
259-
changeRate: "0.0%",
260-
loading: loadingTotalBalance,
261-
}}
262-
balanceDetailInfo={{
263-
availableBalance: isSwitchNetwork ? "-" : `${availableBalanceStr}`,
264-
claimableRewards: isSwitchNetwork ? "-" : `${claimableRewards}`,
265-
stakedLP: isSwitchNetwork ? "-" : `${stakedBalance}`,
266-
unstakedLP: unStakedBalance.toString(),
267-
loadingBalance: loadingTotalBalance,
268-
loadingPositions: loadingTotalBalance,
269-
totalClaimedRewards: totalClaimedRewards.toString(),
270-
}}
308+
balanceSummaryInfo={balanceSummaryInfo}
309+
balanceDetailInfo={balanceDetailInfo}
271310
deposit={deposit}
272311
withdraw={withdraw}
273312
claimAll={claimAllReward}

0 commit comments

Comments
 (0)