diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 4500cbe..f0f8a57 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,3 +1,3 @@ -* @dmitry-tk +* @dmytrotkk *.md @skalenetwork/docowners /docs/ @skalenetwork/docowners diff --git a/src/components/AddToken.tsx b/src/components/AddToken.tsx index 1dccb66..5bad728 100644 --- a/src/components/AddToken.tsx +++ b/src/components/AddToken.tsx @@ -69,7 +69,13 @@ export default function AddToken(props: { ) const iconUrl = getIconUrl(props.token) try { - await enforceNetwork(props.ima.provider, walletClient, switchNetworkAsync) + await enforceNetwork( + props.ima.provider, + walletClient, + switchNetworkAsync, + props.mpc.config.skaleNetwork, + props.destChainName + ) const wasAdded = await window.ethereum.request({ method: 'wallet_watchAsset', params: { diff --git a/src/components/MetaportProvider.tsx b/src/components/MetaportProvider.tsx index 4f8a435..64b2a08 100644 --- a/src/components/MetaportProvider.tsx +++ b/src/components/MetaportProvider.tsx @@ -162,7 +162,8 @@ export default function MetaportProvider(props: { handle(props.tokens[key])} > -
+
> setBtnText: (btnText: string) => void - _switchNetwork: (chainId: number | bigint) => Chain | undefined + _switchNetwork: (chainId: number | bigint) => Promise constructor( mpc: MetaportCore, @@ -93,7 +93,7 @@ export class Action { token: TokenData, setAmountErrorMessage: (amountErrorMessage: string) => void, setBtnText: (btnText: string) => void, - switchNetwork: (chainId: number | bigint) => Chain | undefined, + switchNetwork: (chainId: number | bigint) => Promise, walletClient: WalletClient ) { this.mpc = mpc @@ -183,21 +183,18 @@ export class Action { async getConnectedChain( provider: Provider, customAbiTokenType?: CustomAbiTokenType, - destChainName?: string + destChainName?: string, + chainName?: string ): Promise { let chain: MainnetChain | SChain this.updateState('switch') - const currentChainId = this.walletClient.chain.id - const { chainId } = await provider.getNetwork() - log(`Current chainId: ${currentChainId}, required chainId: ${chainId} `) - if (currentChainId !== Number(chainId)) { - log(`Switching network to ${chainId}...`) - const chain = await this._switchNetwork(Number(chainId)) - if (!chain) { - throw new Error(`Failed to switch from ${currentChainId} to ${chainId} `) - } - log(`Network switched to ${chainId}...`) - } + const chainId = await enforceNetwork( + provider, + this.walletClient, + this._switchNetwork, + this.mpc.config.skaleNetwork, + chainName ?? this.chainName1 + ) const signer = walletClientToSigner(this.walletClient) if (isMainnetChainId(chainId, this.mpc.config.skaleNetwork)) { chain = new MainnetChain(signer.provider, getMainnetAbi(this.mpc.config.skaleNetwork)) diff --git a/src/core/actions/erc20.ts b/src/core/actions/erc20.ts index eecd984..9cb3dc5 100644 --- a/src/core/actions/erc20.ts +++ b/src/core/actions/erc20.ts @@ -221,7 +221,8 @@ export class UnWrapERC20S extends Action { const sChain = (await this.getConnectedChain( this.sChain2.provider, CustomAbiTokenType.erc20wrap, - this.chainName1 + this.chainName1, + this.chainName2 )) as SChain this.updateState('unwrap') let tx diff --git a/src/core/actions/eth.ts b/src/core/actions/eth.ts index b0dbcff..87caa76 100644 --- a/src/core/actions/eth.ts +++ b/src/core/actions/eth.ts @@ -100,7 +100,12 @@ export class UnlockEthM extends Action { async execute() { this.updateState('init') - const mainnet = (await this.getConnectedChain(this.mainnet.provider)) as MainnetChain + const mainnet = (await this.getConnectedChain( + this.mainnet.provider, + undefined, + undefined, + this.chainName2 + )) as MainnetChain this.updateState('unlock') const tx = await mainnet.eth.getMyEth({ address: this.address }) const block = await this.mainnet.provider.getBlock(tx.blockNumber) diff --git a/src/core/network.ts b/src/core/network.ts index ba5708d..35382ee 100644 --- a/src/core/network.ts +++ b/src/core/network.ts @@ -32,6 +32,7 @@ import proxyEndpoints from '../metadata/proxy.json' import { MAINNET_CHAIN_NAME } from './constants' import { IMA_ADDRESSES, IMA_ABIS } from './contracts' import { SkaleNetwork } from './interfaces' +import { constructWagmiChain } from './wagmi_network' export { proxyEndpoints as PROXY_ENDPOINTS } @@ -117,17 +118,24 @@ export function initSChain(network: SkaleNetwork, chainName: string): SChain { export async function enforceNetwork( provider: Provider, walletClient: WalletClient, - switchNetwork: (chainId: number | bigint) => Promise -): Promise { + switchNetwork: (chainId: number | bigint) => Promise, + skaleNetwork: SkaleNetwork, + chainName: string +): Promise { const currentChainId = walletClient.chain.id const { chainId } = await provider.getNetwork() log(`Current chainId: ${currentChainId}, required chainId: ${chainId} `) if (currentChainId !== Number(chainId)) { log(`Switching network to ${chainId}...`) - const chain = await switchNetwork(Number(chainId)) - if (!chain) { - throw new Error(`Failed to switch from ${currentChainId} to ${chainId} `) + if (chainId !== 1n && chainId !== 5n) { + await walletClient.addChain({ chain: constructWagmiChain(skaleNetwork, chainName) }) + } else { + const chain = await switchNetwork(Number(chainId)) + if (!chain) { + throw new Error(`Failed to switch from ${currentChainId} to ${chainId} `) + } } log(`Network switched to ${chainId}...`) } + return chainId } diff --git a/src/styles/_variables.scss b/src/styles/_variables.scss index 574effa..b0136dc 100644 --- a/src/styles/_variables.scss +++ b/src/styles/_variables.scss @@ -5,7 +5,7 @@ $sk-paper-color: RGB(136 135 135 / 15%); $sk-gray-background-color: rgba(161, 161, 161, 0.2); -$sk-btn-height: 47px; +$sk-btn-height: 52px; $sk-disabled-dark: rgba(255, 255, 255, 0.5); $sk-disabled-light: rgba(0, 0, 0, 0.38); diff --git a/src/styles/styles.module.scss b/src/styles/styles.module.scss index 0ab375b..a92fe36 100644 --- a/src/styles/styles.module.scss +++ b/src/styles/styles.module.scss @@ -303,8 +303,8 @@ button { line-height: 1.6 !important; letter-spacing: 0.02857em !important; font-weight: 600 !important; - padding-top: 0.8em !important; - padding-bottom: 0.8em !important; + padding-top: 0.9em !important; + padding-bottom: 0.9em !important; min-height: $sk-btn-height !important; border-radius: $sk-border-radius !important; box-shadow: none !important;