diff --git a/app/assets/v2/css/grants/detail.css b/app/assets/v2/css/grants/detail.css index 669f3752242..f1374a20ba0 100644 --- a/app/assets/v2/css/grants/detail.css +++ b/app/assets/v2/css/grants/detail.css @@ -128,6 +128,10 @@ textarea.editable { animation: rotation2 0.1s linear; } +.update-milestone { + background-color: white; +} + @keyframes rotation { from { transform: rotate(0deg); @@ -161,4 +165,4 @@ textarea.editable { display: flex; justify-content: center; } -} \ No newline at end of file +} diff --git a/app/assets/v2/js/grants/cancel_subscription.js b/app/assets/v2/js/grants/cancel_subscription.js index 6eec32d09b9..a6117d91691 100644 --- a/app/assets/v2/js/grants/cancel_subscription.js +++ b/app/assets/v2/js/grants/cancel_subscription.js @@ -11,20 +11,73 @@ window.onload = function() { data[this.name] = this.value; }); - // currently practically cancelled, but need to delete subscription from miner so it isn't checked every 15 seconds. + // need to delete subscription from miner so it isn't checked every 15 seconds. + + let deployedSubscription = new web3.eth.Contract(compiledSubscription.abi, data.contract_address); let deployedToken = new web3.eth.Contract( compiledToken.abi, // data.token_address - '0xFD9C55bf4B75Ef115749cF76E9083c4241D7a7eB' + '0x00e8baC402e187608C6585c435C9D35947770f5B' ); - web3.eth.getAccounts(function(err, accounts) { + deployedToken.methods.decimals().call(function(err, decimals) { + + let realTokenAmount = Number(data.amount_per_period * 10 ** decimals); + + console.log('realTokenAmount', realTokenAmount); + + let realGasPrice = Number(data.gas_price * 10 ** decimals); + + console.log('realGasPrice', realGasPrice); + + web3.eth.getAccounts(function(err, accounts) { + + deployedToken.methods.approve(data.contract_address, web3.utils.toTwosComplement(0)).send({from: accounts[0]}) + .on('transactionHash', function(hash) { + console.log('hash', hash); + + deployedSubscription.methods.extraNonce(accounts[0]).call(function(err, nonce) { + + nonce = parseInt(nonce) + 1; + + const parts = [ + // subscriber address + accounts[0], + // admin_address + data.admin_address, + // testing token + '0x00e8baC402e187608C6585c435C9D35947770f5B', + // data.amount_per_period + web3.utils.toTwosComplement(realTokenAmount), + // data.period_seconds + web3.utils.toTwosComplement(60), + // data.gas_price + web3.utils.toTwosComplement(realGasPrice), + // nonce + web3.utils.toTwosComplement(1), + // contributor_signature + data.signature + ]; - deployedToken.methods.approve(data.contract_address, web3.utils.toTwosComplement(0)).send({from: accounts[0], gas: 50000}, function(err, result) { + console.log('parts', parts); - form.submit(); + deployedSubscription.methods.cancelSubscription( + ...parts + ).send({from: accounts[0]}) + .on('confirmation', function(confirmationNumber, receipt) { + console.log('receipt', receipt); + form.submit(); + }); + }); + }) + .on('confirmation', function(confirmationNumber, receipt) { + console.log('receipt', receipt); + }) + .on('error', function(err) { + console.log('err', err); + }); }); }); } diff --git a/app/assets/v2/js/grants/fund_grant.js b/app/assets/v2/js/grants/fund_grant.js index 6a02329a70c..9f113629847 100644 --- a/app/assets/v2/js/grants/fund_grant.js +++ b/app/assets/v2/js/grants/fund_grant.js @@ -17,28 +17,42 @@ $(document).ready(function() { data[this.name] = this.value; }); - console.log(data); - - let value = 0; - let txData = '0x02'; // something like this to say, hardcoded VERSION 2, we're sending approved tokens - let gasLimit = 120000; - - // hardcode period seconds to monthly - let periodSeconds = 60; + let realPeriodSeconds = 0; + + if (data.frequency) { + // translate timeAmount&timeType to requiredPeriodSeconds + let periodSeconds = data.frequency; + + if (data.frequency_unit == 'minutes') { + periodSeconds *= 60; + } else if (data.frequency_unit == 'hours') { + periodSeconds *= 3600; + } else if (data.frequency_unit == 'days') { + periodSeconds *= 86400; + } else if (data.frequency_unit == 'months') { + periodSeconds *= 2592000; + } + if (periodSeconds) { + realPeriodSeconds = periodSeconds; + } + } if (!data.gas_price) data.gas_price = 0; - let deployedSubscription = new web3.eth.Contract(compiledSubscription.abi, data.contract_address); // This token is only for testing - let deployedToken = new web3.eth.Contract(compiledToken.abi, '0xFD9C55bf4B75Ef115749cF76E9083c4241D7a7eB'); - + // will need to make dynamic with data.token_address + let deployedToken = new web3.eth.Contract(compiledToken.abi, '0x00e8baC402e187608C6585c435C9D35947770f5B'); deployedToken.methods.decimals().call(function(err, decimals) { - console.log('decimals', typeof decimals); + console.log('decimals', decimals); + + let realApproval = Number(data.approve * 10 ** decimals); + + console.log('realApproval', realApproval); let realTokenAmount = Number(data.amount_per_period * 10 ** decimals); @@ -46,6 +60,7 @@ $(document).ready(function() { let realGasPrice = Number(data.gas_price * 10 ** decimals); + console.log('realGasPrice', realGasPrice); web3.eth.getAccounts(function(err, accounts) { @@ -55,12 +70,11 @@ $(document).ready(function() { // need to figure out why there does not seem to be a limit to this amount. Probably setting way higher than thought - deployedToken.methods.approve(data.contract_address, web3.utils.toTwosComplement(realTokenAmount)).send({from: accounts[0]}, function(err, result) { + deployedToken.methods.approve(data.contract_address, web3.utils.toTwosComplement(realApproval)).send({from: accounts[0]}, function(err, result) { // Should add approval transactions to transaction history console.log('result', result); - deployedSubscription.methods.extraNonce(accounts[0]).call(function(err, nonce) { console.log('nonce1', nonce); @@ -75,13 +89,13 @@ $(document).ready(function() { // admin_address data.admin_address, // testing token - '0xFD9C55bf4B75Ef115749cF76E9083c4241D7a7eB', + '0x00e8baC402e187608C6585c435C9D35947770f5B', // data.amount_per_period - web3.utils.toTwosComplement(data.amount_per_period), + web3.utils.toTwosComplement(realTokenAmount), // data.period_seconds - web3.utils.toTwosComplement(60), + web3.utils.toTwosComplement(realPeriodSeconds), // data.gas_price - web3.utils.toTwosComplement(data.gas_price), + web3.utils.toTwosComplement(realGasPrice), // nonce web3.utils.toTwosComplement(nonce) ]; @@ -130,18 +144,12 @@ $(document).ready(function() { .catch((error)=>{ console.log(error); }); - - }); }); }); - }); - - }); }); - } }); @@ -159,8 +167,4 @@ $(document).ready(function() { }); $('#js-token').select2(); }); - }); - -// will want to check if account already has a subscription. If a second is produced the timestamp will not function properly -// will need to check network to make sure users aren't submiting transactions to non-existant contracts diff --git a/app/assets/v2/js/grants/new.js b/app/assets/v2/js/grants/new.js index 43db141186d..f5f09567f7f 100644 --- a/app/assets/v2/js/grants/new.js +++ b/app/assets/v2/js/grants/new.js @@ -40,6 +40,25 @@ $(document).ready(function() { data[this.name] = this.value; }); + let requiredPeriodSeconds = 0; + + if (data.frequency) { + // translate timeAmount&timeType to requiredPeriodSeconds + let periodSeconds = data.frequency; + + if (data.frequency_unit == 'minutes') { + periodSeconds *= 60; + } else if (data.frequency_unit == 'hours') { + periodSeconds *= 3600; + } else if (data.frequency_unit == 'days') { + periodSeconds *= 86400; + } else if (data.frequency_unit == 'months') { + periodSeconds *= 2592000; + } + if (periodSeconds) { + requiredPeriodSeconds = periodSeconds; + } + } // Begin New Deploy Subscription Contract let SubscriptionContract = new web3.eth.Contract(compiledSubscription.abi); @@ -58,9 +77,9 @@ $(document).ready(function() { // data.token_address, '0x0000000000000000000000000000000000000000', // required tokenAmount - setting to zero - web3.utils.toTwosComplement(0), + web3.utils.toTwosComplement(data.required_amount), // data.frequency - web3.utils.toTwosComplement(0), + web3.utils.toTwosComplement(requiredPeriodSeconds), // data.gas_price web3.utils.toTwosComplement(0) ]; diff --git a/app/grants/templates/grants/cancel.html b/app/grants/templates/grants/cancel.html index 88d1a3bc219..7454abcbbb9 100644 --- a/app/grants/templates/grants/cancel.html +++ b/app/grants/templates/grants/cancel.html @@ -83,6 +83,11 @@