MCPcopy Create free account
hub / github.com/PolymathNetwork/polymath-core / approvePoly

Function approvePoly

CLI/commands/ST20Generator.js:188–206  ·  view source on GitHub ↗
(spender, fee)

Source from the content-addressed store, hash-verified

186}
187
188async function approvePoly(spender, fee) {
189 polyBalance = await polyToken.methods.balanceOf(Issuer.address).call();
190 let requiredAmount = web3.utils.toWei(fee.toString(), "ether");
191 if (parseInt(polyBalance) >= parseInt(requiredAmount)) {
192 let allowance = await polyToken.methods.allowance(spender, Issuer.address).call();
193 if (allowance == web3.utils.toWei(fee.toString(), "ether")) {
194 return true;
195 } else {
196 let approveAction = polyToken.methods.approve(spender, web3.utils.toWei(fee.toString(), "ether"));
197 await common.sendTransaction(approveAction);
198 }
199 } else {
200 let requiredBalance = parseInt(requiredAmount) - parseInt(polyBalance);
201 console.log(chalk.red(`\n*****************************************************************************************************************************************`));
202 console.log(chalk.red(`Not enough balance to Pay the Fee, Require ${(new BigNumber(requiredBalance).dividedBy(new BigNumber(10).pow(18))).toNumber()} POLY but have ${(new BigNumber(polyBalance).dividedBy(new BigNumber(10).pow(18))).toNumber()} POLY. Access POLY faucet to get the POLY to complete this txn`));
203 console.log(chalk.red(`******************************************************************************************************************************************\n`));
204 process.exit(0);
205 }
206}
207
208module.exports = {
209 executeApp: async function (ticker, transferOwnership, name, details, divisible) {

Callers 2

step_ticker_registrationFunction · 0.85
step_token_deployFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected