Skip to content

Commit

Permalink
chore: wallet connect individual wallet support
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Jul 19, 2024
1 parent d15d7a3 commit 75928c5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
39 changes: 35 additions & 4 deletions packages/wallet-ts/src/broadcaster/MsgBroadcaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export class MsgBroadcaster {

public simulateTx: boolean = true

public txTimeoutOnFeeDelegation: boolean = false

public ethereumChainId?: EthereumChainId

public gasBufferCoefficient: number = 1.2
Expand All @@ -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 =
Expand All @@ -113,6 +120,8 @@ export class MsgBroadcaster {
setOptions(options: Partial<MsgBroadcasterOptions>) {
this.simulateTx = options.simulateTx || this.simulateTx
this.txTimeout = options.txTimeout || this.txTimeout
this.txTimeoutOnFeeDelegation =
options.txTimeoutOnFeeDelegation || this.txTimeoutOnFeeDelegation
}

/**
Expand Down Expand Up @@ -453,7 +462,14 @@ export class MsgBroadcaster {
private async broadcastWeb3WithFeeDelegation(
tx: MsgBroadcasterTxOptionsWithAddresses,
): Promise<TxResponse> {
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())
Expand All @@ -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,
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-ts/src/broadcaster/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import Provider, {
EthereumProviderOptions,
} from '@walletconnect/ethereum-provider'

const WalletConnectIds = {
FireBlocks:
'5864e2ced7c293ed18ac35e0db085c09ed567d67346ccb6f58a0327a75137489',
}

interface WalletConnectArgs extends EthereumWalletStrategyArgs {
metadata?: WalletConnectMetadata
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 75928c5

Please sign in to comment.