Skip to content

Commit 670ca69

Browse files
chibieamustaphathelostone-mc
authored
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 <abdulhakeemmustapha@gmail.com> Co-authored-by: Aditya Anand M C <aditya.anandmc@gmail.com>
1 parent a47e128 commit 670ca69

6 files changed

Lines changed: 17 additions & 9 deletions

File tree

app/assets/v2/js/lib/binance/utils.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ binance_utils.getAddressTokenBalance = async (address, tokenContractAddress) =>
6060
['balanceOf(address)']
6161
);
6262
const method_id = methodSignature.substr(0, 10);
63-
const address = address.substr(2).padStart(64, '0'); // remove 0x and pad with zeroes
63+
address = address.substr(2).padStart(64, '0'); // remove 0x and pad with zeroes
6464

6565
const params = [
6666
{
@@ -166,7 +166,9 @@ binance_utils.transferViaExtension = async (amount, to_address, from_address, to
166166

167167
} else if (token_name === 'BUSD') {
168168

169-
const account_balance = await binance_utils.getAddressTokenBalance(from_address);
169+
const busd_contract_address = '0xe9e7cea3dedca5984780bafc599bd69add087d56'
170+
171+
const account_balance = await binance_utils.getAddressTokenBalance(from_address, busd_contract_address);
170172

171173
if (Number(account_balance) < amount ) {
172174
reject(`transferViaExtension: insufficent balance in address ${from_address}`);
@@ -185,7 +187,7 @@ binance_utils.transferViaExtension = async (amount, to_address, from_address, to
185187
const params = [
186188
{
187189
from: from_address,
188-
to: '0xe9e7cea3dedca5984780bafc599bd69add087d56', // BUSD token contract address
190+
to: busd_contract_address,
189191
data: method_id + to_address + amount
190192
},
191193
]

app/assets/v2/js/pages/bounty_detail/binance_extension.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const payWithBinanceExtension = (fulfillment_id, to_address, vm, modal) => {
33
const amount = vm.fulfillment_context.amount;
44
const token_name = vm.bounty.token_name;
55
const from_address = vm.bounty.bounty_owner_address;
6-
6+
77
binance_utils.transferViaExtension(
88
amount * 10 ** vm.decimals,
99
to_address,

app/assets/v2/js/pages/hackathon_new_bounty.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ Vue.mixin({
6262
});
6363

6464
},
65+
getBinanceSelectedAccount: async function() {
66+
let vm = this;
67+
68+
vm.form.funderAddress = await binance_utils.getSelectedAccount();
69+
},
6570
getAmount: function(token) {
6671
let vm = this;
6772

app/dashboard/sync/binance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_binance_txn_status(fulfillment):
3434
'Host': 'gitcoin.co'
3535
}
3636

37-
binance_response = requests.post(binance_url, json=data, headers=headers).json()
37+
binance_response = requests.post(binance_url, json=data).json()
3838

3939
result = binance_response['result']
4040

@@ -43,9 +43,9 @@ def get_binance_txn_status(fulfillment):
4343
if result:
4444
tx_status = int(result.get('status'), 16) # convert hex to decimal
4545

46-
if tx_status == '1':
46+
if tx_status == 1:
4747
response = { 'status': 'done' }
48-
elif tx_status == '0':
48+
elif tx_status == 0:
4949
response = { 'status': 'expired' }
5050

5151
except Exception as e:

app/dashboard/templates/bounty/new_bounty.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,6 @@ <h5 class="text-uppercase h3 font-weight-bold mb-0">Total</h5>
743743
<script src="{% static "v2/js/lib/polkadot/extension.min.js" %}"></script>
744744
<script src="{% static "v2/js/lib/polkadot/utils.js" %}"></script>
745745

746-
<script src="https://cdn.jsdelivr.net/npm/@binance-chain/javascript-sdk@4.1.1/lib/index.min.js"></script>
747746
<script src="{% static "v2/js/lib/binance/utils.js" %}"></script>
748747

749748
<script>

app/dashboard/templates/dashboard/hackathon/new_bounty.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ <h1 class="text-center">Fund Prize</h1>
444444
</div>
445445
</div>
446446

447-
<div class="funder-address-container" v-show="chainId !== '1'">
447+
<div class="funder-address-container" v-show="chainId !== '1' && chainId !== '56'">
448448
<label class="font-caption letter-spacing text-black-60" for="funderAddress">Funder Address</label>
449449
<input name="funderAddress" id="funderAddress" class="form__input" type="text" placeholder="Address with which the bounty will be paid out" v-model="form.funderAddress">
450450
<div class="text-danger" v-if="errors.funderAddress && !form.funderAddress">
@@ -521,6 +521,8 @@ <h5 class="text-uppercase h3 font-weight-bold mb-0">Total</h5>
521521
<script src="{% static "v2/js/lib/polkadot/extension.min.js" %}"></script>
522522
<script src="{% static "v2/js/lib/polkadot/utils.js" %}"></script>
523523

524+
<script src="{% static "v2/js/lib/binance/utils.js" %}"></script>
525+
524526
<script>
525527
$('body').bootstrapTooltip({
526528
selector: '[data-toggle="tooltip"]'

0 commit comments

Comments
 (0)