Skip to content

Commit

Permalink
feat(binance): integrate BUSD for bounties and hackathons 2 (#8213)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Aditya Anand M C <[email protected]>
  • Loading branch information
3 people authored Jan 11, 2021
1 parent a47e128 commit 670ca69
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
8 changes: 5 additions & 3 deletions app/assets/v2/js/lib/binance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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}`);
Expand All @@ -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
},
]
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/bounty_detail/binance_extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions app/assets/v2/js/pages/hackathon_new_bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions app/dashboard/sync/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand All @@ -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:
Expand Down
1 change: 0 additions & 1 deletion app/dashboard/templates/bounty/new_bounty.html
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,6 @@ <h5 class="text-uppercase h3 font-weight-bold mb-0">Total</h5>
<script src="{% static "v2/js/lib/polkadot/extension.min.js" %}"></script>
<script src="{% static "v2/js/lib/polkadot/utils.js" %}"></script>

<script src="https://cdn.jsdelivr.net/npm/@binance-chain/[email protected]/lib/index.min.js"></script>
<script src="{% static "v2/js/lib/binance/utils.js" %}"></script>

<script>
Expand Down
4 changes: 3 additions & 1 deletion app/dashboard/templates/dashboard/hackathon/new_bounty.html
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ <h1 class="text-center">Fund Prize</h1>
</div>
</div>

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

<script src="{% static "v2/js/lib/binance/utils.js" %}"></script>

<script>
$('body').bootstrapTooltip({
selector: '[data-toggle="tooltip"]'
Expand Down

0 comments on commit 670ca69

Please sign in to comment.