From fdd25a65118170c07c4fff6cdfdb69dc94eb2585 Mon Sep 17 00:00:00 2001 From: mhchia Date: Sat, 16 Sep 2023 16:13:45 +0800 Subject: [PATCH] approve only when allowance is not enough --- src/contract-wrapper.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/contract-wrapper.ts b/src/contract-wrapper.ts index 1caa4240..aee05ca9 100644 --- a/src/contract-wrapper.ts +++ b/src/contract-wrapper.ts @@ -180,8 +180,11 @@ export class RLNContract { erc20ABI, this.getContractRunner(), ) - const txApprove = await tokenContract.approve(rlnContractAddress, amount) - await txApprove.wait() + const allowance = await tokenContract.allowance(await this.getSignerAddress(), rlnContractAddress) + if (allowance < amount) { + const txApprove = await tokenContract.approve(rlnContractAddress, amount) + await txApprove.wait() + } const txRegister = await this.rlnContract.register(identityCommitment, amount) const receipt = await txRegister.wait() return receipt