Skip to content

Commit

Permalink
fix web3connect in bounty create flow
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Mar 13, 2020
1 parent 3c14067 commit c501e57
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 33 deletions.
14 changes: 14 additions & 0 deletions app/assets/v2/css/submit_bounty.css
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,18 @@ input:read-only {
display: inline-block;
top: 3px;
position: relative;
}

.wallet-alert {
border-radius: 4px;
}

.wallet-not-connected {
color: #E49003;
background: rgb(228, 144, 3, 0.2);
}

.wallet-success {
color: #0FCE7C;
background: rgb(15, 206, 124, 0.2);
}
7 changes: 2 additions & 5 deletions app/assets/v2/js/pages/bounty_details2.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,17 @@ Vue.mixin({
});
}
},
fulfillmentComplete: function(fulfillment_id, amount, bounty_owner_address) {
fulfillmentComplete: function(fulfillment_id, amount) {

let vm = this;
const owner_address = vm.bounty.bounty_owner_address ?
vm.bounty.bounty_owner_address :
bounty_owner_address;

const token_name = vm.bounty.token_name;
const decimals = tokenNameToDetails('mainnet', token_name).decimals;

const payload = {
amount: amount * 10 ** decimals,
token_name: token_name,
bounty_owner_address: owner_address
bounty_owner_address: vm.bounty.bounty_owner_address
};

const apiUrlBounty = `/api/v1/bounty/payout/${fulfillment_id}`;
Expand Down
4 changes: 4 additions & 0 deletions app/assets/v2/js/pages/bulk_payout.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});

const rateUser = (elem) => {
let userSelected = $(elem).select2('data')[0].text;

Expand Down
5 changes: 5 additions & 0 deletions app/assets/v2/js/pages/cancel_bounty/ETH.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* Data is stored on IPFS + the data is stored in
* standard bounties contract on the ethereum blockchain
*/

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});

const ethCancelBounty = data => {

if (is_bounties_network) {
Expand Down
3 changes: 2 additions & 1 deletion app/assets/v2/js/pages/create_bounty/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ createBounty = data => {
'attached_job_description': hiring.jobDescription,
'eventTag': metadata.eventTag,
'auto_approve_workers': data.auto_approve_workers ? 'True' : 'False',
'web3_type': 'qr'
'web3_type': 'qr',
'bounty_owner_address': data.funderAddress
};

const url = '/api/v1/bounty/create';
Expand Down
4 changes: 4 additions & 0 deletions app/assets/v2/js/pages/faucet_form.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});

