Open Luphia opened 2 years ago
class ConnectorProvider extends React.Component { const allowance = {}; const balance = {}; const allowanceMonitor = {}; const balanceMonitor = {}; const allowanceListener = {}; const balanceListener = {}; const monitorInterval = 1000; constructor(props) { super(props); } watchAllowance(erc20, switchOn) { const currentMonitor = this.allowanceMonitor[erc20]; if(switchOn || (erc20 && switchOn == undefined && currentMonitor == undefined)) { // monitor switch on allowanceMonitor[erc20] = setInterval(() => { ... if(result != this.allowance[erc20]) { this.allowance[erc20] = result; // notice allowanceListener } }, this.monitorInterval); } else { // monitor switch off clearInterval(statusMonitor.approve); delete statusMonitor.approve; } } addAllowanceListener(erc20) { ... return listenerID; } removeAllowanceListener(erc20, listenerID) { ... } watchBalance(asset, switchOn) { const currentMonitor = this.balanceMonitor[asset]; if(switchOn || (asset && switchOn == undefined && currentMonitor == undefined)) { // monitor switch on this.balanceMonitor[asset] = setInterval(() => { ... if(result != this.balance[asset]) { this.balance[asset] = result; // notice balanceListener } }, this.monitorInterval); } else { // monitor switch off clearInterval(currentMonitor); delete this.balanceMonitor[asset]; } } addBalanceListener(asset) { ... return listenerID; } removeBalanceListener(asset, listenerID) { ... } render() { ... } }
Main Problem
Sub Problem
Requirement
Allowance Monitor and Balance Monitor
ConnectorProvider
userEffect