From 670ca69e7686847a27bbd37a4d680e116b26a9e2 Mon Sep 17 00:00:00 2001 From: Chibuotu Amadi Date: Mon, 11 Jan 2021 14:02:47 +0100 Subject: [PATCH] feat(binance): integrate BUSD for bounties and hackathons 2 (#8213) * feat: include BUSD case in bounty detail * process BUSD token transfer * refactor utils + token balance checks - add util to get token balance - enforce sufficient balance for transfer * litte refactor * use only jsonRpcRequest util * fix: amount comparison for insufficient balance * add util to get selected account * use only getSelectedAccount util * autofill funderAddress with selected account * Remove broken CDN import * Fix variable duplicatino * feat: add busd to hackathon bounty * fix: pass contract address to getAddressTokenBalance * fix bug in binance sync tx * remove failing import * fix address bug Co-authored-by: aamustapha Co-authored-by: Aditya Anand M C --- app/assets/v2/js/lib/binance/utils.js | 8 +++++--- app/assets/v2/js/pages/bounty_detail/binance_extension.js | 2 +- app/assets/v2/js/pages/hackathon_new_bounty.js | 5 +++++ app/dashboard/sync/binance.py | 6 +++--- app/dashboard/templates/bounty/new_bounty.html | 1 - .../templates/dashboard/hackathon/new_bounty.html | 4 +++- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/assets/v2/js/lib/binance/utils.js b/app/assets/v2/js/lib/binance/utils.js index 3e932eb7222..7fa5ed7b6aa 100644 --- a/app/assets/v2/js/lib/binance/utils.js +++ b/app/assets/v2/js/lib/binance/utils.js @@ -60,7 +60,7 @@ binance_utils.getAddressTokenBalance = async (address, tokenContractAddress) => ['balanceOf(address)'] ); const method_id = methodSignature.substr(0, 10); - const address = address.substr(2).padStart(64, '0'); // remove 0x and pad with zeroes + address = address.substr(2).padStart(64, '0'); // remove 0x and pad with zeroes const params = [ { @@ -166,7 +166,9 @@ binance_utils.transferViaExtension = async (amount, to_address, from_address, to } else if (token_name === 'BUSD') { - const account_balance = await binance_utils.getAddressTokenBalance(from_address); + const busd_contract_address = '0xe9e7cea3dedca5984780bafc599bd69add087d56' + + const account_balance = await binance_utils.getAddressTokenBalance(from_address, busd_contract_address); if (Number(account_balance) < amount ) { reject(`transferViaExtension: insufficent balance in address ${from_address}`); @@ -185,7 +187,7 @@ binance_utils.transferViaExtension = async (amount, to_address, from_address, to const params = [ { from: from_address, - to: '0xe9e7cea3dedca5984780bafc599bd69add087d56', // BUSD token contract address + to: busd_contract_address, data: method_id + to_address + amount }, ] diff --git a/app/assets/v2/js/pages/bounty_detail/binance_extension.js b/app/assets/v2/js/pages/bounty_detail/binance_extension.js index d0de7c0a313..90896a7117b 100644 --- a/app/assets/v2/js/pages/bounty_detail/binance_extension.js +++ b/app/assets/v2/js/pages/bounty_detail/binance_extension.js @@ -3,7 +3,7 @@ const payWithBinanceExtension = (fulfillment_id, to_address, vm, modal) => { const amount = vm.fulfillment_context.amount; const token_name = vm.bounty.token_name; const from_address = vm.bounty.bounty_owner_address; - + binance_utils.transferViaExtension( amount * 10 ** vm.decimals, to_address, diff --git a/app/assets/v2/js/pages/hackathon_new_bounty.js b/app/assets/v2/js/pages/hackathon_new_bounty.js index 263a2ba84b6..259bd80f829 100644 --- a/app/assets/v2/js/pages/hackathon_new_bounty.js +++ b/app/assets/v2/js/pages/hackathon_new_bounty.js @@ -62,6 +62,11 @@ Vue.mixin({ }); }, + getBinanceSelectedAccount: async function() { + let vm = this; + + vm.form.funderAddress = await binance_utils.getSelectedAccount(); + }, getAmount: function(token) { let vm = this; diff --git a/app/dashboard/sync/binance.py b/app/dashboard/sync/binance.py index 1992f33a0b8..2a533470be2 100644 --- a/app/dashboard/sync/binance.py +++ b/app/dashboard/sync/binance.py @@ -34,7 +34,7 @@ def get_binance_txn_status(fulfillment): 'Host': 'gitcoin.co' } - binance_response = requests.post(binance_url, json=data, headers=headers).json() + binance_response = requests.post(binance_url, json=data).json() result = binance_response['result'] @@ -43,9 +43,9 @@ def get_binance_txn_status(fulfillment): if result: tx_status = int(result.get('status'), 16) # convert hex to decimal - if tx_status == '1': + if tx_status == 1: response = { 'status': 'done' } - elif tx_status == '0': + elif tx_status == 0: response = { 'status': 'expired' } except Exception as e: diff --git a/app/dashboard/templates/bounty/new_bounty.html b/app/dashboard/templates/bounty/new_bounty.html index cd2c00e45e4..70c410c689d 100644 --- a/app/dashboard/templates/bounty/new_bounty.html +++ b/app/dashboard/templates/bounty/new_bounty.html @@ -743,7 +743,6 @@
Total
- + +