Skip to content

Commit 4607193

Browse files
committed
adjust for ModularChainInfo conversion after Supernova update
1 parent 9414a3d commit 4607193

File tree

12 files changed

+99
-96
lines changed

12 files changed

+99
-96
lines changed

apps/extension/src/hooks/analytics/use-insufficient-fee-analytics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export const useInsufficientFeeAnalytics = (
5959
analyticsAmplitudeStore.logEvent("view_insufficient_fee_error", {
6060
pathname,
6161
chainIdentifier: ChainIdHelper.parse(chainId).identifier,
62-
chainName: chainStore.hasChain(chainId)
63-
? chainStore.getChain(chainId).chainName
62+
chainName: chainStore.hasModularChain(chainId)
63+
? chainStore.getModularChain(chainId).chainName
6464
: undefined,
6565
feeCurrencyDenom: feeConfig.fees[0].currency.coinMinimalDenom,
6666
});

apps/extension/src/hooks/use-rewards.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { CoinPretty, Dec, PricePretty } from "@keplr-wallet/unit";
1010
import { NEUTRON_CHAIN_ID, NOBLE_CHAIN_ID } from "../config.ui";
1111
import { ModularChainInfo } from "@keplr-wallet/types";
1212
import { ClaimAllEachState } from "../stores/claim-rewards-state";
13+
import { ChainIdHelper } from "@keplr-wallet/cosmos";
1314

1415
export interface ViewClaimToken extends Omit<ViewToken, "chainInfo"> {
1516
modularChainInfo: ModularChainInfo;
@@ -85,19 +86,15 @@ export function useRewards() {
8586
});
8687
}
8788
} else if ("cosmos" in modularChainInfo) {
88-
const isEVMOnly = chainStore.isEvmOnlyChain(chainId);
89-
if (isEVMOnly) {
90-
continue;
91-
}
92-
9389
const accountAddress = account.bech32Address;
94-
const chainInfo = chainStore.getChain(chainId);
9590
const queries = queriesStore.get(chainId);
9691

9792
if (chainId === NOBLE_CHAIN_ID) {
9893
const queryYield =
9994
queries.noble.queryYield.getQueryBech32Address(accountAddress);
100-
const usdnCurrency = chainInfo.findCurrency("uusdn") || USDN_CURRENCY;
95+
const usdnCurrency =
96+
chainStore.getModularChainInfoImpl(chainId).findCurrency("uusdn") ||
97+
USDN_CURRENCY;
10198
const rawAmount = queryYield.claimableAmount;
10299
const amount = new CoinPretty(usdnCurrency, rawAmount);
103100
if (amount.toDec().gt(new Dec(0))) {
@@ -117,19 +114,24 @@ export function useRewards() {
117114
queries.cosmos.queryRewards.getQueryBech32Address(accountAddress);
118115

119116
const targetDenom = (() => {
120-
if (chainInfo.chainIdentifier === "dydx-mainnet") {
117+
const chainIdentifier = ChainIdHelper.parse(chainId).identifier;
118+
if (chainIdentifier === "dydx-mainnet") {
121119
return "ibc/8E27BA2D5493AF5636760E354E46004562C46AB7EC0CC4C1CA14E9E20E2545B5";
122120
}
123121

124-
if (chainInfo.chainIdentifier === "elys") {
122+
if (chainIdentifier === "elys") {
125123
return "ueden";
126124
}
127125

128-
return chainInfo.stakeCurrency?.coinMinimalDenom;
126+
return "cosmos" in modularChainInfo
127+
? modularChainInfo.cosmos.stakeCurrency?.coinMinimalDenom
128+
: undefined;
129129
})();
130130

131131
if (targetDenom) {
132-
const currency = chainInfo.findCurrency(targetDenom);
132+
const currency = chainStore
133+
.getModularChainInfoImpl(chainId)
134+
.findCurrency(targetDenom);
133135
if (currency) {
134136
const reward = queryRewards.rewards.find(
135137
(r) => r.currency.coinMinimalDenom === targetDenom

apps/extension/src/hooks/use-staked-total-price.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useMemo } from "react";
22
import { useStore } from "../stores";
33
import { PricePretty } from "@keplr-wallet/unit";
4-
import { ChainInfoWithCoreTypes } from "@keplr-wallet/background";
54

65
export function useStakedTotalPrice() {
76
const { hugeQueriesStore, priceStore } = useStore();
@@ -32,10 +31,7 @@ export function useStakedTotalPrice() {
3231
const stakedTotalPriceEmbedOnlyUSD = useMemo(() => {
3332
let result: PricePretty | undefined;
3433
for (const bal of hugeQueriesStore.delegations) {
35-
if (!("currencies" in bal.chainInfo)) {
36-
continue;
37-
}
38-
if (!(bal.chainInfo.embedded as ChainInfoWithCoreTypes).embedded) {
34+
if (!("cosmos" in bal.chainInfo)) {
3935
continue;
4036
}
4137
if (bal.price) {
@@ -50,10 +46,7 @@ export function useStakedTotalPrice() {
5046
}
5147
}
5248
for (const bal of hugeQueriesStore.unbondings) {
53-
if (!("currencies" in bal.chainInfo)) {
54-
continue;
55-
}
56-
if (!(bal.chainInfo.embedded as ChainInfoWithCoreTypes).embedded) {
49+
if (!("cosmos" in bal.chainInfo)) {
5750
continue;
5851
}
5952
if (bal.price) {

apps/extension/src/pages/ibc-swap/hooks/use-swap-analytics.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ export const useSwapAnalytics = ({
154154
const inChainIdentifier = ChainIdHelper.parse(inChainId).identifier;
155155
const outChainIdentifier = ChainIdHelper.parse(outChainId).identifier;
156156

157-
const inChainName = chainStore.hasChain(inChainId)
158-
? chainStore.getChain(inChainId).chainName
157+
const inChainName = chainStore.hasModularChain(inChainId)
158+
? chainStore.getModularChain(inChainId).chainName
159159
: undefined;
160-
const outChainName = chainStore.hasChain(outChainId)
161-
? chainStore.getChain(outChainId).chainName
160+
const outChainName = chainStore.hasModularChain(outChainId)
161+
? chainStore.getModularChain(outChainId).chainName
162162
: undefined;
163163

164164
// source selected
@@ -429,8 +429,8 @@ function getChainProperties(
429429
const chainIdentifier = Number.isNaN(parseInt(_chainIdentifier, 10))
430430
? _chainIdentifier
431431
: `eip155:${_chainIdentifier}`;
432-
const chain = chainStore.hasChain(chainIdentifier)
433-
? chainStore.getChain(chainIdentifier)
432+
const chain = chainStore.hasModularChain(chainIdentifier)
433+
? chainStore.getModularChainInfoImpl(chainIdentifier)
434434
: undefined;
435435

436436
if (!chain) {
@@ -449,7 +449,7 @@ function getChainProperties(
449449

450450
return {
451451
chainIdentifier,
452-
chainName: chain.chainName,
452+
chainName: chain.embedded.chainName,
453453
coinDenom: currency.coinDenom,
454454
amountUsd: price ? price.toDec().toString() : undefined,
455455
};

apps/extension/src/pages/main/components/account-switch-float-modal/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const AccountSwitchFloatModal = observer(
6868
if (uiConfigStore.icnsInfo) {
6969
const keysSettled =
7070
await uiConfigStore.addressBookConfig.getVaultCosmosKeysSettled(
71-
chainStore.getChain(uiConfigStore.icnsInfo.chainId).chainId
71+
chainStore.getModularChain(uiConfigStore.icnsInfo.chainId).chainId
7272
);
7373
const addressMap = new Map<string, string>();
7474
keysSettled.forEach((res) => {

apps/extension/src/pages/main/components/copy-address-item/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ export const CopyAddressItem = observer(
6767
}: CopyAddressItemProps,
6868
ref
6969
) {
70-
const { analyticsStore, keyRingStore, uiConfigStore, chainStore } =
71-
useStore();
70+
const { analyticsStore, keyRingStore, uiConfigStore } = useStore();
7271

7372
const theme = useTheme();
7473

apps/extension/src/pages/main/components/deposit-modal/qr-code.tsx

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -309,30 +309,25 @@ const AddressDisplay = ({
309309
const account = accountStore.getAccount(chainId);
310310
const theme = useTheme();
311311

312-
const isEVMOnlyChain = (() => {
313-
if ("cosmos" in modularChainInfo) {
314-
return chainStore.isEvmOnlyChain(chainId);
315-
}
316-
return false;
317-
})();
312+
const isEVMOnlyChain =
313+
"evm" in modularChainInfo && chainStore.isEvmOnlyChain(chainId);
318314

319315
const displayAddress = useMemo<DisplayAddress>(() => {
320316
const LENGTH_OF_FIRST_PART = 10;
321317
const LENGTH_OF_LAST_PART = 6;
322318

323-
if ("cosmos" in modularChainInfo) {
324-
if (isEVMOnlyChain) {
325-
return {
326-
former: account.ethereumHexAddress.slice(0, LENGTH_OF_FIRST_PART),
327-
middle: account.ethereumHexAddress.slice(
328-
LENGTH_OF_FIRST_PART,
329-
account.ethereumHexAddress.length - LENGTH_OF_LAST_PART
330-
),
331-
latter: account.ethereumHexAddress.slice(
332-
account.ethereumHexAddress.length - LENGTH_OF_LAST_PART
333-
),
334-
};
335-
}
319+
if (isEVMOnlyChain) {
320+
return {
321+
former: account.ethereumHexAddress.slice(0, LENGTH_OF_FIRST_PART),
322+
middle: account.ethereumHexAddress.slice(
323+
LENGTH_OF_FIRST_PART,
324+
account.ethereumHexAddress.length - LENGTH_OF_LAST_PART
325+
),
326+
latter: account.ethereumHexAddress.slice(
327+
account.ethereumHexAddress.length - LENGTH_OF_LAST_PART
328+
),
329+
};
330+
} else if ("cosmos" in modularChainInfo) {
336331
return {
337332
former: account.bech32Address.slice(0, LENGTH_OF_FIRST_PART),
338333
middle: account.bech32Address.slice(
@@ -381,12 +376,10 @@ const AddressDisplay = ({
381376
onClick={(e) => {
382377
e.preventDefault();
383378

384-
if ("cosmos" in modularChainInfo) {
385-
navigator.clipboard.writeText(
386-
isEVMOnlyChain
387-
? account.ethereumHexAddress
388-
: account.bech32Address
389-
);
379+
if (isEVMOnlyChain) {
380+
navigator.clipboard.writeText(account.ethereumHexAddress);
381+
} else if ("cosmos" in modularChainInfo) {
382+
navigator.clipboard.writeText(account.bech32Address);
390383
} else if ("starknet" in modularChainInfo) {
391384
navigator.clipboard.writeText(account.starknetHexAddress);
392385
} else if ("bitcoin" in modularChainInfo) {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ export const StakeEmptyPage: FunctionComponent = observer(() => {
8484
const isStarknet = "starknet" in viewToken.chainInfo;
8585
const stakingUrl = isStarknet
8686
? "https://dashboard.endur.fi/stake"
87-
: "walletUrlForStaking" in viewToken.chainInfo
88-
? viewToken.chainInfo.walletUrlForStaking
87+
: "cosmos" in viewToken.chainInfo &&
88+
!!viewToken.chainInfo.cosmos.walletUrlForStaking
89+
? viewToken.chainInfo.cosmos.walletUrlForStaking
8990
: undefined;
9091

9192
const stakingAprDec = useGetStakingApr(viewToken.chainInfo.chainId);

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,26 @@ export const StakeExplorePage: FunctionComponent = observer(() => {
6868

6969
const stakeCurrencyItems = useMemo<StakeCurrencyItem[]>(() => {
7070
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-
});
81-
}
8271

8372
for (const modularChainInfo of chainStore.modularChainInfos) {
84-
if ("starknet" in modularChainInfo) {
73+
if ("cosmos" in modularChainInfo) {
74+
if (
75+
modularChainInfo.isTestnet ||
76+
!modularChainInfo.cosmos.stakeCurrency
77+
) {
78+
continue;
79+
}
80+
81+
const key = `${
82+
ChainIdHelper.parse(modularChainInfo.chainId).identifier
83+
}/${modularChainInfo.cosmos.stakeCurrency.coinMinimalDenom}`;
84+
85+
items.push({
86+
key,
87+
chainInfo: modularChainInfo,
88+
currency: modularChainInfo.cosmos.stakeCurrency,
89+
});
90+
} else if ("starknet" in modularChainInfo) {
8591
if (modularChainInfo.isTestnet) {
8692
continue;
8793
}
@@ -93,7 +99,8 @@ export const StakeExplorePage: FunctionComponent = observer(() => {
9399
const modularChainInfoImpl = chainStore.getModularChainInfoImpl(
94100
modularChainInfo.chainId
95101
);
96-
const currencies = modularChainInfoImpl.getCurrencies("starknet");
102+
const currencies =
103+
modularChainInfoImpl.getCurrenciesByModule("starknet");
97104
if (currencies.length === 0) {
98105
continue;
99106
}

apps/extension/src/stores/claim-rewards-state/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { action, makeObservable, observable, computed } from "mobx";
2-
import { ChainStore } from "../chain";
32
import { KeyRingStore } from "@keplr-wallet/stores-core";
3+
import { ChainIdHelper } from "@keplr-wallet/cosmos";
44

55
export class ClaimAllEachState {
66
@observable
@@ -61,7 +61,6 @@ export class ClaimRewardsStateStore {
6161
private readonly map = new Map<string, ClaimAllEachState>();
6262

6363
constructor(
64-
private readonly chainStore: ChainStore,
6564
private readonly keyRingStore: KeyRingStore,
6665
private readonly eventListener: {
6766
addEventListener: (type: string, fn: () => unknown) => void;
@@ -73,9 +72,7 @@ export class ClaimRewardsStateStore {
7372
}
7473

7574
private key(chainId: string) {
76-
const chainIdentifier = this.chainStore.hasChain(chainId)
77-
? this.chainStore.getChain(chainId).chainIdentifier
78-
: chainId;
75+
const chainIdentifier = ChainIdHelper.parse(chainId).identifier;
7976
const keyId = this.keyRingStore.selectedKeyInfo?.id ?? "unknown";
8077
return `${keyId}:${chainIdentifier}`;
8178
}

0 commit comments

Comments
 (0)