From 75928c5293a5b61332a585d310f3e6889e421a3f Mon Sep 17 00:00:00 2001 From: Bojan Angjelkoski Date: Fri, 19 Jul 2024 14:48:08 +0200 Subject: [PATCH] chore: wallet connect individual wallet support --- .../src/broadcaster/MsgBroadcaster.ts | 39 +++++++++++++++++-- packages/wallet-ts/src/broadcaster/types.ts | 1 + .../strategies/WalletConnect.ts | 23 +++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/packages/wallet-ts/src/broadcaster/MsgBroadcaster.ts b/packages/wallet-ts/src/broadcaster/MsgBroadcaster.ts index b474dce0c..787b7b5ec 100644 --- a/packages/wallet-ts/src/broadcaster/MsgBroadcaster.ts +++ b/packages/wallet-ts/src/broadcaster/MsgBroadcaster.ts @@ -93,6 +93,8 @@ export class MsgBroadcaster { public simulateTx: boolean = true + public txTimeoutOnFeeDelegation: boolean = false + public ethereumChainId?: EthereumChainId public gasBufferCoefficient: number = 1.2 @@ -101,8 +103,13 @@ export class MsgBroadcaster { const networkInfo = getNetworkInfo(options.network) this.options = options - this.simulateTx = options.simulateTx || true + this.simulateTx = + options.simulateTx !== undefined ? options.simulateTx : true this.txTimeout = options.txTimeout || DEFAULT_BLOCK_TIMEOUT_HEIGHT + this.txTimeoutOnFeeDelegation = + options.txTimeoutOnFeeDelegation !== undefined + ? options.txTimeoutOnFeeDelegation + : true this.gasBufferCoefficient = options.gasBufferCoefficient || 1.2 this.chainId = options.chainId || networkInfo.chainId this.ethereumChainId = @@ -113,6 +120,8 @@ export class MsgBroadcaster { setOptions(options: Partial) { this.simulateTx = options.simulateTx || this.simulateTx this.txTimeout = options.txTimeout || this.txTimeout + this.txTimeoutOnFeeDelegation = + options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation } /** @@ -453,7 +462,14 @@ export class MsgBroadcaster { private async broadcastWeb3WithFeeDelegation( tx: MsgBroadcasterTxOptionsWithAddresses, ): Promise { - const { options, simulateTx, ethereumChainId, endpoints } = this + const { + options, + txTimeout, + endpoints, + simulateTx, + ethereumChainId, + txTimeoutOnFeeDelegation, + } = this const { walletStrategy } = options const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs] const web3Msgs = msgs.map((msg) => msg.toWeb3()) @@ -466,7 +482,21 @@ export class MsgBroadcaster { endpoints.web3gw || endpoints.indexer, ) + let timeoutHeight = undefined + + if (txTimeoutOnFeeDelegation) { + const latestBlock = await new ChainGrpcTendermintApi( + endpoints.grpc, + ).fetchLatestBlock() + const latestHeight = latestBlock!.header!.height + + timeoutHeight = new BigNumberInBase(latestHeight) + .plus(txTimeout) + .toNumber() + } + const txResponse = await transactionApi.prepareTxRequest({ + timeoutHeight, memo: tx.memo, message: web3Msgs, address: tx.ethereumAddress, @@ -775,7 +805,8 @@ export class MsgBroadcaster { private async broadcastCosmosWithFeeDelegation( tx: MsgBroadcasterTxOptionsWithAddresses, ) { - const { options, chainId, endpoints } = this + const { options, chainId, txTimeout, endpoints, txTimeoutOnFeeDelegation } = + this const { walletStrategy } = options const msgs = Array.isArray(tx.msgs) ? tx.msgs : [tx.msgs] @@ -819,7 +850,7 @@ export class MsgBroadcaster { ).fetchLatestBlock() const latestHeight = latestBlock!.header!.height const timeoutHeight = new BigNumberInBase(latestHeight).plus( - DEFAULT_BLOCK_TIMEOUT_HEIGHT, + txTimeoutOnFeeDelegation ? txTimeout : DEFAULT_BLOCK_TIMEOUT_HEIGHT, ) const pubKey = await walletStrategy.getPubKey() diff --git a/packages/wallet-ts/src/broadcaster/types.ts b/packages/wallet-ts/src/broadcaster/types.ts index 86f347342..430ba69f7 100644 --- a/packages/wallet-ts/src/broadcaster/types.ts +++ b/packages/wallet-ts/src/broadcaster/types.ts @@ -42,6 +42,7 @@ export interface MsgBroadcasterOptions { ethereumChainId?: EthereumChainId feePayerPubKey?: string simulateTx?: boolean + txTimeoutOnFeeDelegation?: boolean txTimeout?: number // blocks to wait for tx to be included in a block walletStrategy: WalletStrategy gasBufferCoefficient?: number diff --git a/packages/wallet-ts/src/strategies/wallet-strategy/strategies/WalletConnect.ts b/packages/wallet-ts/src/strategies/wallet-strategy/strategies/WalletConnect.ts index e441b9ddf..d1ea85780 100644 --- a/packages/wallet-ts/src/strategies/wallet-strategy/strategies/WalletConnect.ts +++ b/packages/wallet-ts/src/strategies/wallet-strategy/strategies/WalletConnect.ts @@ -22,6 +22,11 @@ import Provider, { EthereumProviderOptions, } from '@walletconnect/ethereum-provider' +const WalletConnectIds = { + FireBlocks: + '5864e2ced7c293ed18ac35e0db085c09ed567d67346ccb6f58a0327a75137489', +} + interface WalletConnectArgs extends EthereumWalletStrategyArgs { metadata?: WalletConnectMetadata } @@ -320,6 +325,24 @@ export default class WalletConnect .metadata as unknown as EthereumProviderOptions['metadata'], showQrModal: true, optionalChains: [1, 5, 42, 11155111], + qrModalOptions: { + explorerRecommendedWalletIds: [WalletConnectIds.FireBlocks], + explorerExcludedWalletIds: 'ALL', + mobileWallets: [], + walletImages: { + [WalletConnectIds.FireBlocks]: '/wallet-connect/fireblocks.webp', + }, + desktopWallets: [ + { + id: WalletConnectIds.FireBlocks, + name: 'Fireblocks', + links: { + native: 'fireblocks-wc://', + universal: 'https://console.fireblocks.io/v2/', + }, + }, + ], + }, }) return this.provider