startTimer()

The startTimer() method is used to set a timer for 15 minutes in the payment window as shown here. The customer has 15 minutes to make the payment from their wallet to the merchant's wallet address before the request expires:

startTimer = () =>{
if(this.state.tflag == true)
{
this.intervalHandle = setInterval(this.tick,1000);
this.intervalBalance = setInterval(this.bCheck,10000);

let time = this.state.minutes;
this.secondsRemaining = time * 60;
this.setState({
tflag: false
});
}
}

Let's understand the various components of the startTimer method: 

  • tflag is set to false if the app has an ongoing 15-minute window. This prevents React from creating multiple timer intervals when a state variable is updated.
  • If tflag is set to true, meaning no interval exists, the method sets up two intervals. The first interval calls the method tick at an interval of 15 minutes.
  • The tick() method is the brains behind our timer. The second interval calls the bCheck() method at an interval of 10 seconds.
  • The bCheck() method checks the balance of the merchant's wallet address within the 15-minute window.
  • If the address receives an amount equal to or greater than the amount owed by the customer, it stops the timer and notifies the customer of the successful payment.

This method also initializes the secondsRemaining parameter to 600 seconds or 15 minutes. This will be used by the tick() method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.199.210