Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cancelSubscription contract functionality and minor fixes to index.html and detail.html #2501

Merged
merged 15 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/assets/v2/css/grants/detail.css
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ textarea.editable {
animation: rotation2 0.1s linear;
}

.update-milestone {
background-color: white;
}

@keyframes rotation {
from {
transform: rotate(0deg);
Expand Down Expand Up @@ -161,4 +165,4 @@ textarea.editable {
display: flex;
justify-content: center;
}
}
}
63 changes: 58 additions & 5 deletions app/assets/v2/js/grants/cancel_subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
}
Expand Down
60 changes: 32 additions & 28 deletions app/assets/v2/js/grants/fund_grant.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,50 @@ $(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;
captnseagraves marked this conversation as resolved.
Show resolved Hide resolved

if (data.frequency) {
// translate timeAmount&timeType to requiredPeriodSeconds
let periodSeconds = data.frequency;
captnseagraves marked this conversation as resolved.
Show resolved Hide resolved

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);

console.log('realTokenAmount', realTokenAmount);

let realGasPrice = Number(data.gas_price * 10 ** decimals);

console.log('realGasPrice', realGasPrice);

web3.eth.getAccounts(function(err, accounts) {

Expand All @@ -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);
Expand All @@ -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)
];
Expand Down Expand Up @@ -130,18 +144,12 @@ $(document).ready(function() {
.catch((error)=>{
console.log(error);
});


});
});
});

});


});
});

}
});

Expand All @@ -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
23 changes: 21 additions & 2 deletions app/assets/v2/js/grants/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ $(document).ready(function() {
data[this.name] = this.value;
});

let requiredPeriodSeconds = 0;
captnseagraves marked this conversation as resolved.
Show resolved Hide resolved

if (data.frequency) {
// translate timeAmount&timeType to requiredPeriodSeconds
let periodSeconds = data.frequency;
captnseagraves marked this conversation as resolved.
Show resolved Hide resolved

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);
Expand All @@ -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)
];
Expand Down
6 changes: 6 additions & 0 deletions app/grants/templates/grants/cancel.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ <h2 class="my-5 text-center">
</button>
<input type="hidden" id="contract_address" name="contract_address" value="{{ grant.contract_address }}">
<input type="hidden" id="token_address" name="token_address" value="{{ grant.token_address }}">
<input type="hidden" id="admin_address" name="admin_address" value="{{ grant.admin_address }}">
<input type="hidden" id="amount_per_period" name="amount_per_period" value="{{ subscription.amount_per_period }}">
<input type="hidden" id="period_seconds" name="period_seconds" value="{{ subscription.period_seconds }}">
<input type="hidden" id="signature" name="signature" value="{{ subscription.contributor_signature }}">
<input type="hidden" id="gas_price" name="gas_price" value="{{ subscription.gas_price }}">
</form>
</div>
</div>
Expand All @@ -102,6 +107,7 @@ <h2 class="my-5 text-center">
{% include 'shared/footer.html' %}
</body>
<!-- jQuery -->
<script src="{% static "v2/js/grants/compiledSubscriptionContract.js" %}"></script>
<script src="{% static "v2/js/grants/compiledTokenContract.js" %}"></script>
<script src="{% static "v2/js/grants/cancel_subscription.js" %}"></script>
<script src="{% static "v2/js/abi.js" %}"></script>
Expand Down
Loading