Skip to content

Commit

Permalink
approve only when allowance is not enough
Browse files Browse the repository at this point in the history
  • Loading branch information
mhchia committed Sep 16, 2023
1 parent c7b1b04 commit fdd25a6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/contract-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fdd25a6

Please sign in to comment.