From 97d6b7711dbe0f736e36bbee8de395461774e7b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Wed, 30 Oct 2024 12:30:03 +0100 Subject: [PATCH 01/17] Coinbase Wallet --- src/assets/icons/CoinbaseWalletLogo.svg | 1 + .../accounts/Web3ConnectAccount.styled.ts | 14 +++++++---- .../accounts/Web3ConnectEvmAccount.tsx | 5 ++-- .../web3-connect/constants/providers.ts | 2 ++ .../web3-connect/wallets/CoinbaseWallet.ts | 23 +++++++++++++++++++ src/sections/web3-connect/wallets/index.ts | 13 +++++++++++ src/utils/metamask.ts | 5 ++++ 7 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 src/assets/icons/CoinbaseWalletLogo.svg create mode 100644 src/sections/web3-connect/wallets/CoinbaseWallet.ts diff --git a/src/assets/icons/CoinbaseWalletLogo.svg b/src/assets/icons/CoinbaseWalletLogo.svg new file mode 100644 index 000000000..9a67c6423 --- /dev/null +++ b/src/assets/icons/CoinbaseWalletLogo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/sections/web3-connect/accounts/Web3ConnectAccount.styled.ts b/src/sections/web3-connect/accounts/Web3ConnectAccount.styled.ts index a7727afad..a904ae703 100644 --- a/src/sections/web3-connect/accounts/Web3ConnectAccount.styled.ts +++ b/src/sections/web3-connect/accounts/Web3ConnectAccount.styled.ts @@ -68,13 +68,19 @@ export const SAccountItem = styled.div<{ }} ` -export const SChangeAccountButton = styled(Button)` - border: 1px solid rgba(${theme.rgbColors.brightBlue300}, 0.12); - border-top-color: transparent; +export const SChangeAccountButton = styled(Button)<{ isActive?: boolean }>` + border: 1px solid transparent; + border-color: ${({ isActive }) => + isActive ? `rgba(${theme.rgbColors.brightBlue300}, 0.12)` : ""}; + border-top-color: ${({ isActive }) => + isActive ? `transparent` : `rgba(${theme.rgbColors.alpha0}, 0.12)`}; border-radius: ${theme.borderRadius.medium}px; border-top-left-radius: 0; border-top-right-radius: 0; - background: rgba(${theme.rgbColors.primaryA15}, 0.12); + background: ${({ isActive }) => + isActive + ? `rgba(${theme.rgbColors.primaryA15}, 0.12)` + : `rgba(${theme.rgbColors.alpha0}, 0.06)`}; ` diff --git a/src/sections/web3-connect/accounts/Web3ConnectEvmAccount.tsx b/src/sections/web3-connect/accounts/Web3ConnectEvmAccount.tsx index 6c9c1b252..fd7c617a1 100644 --- a/src/sections/web3-connect/accounts/Web3ConnectEvmAccount.tsx +++ b/src/sections/web3-connect/accounts/Web3ConnectEvmAccount.tsx @@ -26,9 +26,7 @@ export const Web3ConnectEvmAccount: FC< // Allow account changing for MetaMask wallets, // but disable for MetaMask-like as it doesn't provide a way to open the account selection programmatically const shouldAllowAccountChange = - isActive && - isMetaMask(wallet?.extension) && - !isMetaMaskLike(wallet?.extension) + isMetaMask(wallet?.extension) && !isMetaMaskLike(wallet?.extension) return (
@@ -51,6 +49,7 @@ export const Web3ConnectEvmAccount: FC< {shouldAllowAccountChange && ( { if (!session) { @@ -103,6 +110,7 @@ export let SUPPORTED_WALLET_PROVIDERS: WalletProvider[] = [ talismanEvm, subwalletEvm, subwallet, + coinbaseWallet, //trustWallet, novaWallet, walletConnect, @@ -150,6 +158,10 @@ const eip6963ProvidersByRdns = new Map([ "com.brave.wallet", { Wallet: BraveWallet, type: WalletProviderType.BraveWallet }, ], + [ + "com.coinbase.wallet", + { Wallet: CoinbaseWallet, type: WalletProviderType.CoinbaseWallet }, + ], ]) /** @@ -157,6 +169,7 @@ const eip6963ProvidersByRdns = new Map([ * For more information, refer to https://eips.ethereum.org/EIPS/eip-6963 */ export function handleAnnounceProvider(event: EIP6963AnnounceProviderEvent) { + console.log(event.detail) const provider = eip6963ProvidersByRdns.get(event.detail.info.rdns) if (provider) { diff --git a/src/utils/metamask.ts b/src/utils/metamask.ts index 94062a258..3a9935840 100644 --- a/src/utils/metamask.ts +++ b/src/utils/metamask.ts @@ -13,6 +13,7 @@ const METAMASK_LIKE_CHECKS = [ "isTrust", "isBraveWallet", "isEnkrypt", + "isCoinbaseWallet", ] as const type MetaMaskLikeChecksValues = (typeof METAMASK_LIKE_CHECKS)[number] @@ -97,6 +98,10 @@ export function isBraveWallet(provider: Maybe) { return isMetaMaskLike(provider) && !!provider?.isBraveWallet } +export function isCoinbaseWallet(provider: Maybe) { + return isMetaMaskLike(provider) && !!provider?.isCoinbaseWallet +} + export function isEnkrypt(provider: Maybe) { return isMetaMaskLike(provider) && !!provider?.isEnkrypt } From 47a60f0ebb5882b45641e1a69e6dd7b6250d8f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Wed, 30 Oct 2024 12:52:00 +0100 Subject: [PATCH 02/17] switch network for permit nonce --- src/sections/web3-connect/signer/EthereumSigner.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sections/web3-connect/signer/EthereumSigner.ts b/src/sections/web3-connect/signer/EthereumSigner.ts index f61ad55b6..0b3601c8c 100644 --- a/src/sections/web3-connect/signer/EthereumSigner.ts +++ b/src/sections/web3-connect/signer/EthereumSigner.ts @@ -82,6 +82,7 @@ export class EthereumSigner { } getPermitNonce = async (): Promise => { + await this.requestNetworkSwitch("hydration") const callPermit = new Contract( CALL_PERMIT_ADDRESS, CALL_PERMIT_ABI, From 86bce8f8e310e4b37182dbda0aebcc1e1b660096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Fri, 15 Nov 2024 18:52:38 +0100 Subject: [PATCH 03/17] Use JsonRpcProvider to fetch permit nonce, workaround for Coinbase wallet --- .../transaction/ReviewTransaction.utils.tsx | 34 +++++++++++++------ .../web3-connect/signer/EthereumSigner.ts | 31 +++++------------ src/sections/web3-connect/wallets/index.ts | 1 - 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/sections/transaction/ReviewTransaction.utils.tsx b/src/sections/transaction/ReviewTransaction.utils.tsx index df9b60287..e021b18b5 100644 --- a/src/sections/transaction/ReviewTransaction.utils.tsx +++ b/src/sections/transaction/ReviewTransaction.utils.tsx @@ -1,4 +1,5 @@ import { + JsonRpcProvider, TransactionReceipt, TransactionResponse, Web3Provider, @@ -27,13 +28,12 @@ import { useEvmAccount, useWallet, } from "sections/web3-connect/Web3Connect.utils" -import { - EthereumSigner, - PermitResult, -} from "sections/web3-connect/signer/EthereumSigner" +import { PermitResult } from "sections/web3-connect/signer/EthereumSigner" import { useSettingsStore } from "state/store" import { useToast } from "state/toasts" import { + CALL_PERMIT_ABI, + CALL_PERMIT_ADDRESS, H160, getEvmChainById, getEvmTxLink, @@ -43,7 +43,9 @@ import { import { isAnyParachain, Maybe } from "utils/helpers" import { createSubscanLink } from "utils/formatting" import { QUERY_KEYS } from "utils/queryKeys" -import { useIsTestnet } from "api/provider" +import { useActiveProvider, useIsTestnet } from "api/provider" +import BigNumber from "bignumber.js" +import { Contract } from "ethers" const EVM_PERMIT_BLOCKTIME = 20_000 @@ -237,17 +239,27 @@ export const useSendEvmTransactionMutation = ( } export function useNextEvmPermitNonce(account: Maybe) { - const { wallet } = useWallet() - + const activeProvider = useActiveProvider() return useQuery( QUERY_KEYS.nextEvmPermitNonce(account), async () => { if (!account) throw new Error("Missing address") - if (!wallet?.signer) throw new Error("Missing wallet signer") - if (!(wallet?.signer instanceof EthereumSigner)) - throw new Error("Invalid signer") - return wallet.signer.getPermitNonce() + const provider = new JsonRpcProvider( + activeProvider.url.replace("wss", "https"), + ) + + const callPermit = new Contract( + CALL_PERMIT_ADDRESS, + CALL_PERMIT_ABI, + provider, + ) + + const nonce = await callPermit.nonces( + H160.fromAccount(account.toString()), + ) + + return BigNumber(nonce.toString()) }, { refetchInterval: EVM_PERMIT_BLOCKTIME, diff --git a/src/sections/web3-connect/signer/EthereumSigner.ts b/src/sections/web3-connect/signer/EthereumSigner.ts index 0b3601c8c..61265ed10 100644 --- a/src/sections/web3-connect/signer/EthereumSigner.ts +++ b/src/sections/web3-connect/signer/EthereumSigner.ts @@ -6,19 +6,16 @@ import { import UniversalProvider from "@walletconnect/universal-provider/dist/types/UniversalProvider" import BigNumber from "bignumber.js" -import { Contract, Signature } from "ethers" +import { Signature } from "ethers" import { splitSignature } from "ethers/lib/utils" -import { - CALL_PERMIT_ABI, - CALL_PERMIT_ADDRESS, - DISPATCH_ADDRESS, -} from "utils/evm" +import { CALL_PERMIT_ADDRESS, DISPATCH_ADDRESS } from "utils/evm" import { MetaMaskLikeProvider, isEthereumProvider, requestNetworkSwitch, } from "utils/metamask" import { chainsMap } from "@galacticcouncil/xcm-cfg" +import { sleep } from "utils/helpers" type PermitMessage = { from: string @@ -64,11 +61,12 @@ export class EthereumSigner { if (isEthereumProvider(this.provider)) { await requestNetworkSwitch(this.provider, { chain, - onSwitch: () => { - // update signer after network switch - this.signer = this.getSigner(this.provider) - }, }) + // update signer after network switch + // give some leeway for the network switch to take effect, + // some wallets like Coinbase dont reflect the change inside provider immediately + await sleep(200) + this.signer = this.getSigner(this.provider) } } @@ -81,19 +79,6 @@ export class EthereumSigner { }) } - getPermitNonce = async (): Promise => { - await this.requestNetworkSwitch("hydration") - const callPermit = new Contract( - CALL_PERMIT_ADDRESS, - CALL_PERMIT_ABI, - this.signer.provider, - ) - - const nonce = await callPermit.nonces(this.address) - - return BigNumber(nonce.toString()) - } - getPermit = async (data: string, nonce: BigNumber): Promise => { if (this.provider && this.address) { await this.requestNetworkSwitch("hydration") diff --git a/src/sections/web3-connect/wallets/index.ts b/src/sections/web3-connect/wallets/index.ts index f773bcac6..7e41af14c 100644 --- a/src/sections/web3-connect/wallets/index.ts +++ b/src/sections/web3-connect/wallets/index.ts @@ -169,7 +169,6 @@ const eip6963ProvidersByRdns = new Map([ * For more information, refer to https://eips.ethereum.org/EIPS/eip-6963 */ export function handleAnnounceProvider(event: EIP6963AnnounceProviderEvent) { - console.log(event.detail) const provider = eip6963ProvidersByRdns.get(event.detail.info.rdns) if (provider) { From 9d5a843e09b14ad0f8d72a6df6876e3ff34f8647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Tue, 19 Nov 2024 14:18:05 +0100 Subject: [PATCH 04/17] always fetch evm nonce in EthereumSigner --- src/sections/web3-connect/signer/EthereumSigner.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/sections/web3-connect/signer/EthereumSigner.ts b/src/sections/web3-connect/signer/EthereumSigner.ts index 61265ed10..733efbb13 100644 --- a/src/sections/web3-connect/signer/EthereumSigner.ts +++ b/src/sections/web3-connect/signer/EthereumSigner.ts @@ -54,6 +54,7 @@ export class EthereumSigner { return Promise.all([ this.signer.provider.estimateGas(tx), this.signer.provider.getGasPrice(), + this.signer.provider.getFeeData(), ]) } @@ -203,15 +204,17 @@ export class EthereumSigner { await this.requestNetworkSwitch(from) if (from === "hydration") { - const [gas, gasPrice] = await this.getGasValues(tx) + const [gas, gasPrice, feeData] = await this.getGasValues(tx) const onePrc = gasPrice.div(100) const gasPricePlus = gasPrice.add(onePrc) return await this.signer.sendTransaction({ - maxPriorityFeePerGas: gasPricePlus, - maxFeePerGas: gasPricePlus, + maxPriorityFeePerGas: + feeData.maxPriorityFeePerGas?.toString() ?? gasPricePlus, + maxFeePerGas: feeData.maxFeePerGas?.toString() ?? gasPricePlus, gasLimit: gas.mul(11).div(10), // add 10% + nonce: await this.signer.getTransactionCount(), ...tx, }) } else { From ef249c81d2829473d5540598f0dddec24fe76e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Tue, 26 Nov 2024 16:26:19 +0100 Subject: [PATCH 05/17] Nightly wallet --- src/assets/icons/NightlyLogo.svg | 4 +++ .../web3-connect/constants/providers.ts | 4 +++ src/sections/web3-connect/wallets/Nightly.ts | 27 +++++++++++++++++++ .../web3-connect/wallets/NightlyEvm.ts | 22 +++++++++++++++ src/sections/web3-connect/wallets/index.ts | 10 +++++++ src/utils/metamask.ts | 11 +++++++- 6 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/assets/icons/NightlyLogo.svg create mode 100644 src/sections/web3-connect/wallets/Nightly.ts create mode 100644 src/sections/web3-connect/wallets/NightlyEvm.ts diff --git a/src/assets/icons/NightlyLogo.svg b/src/assets/icons/NightlyLogo.svg new file mode 100644 index 000000000..7d665a3ae --- /dev/null +++ b/src/assets/icons/NightlyLogo.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/sections/web3-connect/constants/providers.ts b/src/sections/web3-connect/constants/providers.ts index a670cd800..1dc896fbe 100644 --- a/src/sections/web3-connect/constants/providers.ts +++ b/src/sections/web3-connect/constants/providers.ts @@ -9,6 +9,8 @@ export enum WalletProviderType { TrustWallet = "trustwallet", BraveWallet = "bravewallet", CoinbaseWallet = "coinbasewallet", + Nightly = "nightly", + NightlyEvm = "nightly-evm", Phantom = "phantom", Enkrypt = "enkrypt", MantaWallet = "manta-wallet-js", @@ -32,6 +34,7 @@ export const EVM_PROVIDERS: WalletProviderType[] = [ WalletProviderType.MetaMask, WalletProviderType.TalismanEvm, WalletProviderType.SubwalletEvm, + WalletProviderType.NightlyEvm, //WalletProviderType.TrustWallet, WalletProviderType.CoinbaseWallet, WalletProviderType.BraveWallet, @@ -45,6 +48,7 @@ export const SUBSTRATE_PROVIDERS: WalletProviderType[] = [ WalletProviderType.Enkrypt, WalletProviderType.PolkadotJS, WalletProviderType.NovaWallet, + WalletProviderType.Nightly, WalletProviderType.MantaWallet, WalletProviderType.FearlessWallet, WalletProviderType.Polkagate, diff --git a/src/sections/web3-connect/wallets/Nightly.ts b/src/sections/web3-connect/wallets/Nightly.ts new file mode 100644 index 000000000..5c78e6311 --- /dev/null +++ b/src/sections/web3-connect/wallets/Nightly.ts @@ -0,0 +1,27 @@ +import { InjectedWindow } from "@polkadot/extension-inject/types" +import { BaseDotsamaWallet } from "@talismn/connect-wallets" +import NightlyLogo from "assets/icons/NightlyLogo.svg" +import { WalletProviderType } from "sections/web3-connect/Web3Connect.utils" + +export class Nightly extends BaseDotsamaWallet { + extensionName = WalletProviderType.Nightly + title = "Nightly" + installUrl = "https://nightly.app/download" + logo = { + src: NightlyLogo, + alt: "Nightly Logo", + } + + get installed() { + const injectedWindow = window as Window & InjectedWindow + const injectedExtension = injectedWindow?.injectedWeb3?.Nightly + + return !!injectedExtension + } + + get rawExtension() { + const injectedWindow = window as Window & InjectedWindow + const injectedExtension = injectedWindow?.injectedWeb3?.Nightly + return injectedExtension + } +} diff --git a/src/sections/web3-connect/wallets/NightlyEvm.ts b/src/sections/web3-connect/wallets/NightlyEvm.ts new file mode 100644 index 000000000..33f2a4bff --- /dev/null +++ b/src/sections/web3-connect/wallets/NightlyEvm.ts @@ -0,0 +1,22 @@ +import NightlyLogo from "assets/icons/NightlyLogo.svg" +import { WalletProviderType } from "sections/web3-connect/constants/providers" +import { isNightly } from "utils/metamask" +import { MetaMask } from "./MetaMask" + +export class NightlyEvm extends MetaMask { + extensionName = WalletProviderType.NightlyEvm + title = "Nightly" + installUrl = "https://nightly.app/download" + logo = { + src: NightlyLogo, + alt: "Nightly Logo", + } + + get installed() { + return isNightly(this._provider) + } + + get rawExtension() { + return this._provider + } +} diff --git a/src/sections/web3-connect/wallets/index.ts b/src/sections/web3-connect/wallets/index.ts index 7e41af14c..95783b2f7 100644 --- a/src/sections/web3-connect/wallets/index.ts +++ b/src/sections/web3-connect/wallets/index.ts @@ -19,6 +19,8 @@ import { import { useWeb3ConnectStore } from "sections/web3-connect/store/useWeb3ConnectStore" import { WalletConnectEvm } from "sections/web3-connect/wallets/WalletConnectEvm" import { CoinbaseWallet } from "sections/web3-connect/wallets/CoinbaseWallet" +import { NightlyEvm } from "sections/web3-connect/wallets/NightlyEvm" +import { Nightly } from "sections/web3-connect/wallets/Nightly" export type WalletProvider = { type: WalletProviderType @@ -81,6 +83,11 @@ const coinbaseWallet: Wallet = new CoinbaseWallet({ ), }) +const nightly: Wallet = new Nightly() +const nightlyEvm: Wallet = new NightlyEvm({ + onAccountsChanged: onMetaMaskLikeAccountChange(WalletProviderType.NightlyEvm), +}) + const walletConnect: Wallet = new WalletConnect({ onModalClose: (session) => { if (!session) { @@ -111,6 +118,8 @@ export let SUPPORTED_WALLET_PROVIDERS: WalletProvider[] = [ subwalletEvm, subwallet, coinbaseWallet, + nightly, + nightlyEvm, //trustWallet, novaWallet, walletConnect, @@ -162,6 +171,7 @@ const eip6963ProvidersByRdns = new Map([ "com.coinbase.wallet", { Wallet: CoinbaseWallet, type: WalletProviderType.CoinbaseWallet }, ], + ["app.nightly", { Wallet: NightlyEvm, type: WalletProviderType.NightlyEvm }], ]) /** diff --git a/src/utils/metamask.ts b/src/utils/metamask.ts index 4b825acbd..866c8a431 100644 --- a/src/utils/metamask.ts +++ b/src/utils/metamask.ts @@ -14,6 +14,7 @@ const METAMASK_LIKE_CHECKS = [ "isBraveWallet", "isEnkrypt", "isCoinbaseWallet", + "isNightly", ] as const type MetaMaskLikeChecksValues = (typeof METAMASK_LIKE_CHECKS)[number] @@ -69,7 +70,6 @@ export function isMetaMaskLike( ): provider is Required { return ( !!provider && - typeof provider?.isMetaMask === "boolean" && METAMASK_LIKE_CHECKS.some( (key) => !!(provider as MetaMaskLikeProvider)?.[key], ) @@ -102,6 +102,10 @@ export function isCoinbaseWallet(provider: Maybe) { return isMetaMaskLike(provider) && !!provider?.isCoinbaseWallet } +export function isNightly(provider: Maybe) { + return isMetaMaskLike(provider) && !!provider?.isNightly +} + export function isEnkrypt(provider: Maybe) { return isMetaMaskLike(provider) && !!provider?.isEnkrypt } @@ -207,6 +211,11 @@ function normalizeChainSwitchError( ) { if (!provider) return let message: Record = {} + + if (typeof error === "string") { + return "CHAIN_NOT_FOUND" + } + try { message = typeof error?.message === "string" ? JSON.parse(error.message) : {} From aa71b482ccf2ffdd2d9512f7328f9b7cd9211f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Tue, 26 Nov 2024 17:09:33 +0100 Subject: [PATCH 06/17] Hide Nightly EVM --- src/sections/web3-connect/wallets/index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sections/web3-connect/wallets/index.ts b/src/sections/web3-connect/wallets/index.ts index 95783b2f7..a596b86a0 100644 --- a/src/sections/web3-connect/wallets/index.ts +++ b/src/sections/web3-connect/wallets/index.ts @@ -19,7 +19,7 @@ import { import { useWeb3ConnectStore } from "sections/web3-connect/store/useWeb3ConnectStore" import { WalletConnectEvm } from "sections/web3-connect/wallets/WalletConnectEvm" import { CoinbaseWallet } from "sections/web3-connect/wallets/CoinbaseWallet" -import { NightlyEvm } from "sections/web3-connect/wallets/NightlyEvm" +// import { NightlyEvm } from "sections/web3-connect/wallets/NightlyEvm" import { Nightly } from "sections/web3-connect/wallets/Nightly" export type WalletProvider = { @@ -84,9 +84,9 @@ const coinbaseWallet: Wallet = new CoinbaseWallet({ }) const nightly: Wallet = new Nightly() -const nightlyEvm: Wallet = new NightlyEvm({ +/* const nightlyEvm: Wallet = new NightlyEvm({ onAccountsChanged: onMetaMaskLikeAccountChange(WalletProviderType.NightlyEvm), -}) +}) */ const walletConnect: Wallet = new WalletConnect({ onModalClose: (session) => { @@ -119,7 +119,7 @@ export let SUPPORTED_WALLET_PROVIDERS: WalletProvider[] = [ subwallet, coinbaseWallet, nightly, - nightlyEvm, + // nightlyEvm, //trustWallet, novaWallet, walletConnect, @@ -171,7 +171,7 @@ const eip6963ProvidersByRdns = new Map([ "com.coinbase.wallet", { Wallet: CoinbaseWallet, type: WalletProviderType.CoinbaseWallet }, ], - ["app.nightly", { Wallet: NightlyEvm, type: WalletProviderType.NightlyEvm }], + /* ["app.nightly", { Wallet: NightlyEvm, type: WalletProviderType.NightlyEvm }], */ ]) /** From 5193c9c80290ea5e67f9701f97738623402e67fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Wed, 27 Nov 2024 18:04:37 +0100 Subject: [PATCH 07/17] enable nightly evm --- src/sections/web3-connect/wallets/MetaMask.ts | 6 ++++- src/sections/web3-connect/wallets/index.ts | 10 ++++---- src/utils/metamask.ts | 24 +++++++++++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/sections/web3-connect/wallets/MetaMask.ts b/src/sections/web3-connect/wallets/MetaMask.ts index f33e73fbf..45e9b8a04 100644 --- a/src/sections/web3-connect/wallets/MetaMask.ts +++ b/src/sections/web3-connect/wallets/MetaMask.ts @@ -74,8 +74,12 @@ export class MetaMask implements Wallet { } try { - if (!isMetaMask(this.rawExtension) && !isMetaMaskLike(this.rawExtension)) + if ( + !isMetaMask(this.rawExtension) && + !isMetaMaskLike(this.rawExtension) + ) { return + } const metamask = this.rawExtension diff --git a/src/sections/web3-connect/wallets/index.ts b/src/sections/web3-connect/wallets/index.ts index a596b86a0..95783b2f7 100644 --- a/src/sections/web3-connect/wallets/index.ts +++ b/src/sections/web3-connect/wallets/index.ts @@ -19,7 +19,7 @@ import { import { useWeb3ConnectStore } from "sections/web3-connect/store/useWeb3ConnectStore" import { WalletConnectEvm } from "sections/web3-connect/wallets/WalletConnectEvm" import { CoinbaseWallet } from "sections/web3-connect/wallets/CoinbaseWallet" -// import { NightlyEvm } from "sections/web3-connect/wallets/NightlyEvm" +import { NightlyEvm } from "sections/web3-connect/wallets/NightlyEvm" import { Nightly } from "sections/web3-connect/wallets/Nightly" export type WalletProvider = { @@ -84,9 +84,9 @@ const coinbaseWallet: Wallet = new CoinbaseWallet({ }) const nightly: Wallet = new Nightly() -/* const nightlyEvm: Wallet = new NightlyEvm({ +const nightlyEvm: Wallet = new NightlyEvm({ onAccountsChanged: onMetaMaskLikeAccountChange(WalletProviderType.NightlyEvm), -}) */ +}) const walletConnect: Wallet = new WalletConnect({ onModalClose: (session) => { @@ -119,7 +119,7 @@ export let SUPPORTED_WALLET_PROVIDERS: WalletProvider[] = [ subwallet, coinbaseWallet, nightly, - // nightlyEvm, + nightlyEvm, //trustWallet, novaWallet, walletConnect, @@ -171,7 +171,7 @@ const eip6963ProvidersByRdns = new Map([ "com.coinbase.wallet", { Wallet: CoinbaseWallet, type: WalletProviderType.CoinbaseWallet }, ], - /* ["app.nightly", { Wallet: NightlyEvm, type: WalletProviderType.NightlyEvm }], */ + ["app.nightly", { Wallet: NightlyEvm, type: WalletProviderType.NightlyEvm }], ]) /** diff --git a/src/utils/metamask.ts b/src/utils/metamask.ts index 866c8a431..f4c4b9b38 100644 --- a/src/utils/metamask.ts +++ b/src/utils/metamask.ts @@ -140,12 +140,28 @@ export async function requestNetworkSwitch( if (errorType === "CHAIN_NOT_FOUND") { try { - await provider - .request({ + await Promise.race([ + provider.request({ method: "wallet_addEthereumChain", params: [params], - }) - .then(options?.onSwitch) + }), + new Promise((resolve) => { + const id = setInterval(async () => { + const chainId = await provider.request({ method: "eth_chainId" }) + if (chainId === params.chainId) { + resolve(true) + clearInterval(id) + } else { + await provider.request({ + method: "wallet_switchEthereumChain", + params: [params], + }) + } + }, 5000) + }), + ]) + + options?.onSwitch?.() } catch (err) {} } else { throw new Error(error) From 7f8e72f007268aa382504a791fb5167843381e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Thu, 28 Nov 2024 12:05:07 +0100 Subject: [PATCH 08/17] adjust gas price --- src/sections/web3-connect/signer/EthereumSigner.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sections/web3-connect/signer/EthereumSigner.ts b/src/sections/web3-connect/signer/EthereumSigner.ts index 8c941e169..91c10d75d 100644 --- a/src/sections/web3-connect/signer/EthereumSigner.ts +++ b/src/sections/web3-connect/signer/EthereumSigner.ts @@ -57,8 +57,8 @@ export class EthereumSigner { this.signer.provider.getFeeData(), ]) - const onePrc = gasPrice.div(100) - const gasPricePlus = gasPrice.add(onePrc) + const twoPrc = gasPrice.div(100).mul(2) + const gasPricePlus = gasPrice.add(twoPrc) return { gas, From 47ad32d0d89e81e98ecef4e4451ff157045926d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Wed, 4 Dec 2024 13:51:35 +0100 Subject: [PATCH 09/17] bump apps --- package.json | 2 +- .../web3-connect/signer/EthereumSigner.ts | 7 +++- yarn.lock | 35 +++++++++++++++---- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 5a8a7e651..841332330 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@emotion/styled": "^11.10.4", "@ethersproject/address": "^5.7.0", "@ethersproject/providers": "^5.7.2", - "@galacticcouncil/apps": "^9.0.2", + "@galacticcouncil/apps": "9.1.0-pr157-d0957d6", "@galacticcouncil/math-lbp": "^1.0.0", "@galacticcouncil/math-liquidity-mining": "^1.0.0", "@galacticcouncil/math-omnipool": "^1.0.0", diff --git a/src/sections/web3-connect/signer/EthereumSigner.ts b/src/sections/web3-connect/signer/EthereumSigner.ts index 11a171ba8..1ded998e4 100644 --- a/src/sections/web3-connect/signer/EthereumSigner.ts +++ b/src/sections/web3-connect/signer/EthereumSigner.ts @@ -243,10 +243,15 @@ export class EthereumSigner { const { gas, maxFeePerGas, maxPriorityFeePerGas } = await this.getGasValues(tx) + console.log({ + maxPriorityFeePerGas: maxPriorityFeePerGas.toString(), + maxFeePerGas: maxFeePerGas.toString(), + }) + return await this.signer.sendTransaction({ maxPriorityFeePerGas, maxFeePerGas, - gasLimit: gas.mul(12).div(10), // add 20% + gasLimit: gas.mul(13).div(10), // add 30% ...tx, }) } else { diff --git a/yarn.lock b/yarn.lock index ad19b19b2..1810ed8f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2222,10 +2222,10 @@ resolved "https://registry.yarnpkg.com/@galacticcouncil/api-augment/-/api-augment-0.3.0.tgz#1377809cf125941410eea6ad97b4da0ca1eabb6c" integrity sha512-f14ftbivheBK8kSnqd8hSQlMPuVLY9571S5yx0LPU6K6m78F3pDPl09OEuJ+dSKHOw8hWzmFxiv0wRMYvDkeKA== -"@galacticcouncil/apps@^9.0.2": - version "9.0.2" - resolved "https://registry.yarnpkg.com/@galacticcouncil/apps/-/apps-9.0.2.tgz#11f91d6035b9ff663e9ddc11f5afea76244c07b5" - integrity sha512-1QqmIFQwrLXe8byWotLPjZ3SlFJHwaj9w4gId/RyToZ6TWtHzzDkxjXhf5pg38jzeirjyUr7VYVW0i5mE4HsnA== +"@galacticcouncil/apps@9.1.0-pr157-d0957d6": + version "9.1.0-pr157-d0957d6" + resolved "https://registry.yarnpkg.com/@galacticcouncil/apps/-/apps-9.1.0-pr157-d0957d6.tgz#d15e2728a80986426275192120bcfb69305e7244" + integrity sha512-iv4OQB4VPPFMcWBvY1atuYtO8qfyb55cR0WKtSp5KCNo77exihhhPy9eZWpu0yFV6SI19ML/08ynoCekYCSorA== dependencies: "@cfx-kit/wallet-avatar" "0.0.5" "@thi.ng/atom" "^5.1.3" @@ -11672,7 +11672,7 @@ prelude-ls@^1.2.1: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396" integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== -"prettier-fallback@npm:prettier@^3", prettier@^2.8.0, prettier@^3.1.1, prettier@^3.3.2: +"prettier-fallback@npm:prettier@^3": version "3.3.2" resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.2.tgz#03ff86dc7c835f2d2559ee76876a3914cec4a90a" integrity sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA== @@ -11684,6 +11684,11 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" +prettier@^2.8.0, prettier@^3.1.1, prettier@^3.3.2: + version "3.3.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.2.tgz#03ff86dc7c835f2d2559ee76876a3914cec4a90a" + integrity sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA== + pretty-format@^27.0.0, pretty-format@^27.0.2, pretty-format@^27.5.1: version "27.5.1" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e" @@ -12993,7 +12998,14 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1, strip-ansi@^7.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1, strip-ansi@^7.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -14012,7 +14024,16 @@ wordwrap@^1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@7.0.0, wrap-ansi@^6.2.0, wrap-ansi@^8.1.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + +wrap-ansi@7.0.0, wrap-ansi@^6.2.0, wrap-ansi@^8.1.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== From 1d02af36d252457546294900e6426d39768c90e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Wed, 4 Dec 2024 14:22:38 +0100 Subject: [PATCH 10/17] remove debug --- src/sections/web3-connect/signer/EthereumSigner.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/sections/web3-connect/signer/EthereumSigner.ts b/src/sections/web3-connect/signer/EthereumSigner.ts index 1ded998e4..08f918c1f 100644 --- a/src/sections/web3-connect/signer/EthereumSigner.ts +++ b/src/sections/web3-connect/signer/EthereumSigner.ts @@ -243,11 +243,6 @@ export class EthereumSigner { const { gas, maxFeePerGas, maxPriorityFeePerGas } = await this.getGasValues(tx) - console.log({ - maxPriorityFeePerGas: maxPriorityFeePerGas.toString(), - maxFeePerGas: maxFeePerGas.toString(), - }) - return await this.signer.sendTransaction({ maxPriorityFeePerGas, maxFeePerGas, From 2623aaeb5a4272aa45f06c9d419138fdef6faa8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Fri, 6 Dec 2024 14:39:02 +0100 Subject: [PATCH 11/17] enable trust wallet --- src/sections/web3-connect/constants/providers.ts | 2 +- src/sections/web3-connect/wallets/index.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/sections/web3-connect/constants/providers.ts b/src/sections/web3-connect/constants/providers.ts index 1dc896fbe..bf2010cdb 100644 --- a/src/sections/web3-connect/constants/providers.ts +++ b/src/sections/web3-connect/constants/providers.ts @@ -35,7 +35,7 @@ export const EVM_PROVIDERS: WalletProviderType[] = [ WalletProviderType.TalismanEvm, WalletProviderType.SubwalletEvm, WalletProviderType.NightlyEvm, - //WalletProviderType.TrustWallet, + WalletProviderType.TrustWallet, WalletProviderType.CoinbaseWallet, WalletProviderType.BraveWallet, WalletProviderType.Phantom, diff --git a/src/sections/web3-connect/wallets/index.ts b/src/sections/web3-connect/wallets/index.ts index 95783b2f7..7b96f3f2c 100644 --- a/src/sections/web3-connect/wallets/index.ts +++ b/src/sections/web3-connect/wallets/index.ts @@ -9,7 +9,7 @@ import { WalletConnect } from "./WalletConnect" import { H160, isEvmAddress } from "utils/evm" import { SubWalletEvm } from "./SubWalletEvm" import { SubWallet } from "./SubWallet" -// import { TrustWallet } from "./TrustWallet" +import { TrustWallet } from "./TrustWallet" import { BraveWallet } from "./BraveWallet" import { EIP6963AnnounceProviderEvent } from "sections/web3-connect/types" import { @@ -71,11 +71,11 @@ const metaMask: Wallet = new MetaMask({ onAccountsChanged: onMetaMaskLikeAccountChange(WalletProviderType.MetaMask), }) -/* const trustWallet: Wallet = new TrustWallet({ +const trustWallet: Wallet = new TrustWallet({ onAccountsChanged: onMetaMaskLikeAccountChange( WalletProviderType.TrustWallet, ), -}) */ +}) const coinbaseWallet: Wallet = new CoinbaseWallet({ onAccountsChanged: onMetaMaskLikeAccountChange( @@ -120,7 +120,7 @@ export let SUPPORTED_WALLET_PROVIDERS: WalletProvider[] = [ coinbaseWallet, nightly, nightlyEvm, - //trustWallet, + trustWallet, novaWallet, walletConnect, walletConnectEvm, @@ -155,10 +155,10 @@ function syncSupportedWalletProviders(wallet: Wallet) { const eip6963ProvidersByRdns = new Map([ ["io.metamask", { Wallet: MetaMask, type: WalletProviderType.MetaMask }], - // [ - // "com.trustwallet.app", - // { Wallet: TrustWallet, type: WalletProviderType.TrustWallet }, - // ], + [ + "com.trustwallet.app", + { Wallet: TrustWallet, type: WalletProviderType.TrustWallet }, + ], [ "xyz.talisman", { Wallet: TalismanEvm, type: WalletProviderType.TalismanEvm }, From 18973836a5861fa568798d1f6dd27e371bb6c515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Fri, 6 Dec 2024 14:45:35 +0100 Subject: [PATCH 12/17] fix lint --- src/sections/web3-connect/wallets/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sections/web3-connect/wallets/index.ts b/src/sections/web3-connect/wallets/index.ts index 7b96f3f2c..ad45f53bb 100644 --- a/src/sections/web3-connect/wallets/index.ts +++ b/src/sections/web3-connect/wallets/index.ts @@ -156,7 +156,7 @@ function syncSupportedWalletProviders(wallet: Wallet) { const eip6963ProvidersByRdns = new Map([ ["io.metamask", { Wallet: MetaMask, type: WalletProviderType.MetaMask }], [ - "com.trustwallet.app", + "com.trustwallet.app", { Wallet: TrustWallet, type: WalletProviderType.TrustWallet }, ], [ From 97cf00c277d4a73ffca3bdb7cc4be718a0f263ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Mon, 9 Dec 2024 11:45:09 +0100 Subject: [PATCH 13/17] Added Rabby Wallet --- src/assets/icons/RabbyWalletLogo.svg | 47 +++++++++++++++++++ .../web3-connect/constants/providers.ts | 2 + .../web3-connect/wallets/RabbyWallet.ts | 23 +++++++++ src/sections/web3-connect/wallets/index.ts | 9 ++++ src/utils/metamask.ts | 5 ++ 5 files changed, 86 insertions(+) create mode 100644 src/assets/icons/RabbyWalletLogo.svg create mode 100644 src/sections/web3-connect/wallets/RabbyWallet.ts diff --git a/src/assets/icons/RabbyWalletLogo.svg b/src/assets/icons/RabbyWalletLogo.svg new file mode 100644 index 000000000..9d4e1dc1e --- /dev/null +++ b/src/assets/icons/RabbyWalletLogo.svg @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/sections/web3-connect/constants/providers.ts b/src/sections/web3-connect/constants/providers.ts index bf2010cdb..d1b900300 100644 --- a/src/sections/web3-connect/constants/providers.ts +++ b/src/sections/web3-connect/constants/providers.ts @@ -9,6 +9,7 @@ export enum WalletProviderType { TrustWallet = "trustwallet", BraveWallet = "bravewallet", CoinbaseWallet = "coinbasewallet", + RabbyWallet = "rabbywallet", Nightly = "nightly", NightlyEvm = "nightly-evm", Phantom = "phantom", @@ -35,6 +36,7 @@ export const EVM_PROVIDERS: WalletProviderType[] = [ WalletProviderType.TalismanEvm, WalletProviderType.SubwalletEvm, WalletProviderType.NightlyEvm, + WalletProviderType.RabbyWallet, WalletProviderType.TrustWallet, WalletProviderType.CoinbaseWallet, WalletProviderType.BraveWallet, diff --git a/src/sections/web3-connect/wallets/RabbyWallet.ts b/src/sections/web3-connect/wallets/RabbyWallet.ts new file mode 100644 index 000000000..4cf526d09 --- /dev/null +++ b/src/sections/web3-connect/wallets/RabbyWallet.ts @@ -0,0 +1,23 @@ +import { WalletProviderType } from "sections/web3-connect/constants/providers" +import { isRabbyWallet } from "utils/metamask" +import { MetaMask } from "./MetaMask" +import RabbyWalletLogo from "assets/icons/RabbyWalletLogo.svg" + +export class RabbyWallet extends MetaMask { + extensionName = WalletProviderType.RabbyWallet + title = "Rabby Wallet" + installUrl = "https://rabby.io" + logo = { + src: RabbyWalletLogo, + alt: "Rabby Wallet Logo", + } + + get installed() { + const provider = this._provider || window.ethereum + return isRabbyWallet(provider) + } + + get rawExtension() { + return this._provider || window.ethereum + } +} diff --git a/src/sections/web3-connect/wallets/index.ts b/src/sections/web3-connect/wallets/index.ts index ad45f53bb..c11f0ac12 100644 --- a/src/sections/web3-connect/wallets/index.ts +++ b/src/sections/web3-connect/wallets/index.ts @@ -21,6 +21,7 @@ import { WalletConnectEvm } from "sections/web3-connect/wallets/WalletConnectEvm import { CoinbaseWallet } from "sections/web3-connect/wallets/CoinbaseWallet" import { NightlyEvm } from "sections/web3-connect/wallets/NightlyEvm" import { Nightly } from "sections/web3-connect/wallets/Nightly" +import { RabbyWallet } from "sections/web3-connect/wallets/RabbyWallet" export type WalletProvider = { type: WalletProviderType @@ -88,6 +89,12 @@ const nightlyEvm: Wallet = new NightlyEvm({ onAccountsChanged: onMetaMaskLikeAccountChange(WalletProviderType.NightlyEvm), }) +const rabbyWallet: Wallet = new RabbyWallet({ + onAccountsChanged: onMetaMaskLikeAccountChange( + WalletProviderType.RabbyWallet, + ), +}) + const walletConnect: Wallet = new WalletConnect({ onModalClose: (session) => { if (!session) { @@ -120,6 +127,7 @@ export let SUPPORTED_WALLET_PROVIDERS: WalletProvider[] = [ coinbaseWallet, nightly, nightlyEvm, + rabbyWallet, trustWallet, novaWallet, walletConnect, @@ -172,6 +180,7 @@ const eip6963ProvidersByRdns = new Map([ { Wallet: CoinbaseWallet, type: WalletProviderType.CoinbaseWallet }, ], ["app.nightly", { Wallet: NightlyEvm, type: WalletProviderType.NightlyEvm }], + ["io.rabby", { Wallet: RabbyWallet, type: WalletProviderType.RabbyWallet }], ]) /** diff --git a/src/utils/metamask.ts b/src/utils/metamask.ts index f4c4b9b38..22b28aef8 100644 --- a/src/utils/metamask.ts +++ b/src/utils/metamask.ts @@ -15,6 +15,7 @@ const METAMASK_LIKE_CHECKS = [ "isEnkrypt", "isCoinbaseWallet", "isNightly", + "isRabby", ] as const type MetaMaskLikeChecksValues = (typeof METAMASK_LIKE_CHECKS)[number] @@ -106,6 +107,10 @@ export function isNightly(provider: Maybe) { return isMetaMaskLike(provider) && !!provider?.isNightly } +export function isRabbyWallet(provider: Maybe) { + return isMetaMaskLike(provider) && !!provider?.isRabby +} + export function isEnkrypt(provider: Maybe) { return isMetaMaskLike(provider) && !!provider?.isEnkrypt } From b1fd41b37eff223ef5a70c8420d0aca5af652938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Mon, 9 Dec 2024 16:16:31 +0100 Subject: [PATCH 14/17] update pkgs --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d9cac6336..ec34dc7b8 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@emotion/styled": "^11.10.4", "@ethersproject/address": "^5.7.0", "@ethersproject/providers": "^5.7.2", - "@galacticcouncil/apps": "^9.1.0", + "@galacticcouncil/apps": "9.2.0-pr161-b2a6da5", "@galacticcouncil/math-lbp": "^1.0.0", "@galacticcouncil/math-liquidity-mining": "^1.0.0", "@galacticcouncil/math-omnipool": "^1.0.0", diff --git a/yarn.lock b/yarn.lock index 30102728f..d78ed69ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2222,10 +2222,10 @@ resolved "https://registry.yarnpkg.com/@galacticcouncil/api-augment/-/api-augment-0.3.0.tgz#1377809cf125941410eea6ad97b4da0ca1eabb6c" integrity sha512-f14ftbivheBK8kSnqd8hSQlMPuVLY9571S5yx0LPU6K6m78F3pDPl09OEuJ+dSKHOw8hWzmFxiv0wRMYvDkeKA== -"@galacticcouncil/apps@^9.1.0": - version "9.1.0" - resolved "https://registry.yarnpkg.com/@galacticcouncil/apps/-/apps-9.1.0.tgz#4c2d18242053318e7131038619c44ffbf744dfb9" - integrity sha512-lAb3VYNy1oLUIgOZx7MkwpF0mgz8LQbXSTXHW8ESw46I8tALo0bqonb4X17y4ZfWgv88OcoOzdORwJboPWmpUg== +"@galacticcouncil/apps@9.2.0-pr161-b2a6da5": + version "9.2.0-pr161-b2a6da5" + resolved "https://registry.yarnpkg.com/@galacticcouncil/apps/-/apps-9.2.0-pr161-b2a6da5.tgz#e3b4753018a12827ccd9017f28251e948d8d79e7" + integrity sha512-qd/15moBJzwvEtW43t6ttUtzzSN9NsKsJVyt2UHwhdsa2TR7UmxcGH4ubQ1053A3zgAZtaHYFx51vrXS6QUXag== dependencies: "@cfx-kit/wallet-avatar" "0.0.5" "@thi.ng/atom" "^5.1.3" From c089050f07634031ab92282302770662b246ca51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Tue, 10 Dec 2024 11:53:30 +0100 Subject: [PATCH 15/17] add chainId prop to native evm tx --- src/sections/web3-connect/signer/EthereumSigner.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sections/web3-connect/signer/EthereumSigner.ts b/src/sections/web3-connect/signer/EthereumSigner.ts index 08f918c1f..af7447efc 100644 --- a/src/sections/web3-connect/signer/EthereumSigner.ts +++ b/src/sections/web3-connect/signer/EthereumSigner.ts @@ -16,6 +16,7 @@ import { requestNetworkSwitch, } from "utils/metamask" import { sleep } from "utils/helpers" +import { EvmChain } from "@galacticcouncil/xcm-core" type PermitMessage = { from: string @@ -235,7 +236,8 @@ export class EthereumSigner { transaction: TransactionRequest & { chain?: string }, ) => { const { chain, ...tx } = transaction - const from = chain && chainsMap.get(chain) ? chain : "hydration" + const from = chain && chainsMap.get(chain)?.isEvmChain ? chain : "hydration" + const chainCfg = chainsMap.get(from) as EvmChain await this.requestNetworkSwitch(from) @@ -244,9 +246,11 @@ export class EthereumSigner { await this.getGasValues(tx) return await this.signer.sendTransaction({ + chainId: chainCfg.evmChain.id, + nonce: tx?.nonce ?? (await this.signer.getTransactionCount()), maxPriorityFeePerGas, maxFeePerGas, - gasLimit: gas.mul(13).div(10), // add 30% + gasLimit: gas.mul(12).div(10), // add 20% ...tx, }) } else { From e4762a010e89b78061f981a7b9453a541715e467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Tue, 10 Dec 2024 12:59:23 +0100 Subject: [PATCH 16/17] bump fee per gas --- .../web3-connect/signer/EthereumSigner.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/sections/web3-connect/signer/EthereumSigner.ts b/src/sections/web3-connect/signer/EthereumSigner.ts index af7447efc..0605a9707 100644 --- a/src/sections/web3-connect/signer/EthereumSigner.ts +++ b/src/sections/web3-connect/signer/EthereumSigner.ts @@ -55,11 +55,10 @@ export class EthereumSigner { const [gas, gasPrice] = await Promise.all([ this.signer.provider.estimateGas(tx), this.signer.provider.getGasPrice(), - this.signer.provider.getFeeData(), ]) - const twoPrc = gasPrice.div(100).mul(2) - const gasPricePlus = gasPrice.add(twoPrc) + const fivePrc = gasPrice.div(100).mul(5) + const gasPricePlus = gasPrice.add(fivePrc) return { gas, @@ -245,12 +244,16 @@ export class EthereumSigner { const { gas, maxFeePerGas, maxPriorityFeePerGas } = await this.getGasValues(tx) + const chainId = chainCfg.evmChain.id + const nonce = await this.signer.getTransactionCount() + return await this.signer.sendTransaction({ - chainId: chainCfg.evmChain.id, - nonce: tx?.nonce ?? (await this.signer.getTransactionCount()), + chainId, + nonce, + value: 0, maxPriorityFeePerGas, maxFeePerGas, - gasLimit: gas.mul(12).div(10), // add 20% + gasLimit: gas.mul(13).div(10), // add 30% ...tx, }) } else { From f2118c4ea2ea0c24596cdf47fd4d20e9f3dbf479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Von=C3=A1=C5=A1ek?= Date: Tue, 10 Dec 2024 14:05:05 +0100 Subject: [PATCH 17/17] change evm wait to 1 confirmation --- src/sections/transaction/ReviewTransaction.utils.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sections/transaction/ReviewTransaction.utils.tsx b/src/sections/transaction/ReviewTransaction.utils.tsx index 8ad8f0a4f..c20a8a220 100644 --- a/src/sections/transaction/ReviewTransaction.utils.tsx +++ b/src/sections/transaction/ReviewTransaction.utils.tsx @@ -214,7 +214,7 @@ export const useSendEvmTransactionMutation = ( setTxState("Broadcast") setTxHash(evmTx?.hash ?? "") setTxData(evmTx?.data) - const receipt = await evmTx.wait() + const receipt = await evmTx.wait(1) setTxState("InBlock") return resolve(evmTxReceiptToSubmittableResult(receipt))