$('document').ready(function() {

$('#comment').bind('input propertychange', function() {
Expand Down
5 changes: 5 additions & 0 deletions app/assets/v2/js/pages/fulfill_bounty/ETH.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* Data is stored on IPFS + the data is stored in
* standard bounties contract on the ethereum blockchain
*/

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});

const ethFulfillBounty = data => {
if (is_bounties_network) {
waitforWeb3(actions_page_warn_if_not_on_same_network);
Expand Down
4 changes: 4 additions & 0 deletions app/assets/v2/js/pages/increase_bounty.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* eslint-disable no-lonely-if */
window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});

load_tokens();

const FEE_PERCENTAGE = document.FEE_PERCENTAGE / 100.0;
Expand Down
69 changes: 66 additions & 3 deletions app/assets/v2/js/pages/new_bounty.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,60 @@
/* eslint-disable no-console */
/* eslint-disable nonblock-statement-body-position */
/* eslint-disable no-lonely-if */
document.web3network = 'mainnet';
load_tokens();

const qr_tokens = ['ETC'];


const updateOnNetworkOrTokenChange = () => {
const tokenName = $('select[name=denomination]').select2('data')[0] &&
$('select[name=denomination]').select2('data')[0].text;

if (!tokenName) {
// tokens haven't loaded yet
} else if (qr_tokens.includes(tokenName)) {
document.web3network = 'mainnet';

$('#navbar-network-banner').hide();
$('.navbar-network').hide();

$('.funder-address-container').show();
$('#funderAddress').attr('required', true);

$('.web3-alert').hide();

} else {
listen_for_web3_changes();

$('#navbar-network-banner').show();
$('.navbar-network').show();

$('.funder-address-container').hide();
$('#funderAddress').attr('required', '');
$('#funderAddress').val('');

$('.web3-alert').show();
if (!document.web3network) {
$('.web3-alert').html('To continue, please setup a web3 wallet.');
$('.web3-alert').addClass('wallet-not-connected');
} else if (document.web3network == 'locked') {
$('.web3-alert').html('To continue, please unlock your web3 wallet');
$('.web3-alert').addClass('wallet-not-connected');
} else if (document.web3network == 'rinkeby') {
$('.web3-alert').html(`connected to address <b>${web3.eth.coinbase}</b> on rinkeby`);
$('.web3-alert').addClass('wallet-success');
} else {
$('.web3-alert').html(`connected to address <b>${web3.eth.coinbase}</b> on mainnet`);
$('.web3-alert').addClass('wallet-success');
}
}
};

window.addEventListener('load', function() {
setInterval(updateOnNetworkOrTokenChange, 5000);
});

var localStorage = window.localStorage ? window.localStorage : {};
const quickstartURL = document.location.origin + '/bounty/quickstart';

Expand Down Expand Up @@ -364,9 +416,19 @@ $(function() {
var triggerDenominationUpdate = function(e) {
setUsdAmount();
handleTokenAuth();
const token_val = $('select[name=denomination]').val();
const tokendetails = tokenAddressToDetails(token_val);
var token = tokendetails['name'];

updateOnNetworkOrTokenChange();

const token_address = $('select[name=denomination]').val();

const tokenName = $('select[name=denomination]').select2('data')[0] ?
$('select[name=denomination]').select2('data')[0].text : 'ETH';

const tokendetails = qr_tokens.includes(tokenName) ?
tokenAddressToDetailsByNetwork(token_address, 'mainnet') :
tokenAddressToDetails(token_address);

const token = tokendetails['name'];

updateViewForToken(token);

Expand All @@ -376,6 +438,7 @@ $(function() {
};

$('select[name=denomination]').change(triggerDenominationUpdate);

waitforWeb3(function() {
setTimeout(function() {
triggerDenominationUpdate();
Expand Down
5 changes: 5 additions & 0 deletions app/assets/v2/js/pages/process_bounty.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
/* eslint-disable no-console */

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});

window.onload = function() {

const rateUser = () => {
Expand Down
4 changes: 4 additions & 0 deletions app/assets/v2/js/pages/refund_request.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});

$(document).ready(function() {
if (!caseInsensitiveCompare($('#bounty_owner').html(), document.contxt.github_handle)) {
$('.metamask-banner').hide();
Expand Down
5 changes: 0 additions & 5 deletions app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,11 +1023,6 @@ var actions_page_warn_if_not_on_same_network = function() {

attach_change_element_type();

if (typeof is_bounties_network == 'undefined' || is_bounties_network) {
window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});
}

var setUsdAmount = function() {
const amount = $('input[name=amount]').val();
Expand Down
6 changes: 1 addition & 5 deletions app/dashboard/templates/bounty/details2.html
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ <h4 class="mb-3">
<span class="d-block">Scan QR code using address</span>
<span>[[bounty.bounty_owner_address]]</span>
</p>
<p v-else>
<span class="d-block">Enter Address with which payment will be made</span>
<input class="w-75" v-model="inputBountyOwnerAddress">
</p>

<p>Payout [[ bounty.value_in_eth ]] [[ bounty.token_name ]] to [[ fulfillment.profile.handle ]] ([[ fulfillment.fulfiller_address | truncateHash ]])</p>

Expand All @@ -374,7 +370,7 @@ <h4 class="mb-3">
<qrcode :string="`${fulfillment.fulfiller_address}?amount=${inputAmount}`"></qrcode>
<small class="d-block my-3">Scan the QR code above with your ETC Wallet to payout</small>
<button class="d-block mx-auto mb-3 btn btn-outline-gc-blue px-2 font-caption font-weight-semibold"
@click="fulfillmentComplete(fulfillment.pk, inputAmount, inputBountyOwnerAddress)"
@click="fulfillmentComplete(fulfillment.pk, inputAmount)"
>
I've Scanned + Paid
</button>
Expand Down
22 changes: 9 additions & 13 deletions app/dashboard/templates/bounty/fund.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,9 @@
{% include 'shared/nav.html' %}
</div>
<div class="submit_bounty_content">
<div class="row no-gutters metamask-banner">
<div class="col-12">
{% include 'shared/no_issue_error.html' with page='submit_bounty' %}
{% include 'shared/no_metamask_error.html' %}
{% include 'shared/zero_balance_error.html' %}
{% include 'shared/unlock_metamask.html' %}
{% include 'shared/connect_metamask.html' %}
</div>
</div>
<div class="row justify-content-center">

<div id="robot_error" class="hidden">
<img src="{% static "v2/images/prime.png" %}">
</div>
<div class="col-lg-8 col-sm-12 my-5" id="primary_form">
<div class="col-lg-8 col-sm-12 my-5" id="create_bounty_form">
<form id="submitBounty" class="pt-5">

<div id="about-section" class="pt-2 bg-white rounded p-5">
Expand Down Expand Up @@ -114,6 +102,14 @@ <h5 class="font-smaller-3 font-weight-bold mb-2">Important Notes on Private Repo

{% include 'shared/pricing.html' %}

<div class="web3-alert font-smaller-2 py-2 px-3 mt-2">
</div>

<div class="funder-address-container" style="display: none;">
<label class="font-caption letter-spacing text-black-60" for=funderAddress>{% trans "Funder Address" %}</label>
<input name='funderAddress' id="funderAddress" class="form__input" type="text" placeholder="{% trans 'Address with which the bounty will be paid out' %}"/>
</div>

<div class="mt-4">
{% include 'shared/bounty_details.html' %}
</div>
Expand Down
1 change: 1 addition & 0 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4658,6 +4658,7 @@ def create_bounty_v1(request):
bounty.raw_data = request.POST.get("raw_data", {}) # ETC-TODO: REMOVE ?
bounty.web3_type = request.POST.get("web3_type", '')
bounty.value_true = request.POST.get("amount", 0)
bounty.bounty_owner_address = request.POST.get("bounty_owner_address", 0)

''' ETC-TODO
bounty.unsigned_nda = request.POST.get("unsigned_nda")
Expand Down
2 changes: 1 addition & 1 deletion app/grants/templates/grants/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</head>
<body class="interior {{ active }} grant g-font-muli">
{% include 'shared/tag_manager_2.html' %}
<div class="container-fluid header dash">
<div class="container-fluid header dash px-0">
{% include 'shared/top_nav.html' with class='d-md-flex' %}
{% include 'grants/nav.html' %}
<div class="row no-gutters metamask-banner">
Expand Down
5 changes: 5 additions & 0 deletions app/retail/templates/pricing/subscribe.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ <h2 class="price">
<script src="{% static 'v2/js/lib/animate-number.min.js' %}"></script>

<script>

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
});

$(document).ready(function() {

if(getParam('pack') == 'annual')
Expand Down

0 comments on commit c501e57

Please sign in to comment.