Skip to content

Commit

Permalink
Refactor some logic to check if a chain is evm only
Browse files Browse the repository at this point in the history
  • Loading branch information
delivan committed May 27, 2024
1 parent 6ba47a0 commit 9a289e1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/extension/src/components/address-book-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const AddressBookModal: FunctionComponent<{

const chainInfo = chainStore.getChain(recipientConfig.chainId);
const isEVMChain = chainInfo.evm !== undefined;
const isEVMOnlyChain = chainInfo.chainId.startsWith("eip155");
const isEVMOnlyChain = chainStore.isEvmOnlyChain(chainInfo.chainId);
const isERC20 = new DenomHelper(currency.coinMinimalDenom).type === "erc20";

const datas: {
Expand Down
5 changes: 3 additions & 2 deletions apps/extension/src/pages/main/available.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ export const AvailableTabView: FunctionComponent<{
const account = accountStore.getAccount(
viewToken.chainInfo.chainId
);
const isEVMOnlyChain =
viewToken.chainInfo.chainId.startsWith("eip155");
const isEVMOnlyChain = chainStore.isEvmOnlyChain(
viewToken.chainInfo.chainId
);

return isEVMOnlyChain
? account.ethereumHexAddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export const AddressChip: FunctionComponent<{
// modal 안에서는 배경색을 바꿈
inModal?: boolean;
}> = observer(({ chainId, inModal }) => {
const { accountStore } = useStore();
const { accountStore, chainStore } = useStore();

const isEVMOnlyChain = chainId.startsWith("eip155");
const isEVMOnlyChain = chainStore.isEvmOnlyChain(chainId);

const theme = useTheme();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ReceiveModal: FunctionComponent<{

const chainInfo = chainStore.getChain(chainId);
const account = accountStore.getAccount(chainId);
const isEVMOnlyChain = chainId.startsWith("eip155");
const isEVMOnlyChain = chainStore.isEvmOnlyChain(chainId);

return (
<Box
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/pages/send/amount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const SendAmountPage: FunctionComponent = observer(() => {
const chainId = initialChainId || chainStore.chainInfosInUI[0].chainId;
const chainInfo = chainStore.getChain(chainId);
const isEvmChain = chainStore.isEvmChain(chainId);
const isEVMOnlyChain = isEvmChain && chainId.split(":")[0] === "eip155";
const isEVMOnlyChain = chainStore.isEvmOnlyChain(chainId);

const coinMinimalDenom =
initialCoinMinimalDenom ||
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/tx/recipient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class RecipientConfig
}

const chainInfo = this.chainInfo;
const isEvmChain = !!EthereumAccountBase.evmInfo(this.chainInfo);
const isEvmChain = !!this.chainInfo.evm;
const hasEthereumAddress =
chainInfo.bip44.coinType === 60 ||
!!chainInfo.features?.includes("eth-address-gen") ||
Expand Down Expand Up @@ -258,7 +258,7 @@ export class RecipientConfig
}

const chainInfo = this.chainInfo;
const isEvmChain = !!EthereumAccountBase.evmInfo(this.chainInfo);
const isEvmChain = !!this.chainInfo.evm;
const hasEthereumAddress =
chainInfo.bip44.coinType === 60 ||
!!chainInfo.features?.includes("eth-address-gen") ||
Expand Down
11 changes: 3 additions & 8 deletions packages/stores-eth/src/account/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { simpleFetch } from "@keplr-wallet/simple-fetch";
import { ChainGetter } from "@keplr-wallet/stores";
import {
AppCurrency,
ChainInfo,
EthSignType,
EthTxReceipt,
Keplr,
Expand Down Expand Up @@ -31,10 +30,6 @@ export class EthereumAccountBase {
makeObservable(this);
}

static evmInfo(chainInfo: ChainInfo): ChainInfo["evm"] | undefined {
return chainInfo.evm;
}

@action
setIsSendingTx(value: boolean) {
this._isSendingTx = value;
Expand All @@ -56,7 +51,7 @@ export class EthereumAccountBase {
recipient: string;
}) {
const chainInfo = this.chainGetter.getChain(this.chainId);
const evmInfo = EthereumAccountBase.evmInfo(chainInfo);
const evmInfo = chainInfo.evm;
if (!evmInfo) {
throw new Error("No EVM chain info provided");
}
Expand Down Expand Up @@ -134,7 +129,7 @@ export class EthereumAccountBase {
maxPriorityFeePerGas: string;
}): Promise<UnsignedTransaction> {
const chainInfo = this.chainGetter.getChain(this.chainId);
const evmInfo = EthereumAccountBase.evmInfo(chainInfo);
const evmInfo = chainInfo.evm;
if (!evmInfo) {
throw new Error("No EVM chain info provided");
}
Expand Down Expand Up @@ -201,7 +196,7 @@ export class EthereumAccountBase {
) {
try {
const chainInfo = this.chainGetter.getChain(this.chainId);
const evmInfo = EthereumAccountBase.evmInfo(chainInfo);
const evmInfo = chainInfo.evm;
if (!evmInfo) {
throw new Error("No EVM info provided");
}
Expand Down
4 changes: 4 additions & 0 deletions packages/stores/src/chain/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,4 +594,8 @@ export class ChainStore<C extends ChainInfo = ChainInfo>
const chainInfo = this.getChain(chainId);
return chainInfo.evm !== undefined;
}

isEvmOnlyChain(chainId: string): boolean {
return this.isEvmChain(chainId) && chainId.split(":")[0] === "eip155";
}
}

0 comments on commit 9a289e1

Please sign in to comment.