Skip to content

Commit fa0f20f

Browse files
authored
Merge pull request #1671 from chainapsis/sam/keplr-1453
Hard-code top 4 chains in stake explore page
2 parents d86b6c0 + 83d31a1 commit fa0f20f

File tree

1 file changed

+90
-30
lines changed

1 file changed

+90
-30
lines changed

apps/extension/src/pages/stake/explore.tsx

Lines changed: 90 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { observer } from "mobx-react-lite";
2-
import React, { FunctionComponent, useState } from "react";
2+
import React, { FunctionComponent, useMemo, useState } from "react";
33
import { MainHeaderLayout } from "../main/layouts/header";
44
import styled, { useTheme } from "styled-components";
55
import { ColorPalette } from "../../styles";
@@ -33,13 +33,28 @@ import { IconProps } from "../../components/icon/types";
3333
import { ChainIdHelper } from "@keplr-wallet/cosmos";
3434
import { COMMON_HOVER_OPACITY } from "../../styles/constant";
3535

36+
const priority = (chainId: string) => {
37+
const id = ChainIdHelper.parse(chainId).identifier;
38+
if (id === "cosmoshub") return 0;
39+
if (id === "osmosis") return 1;
40+
if (id === "celestia") return 2;
41+
if (id === "injective") return 3;
42+
return 4;
43+
};
44+
45+
type StakeCurrencyItem = {
46+
key: string;
47+
chainInfo: ViewToken["chainInfo"];
48+
currency: ViewToken["token"]["currency"];
49+
};
50+
3651
export const StakeExplorePage: FunctionComponent = observer(() => {
3752
const theme = useTheme();
3853
const intl = useIntl();
3954

4055
const [searchParams] = useSearchParams();
4156

42-
const { hugeQueriesStore } = useStore();
57+
const { chainStore } = useStore();
4358

4459
const [isOpenDepositModal, setIsOpenDepositModal] = React.useState(false);
4560
const [isOpenBuy, setIsOpenBuy] = React.useState(false);
@@ -51,22 +66,65 @@ export const StakeExplorePage: FunctionComponent = observer(() => {
5166

5267
const showBackButton = searchParams.get("showBackButton") === "true";
5368

54-
const priority = (chainId: string) => {
55-
const id = ChainIdHelper.parse(chainId).identifier;
56-
if (id === "cosmoshub") return 0;
57-
if (id === "osmosis") return 1;
58-
if (id === "injective") return 2;
59-
if (id === "starknet:SN_MAIN") return 3;
60-
return 4;
61-
};
62-
63-
const stakables = [...hugeQueriesStore.stakables].sort((a, b) => {
64-
const diff = priority(a.chainInfo.chainId) - priority(b.chainInfo.chainId);
65-
if (diff !== 0) {
66-
return diff;
69+
const stakeCurrencyItems = useMemo<StakeCurrencyItem[]>(() => {
70+
const items: StakeCurrencyItem[] = [];
71+
for (const chainInfo of chainStore.chainInfos) {
72+
if (chainInfo.isTestnet || !chainInfo.stakeCurrency) {
73+
continue;
74+
}
75+
const key = `${chainInfo.chainIdentifier}/${chainInfo.stakeCurrency.coinMinimalDenom}`;
76+
items.push({
77+
key,
78+
chainInfo: chainInfo,
79+
currency: chainInfo.stakeCurrency,
80+
});
6781
}
68-
return a.token.currency.coinDenom.localeCompare(b.token.currency.coinDenom);
69-
});
82+
83+
for (const modularChainInfo of chainStore.modularChainInfos) {
84+
if ("starknet" in modularChainInfo) {
85+
if (modularChainInfo.isTestnet) {
86+
continue;
87+
}
88+
89+
const chainIdentifier = ChainIdHelper.parse(
90+
modularChainInfo.chainId
91+
).identifier;
92+
93+
const modularChainInfoImpl = chainStore.getModularChainInfoImpl(
94+
modularChainInfo.chainId
95+
);
96+
const currencies = modularChainInfoImpl.getCurrencies("starknet");
97+
if (currencies.length === 0) {
98+
continue;
99+
}
100+
101+
const strkContractAddress =
102+
modularChainInfo.starknet.strkContractAddress;
103+
const strkDenom = `erc20:${strkContractAddress.toLowerCase()}`;
104+
const strkCurrency = currencies.find(
105+
(currency) => currency.coinMinimalDenom === strkDenom
106+
);
107+
if (!strkCurrency) {
108+
continue;
109+
}
110+
const strkKey = `${chainIdentifier}/${strkDenom}`;
111+
items.push({
112+
key: strkKey,
113+
chainInfo: modularChainInfo,
114+
currency: strkCurrency,
115+
});
116+
}
117+
}
118+
119+
return items.sort((a, b) => {
120+
const diff =
121+
priority(a.chainInfo.chainId) - priority(b.chainInfo.chainId);
122+
if (diff !== 0) {
123+
return diff;
124+
}
125+
return a.currency.coinDenom.localeCompare(b.currency.coinDenom);
126+
});
127+
}, [chainStore]);
70128

71129
return (
72130
<MainHeaderLayout>
@@ -114,12 +172,14 @@ export const StakeExplorePage: FunctionComponent = observer(() => {
114172
<Gutter size="1.25rem" />
115173

116174
<CollapsibleGrid
117-
items={stakables.map((stakable) => (
175+
items={stakeCurrencyItems.map((item) => (
118176
<AssetCard
119-
key={`${stakable.chainInfo.chainId}-${stakable.token.currency.coinMinimalDenom}`}
120-
viewToken={stakable}
177+
key={item.key}
178+
chainId={item.chainInfo.chainId}
179+
chainInfo={item.chainInfo}
180+
currency={item.currency}
121181
onClick={() => {
122-
setDepositInitialSearch(stakable.chainInfo.chainName);
182+
setDepositInitialSearch(item.chainInfo.chainName);
123183
setIsOpenDepositModal(true);
124184
}}
125185
/>
@@ -223,17 +283,19 @@ const CollapsibleGrid: FunctionComponent<{
223283
};
224284

225285
const AssetCard: FunctionComponent<{
226-
viewToken: ViewToken;
286+
chainId: string;
287+
chainInfo: ViewToken["chainInfo"];
288+
currency: ViewToken["token"]["currency"];
227289
onClick: () => void;
228-
}> = observer(({ viewToken, onClick }) => {
229-
const stakingAprDec = useGetStakingApr(viewToken.chainInfo.chainId);
290+
}> = observer(({ chainId, chainInfo, currency, onClick }) => {
291+
const stakingAprDec = useGetStakingApr(chainId);
230292
const theme = useTheme();
231293

232294
return (
233295
<Styles.AssetCard onClick={onClick}>
234296
<CurrencyImageFallback
235-
chainInfo={viewToken.chainInfo}
236-
currency={viewToken.token.currency}
297+
chainInfo={chainInfo}
298+
currency={currency}
237299
size="2rem"
238300
/>
239301
<Gutter size="0.75rem" />
@@ -245,7 +307,7 @@ const AssetCard: FunctionComponent<{
245307
: ColorPalette["gray-10"]
246308
}
247309
>
248-
{viewToken.token.currency.coinDenom}
310+
{currency.coinDenom}
249311
</Subtitle2>
250312
<Gutter size="0.25rem" />
251313
<Subtitle3
@@ -259,9 +321,7 @@ const AssetCard: FunctionComponent<{
259321
</Subtitle3>
260322
</XAxis>
261323
<Gutter size="0.25rem" />
262-
<Body3 color={ColorPalette["gray-300"]}>
263-
{viewToken.chainInfo.chainName}
264-
</Body3>
324+
<Body3 color={ColorPalette["gray-300"]}>{chainInfo.chainName}</Body3>
265325
</Styles.AssetCard>
266326
);
267327
});

0 commit comments

Comments
 (0)