Skip to content

Commit e375071

Browse files
authored
add cumulative to fee option permissions + reduce api call if not needed (#530)
1 parent 23d5394 commit e375071

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

packages/connect/src/connectors/wagmiConnectors/sequenceV3Connector.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,15 @@ export class SequenceV3Provider implements EIP1193Provider {
307307
param: 'value',
308308
type: 'uint256',
309309
condition: 'LESS_THAN_OR_EQUAL',
310-
value: token.decimals === 18 ? parseEther('0.1') : parseUnits('50', token.decimals || 6)
310+
value: token.decimals === 18 ? parseEther('0.1') : parseUnits('50', token.decimals || 6),
311+
cumulative: true
311312
},
312313
{
313314
param: 'to',
314315
type: 'address',
315316
condition: 'EQUAL',
316-
value: feeTokens.paymentAddress as Address
317+
value: feeTokens.paymentAddress as Address,
318+
cumulative: false
317319
}
318320
]
319321
})
@@ -456,11 +458,13 @@ export class SequenceV3Provider implements EIP1193Provider {
456458
const hasPermission = await this.client.hasPermission(this.currentChainId, transactions)
457459

458460
if (hasPermission) {
459-
const feeOptions = await this.client.getFeeOptions(this.currentChainId, transactions)
460-
let selectedFeeOption: Relayer.FeeOption | undefined
461+
// @note feeConfirmationHandler will only be defined if the useFeeOptions hook is used anywhere in the app
462+
// if it is not used, we do not query fee options at all
463+
if (this.feeConfirmationHandler) {
464+
const feeOptions = await this.client.getFeeOptions(this.currentChainId, transactions)
465+
let selectedFeeOption: Relayer.FeeOption | undefined
461466

462-
if (feeOptions && feeOptions.length > 0) {
463-
if (this.feeConfirmationHandler) {
467+
if (feeOptions && feeOptions.length > 0) {
464468
const id = uuidv4()
465469
const confirmation = await this.feeConfirmationHandler.confirmFeeOption(id, feeOptions, [tx], this.currentChainId)
466470

@@ -479,9 +483,13 @@ export class SequenceV3Provider implements EIP1193Provider {
479483
}
480484
selectedFeeOption = confirmation.feeOption
481485
}
486+
// @note if dApp has permission and there is a confirmation handler
487+
// if there is no selectedFeeOption, dapp should sponsor the transaction or network used should be testnet
488+
return this.client.sendTransaction(this.currentChainId, transactions, selectedFeeOption)
489+
} else {
490+
// @note if dApp has permission but there is no confirmation handler, in this case dapp should sponsor the transaction
491+
return this.client.sendTransaction(this.currentChainId, transactions)
482492
}
483-
// @note no fee option selected, in this case dapp should sponsor the transaction
484-
return this.client.sendTransaction(this.currentChainId, transactions, selectedFeeOption)
485493
} else {
486494
return new Promise((resolve, reject) => {
487495
const unsubscribe = this.client.on('walletActionResponse', (data: any) => {

0 commit comments

Comments
 (0)