-
-
Notifications
You must be signed in to change notification settings - Fork 775
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
feat(grants): binance crosschain integration #8306
Merged
Merged
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
954a853
feat: add binance chain sync + new migration
chibie 4554e7f
defer makemigration
chibie 136400d
feat: sync payout/pending tx flow
chibie bf0ee50
update admin + repr + cart_payload
chibie c37f479
update contribute view
chibie 97454ce
update grant new + edit view
chibie d42ff14
fix redundancy
chibie 897e2bc
add binance to grant creation flow + edit flow
chibie ae993d3
add contribution with binance extension
chibie 23c044e
binance cart flow
chibie b4288b9
Merge branch 'master' into feat/grants-binance-crosschain
chibie 275ba02
handle BUSD contribution
chibie a41a061
Merge branch 'master' into feat/grants-binance-crosschain
chibie e9bbb5a
fix isBinanceExtInstalled
chibie 9b63d6d
new migration
chibie f43ee04
fix chain selection
chibie 9f24347
include binance html + handle decimals
chibie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const contributeWithBinanceExtension = async (grant, vm) => { | ||
const amount = grant.grant_donation_amount; | ||
const token_name = grant.grant_donation_currency; | ||
const to_address = grant.binance_payout_address; | ||
|
||
try { | ||
const from_address = await binance_utils.getSelectedAccount(); | ||
} catch (error) { | ||
_alert({ message: `Please ensure your Binance Chain Extension wallet is installed and enabled`}, 'error'); | ||
return; | ||
} | ||
const account_balance = await binance_utils.getAddressBalance(from_address); | ||
|
||
if (Number(account_balance) < amount) { | ||
_alert({ message: `Account needs to have more than ${amount} BNB for payout` }, 'error'); | ||
return; | ||
} | ||
|
||
binance_utils.transferViaExtension( | ||
amount * 10 ** vm.decimals, | ||
to_address, | ||
from_address, | ||
token_name | ||
).then(txn => { | ||
if (txn) { | ||
callback(null, from_address, txn); | ||
} else { | ||
callback('error in signing transaction'); | ||
} | ||
}).catch(err => { | ||
callback(err); | ||
}); | ||
|
||
function callback(error, from_address, txn) { | ||
if (error) { | ||
vm.updatePaymentStatus(grant.grant_id, 'failed'); | ||
_alert({ message: gettext('Unable to contribute to grant due to ' + error) }, 'error'); | ||
console.log(error); | ||
} else { | ||
|
||
const payload = { | ||
'contributions': [{ | ||
'grant_id': grant.grant_id, | ||
'contributor_address': from_address, | ||
'tx_id': txn, | ||
'token_symbol': grant.grant_donation_currency, | ||
'tenant': 'BINANCE', | ||
'comment': grant.grant_comments, | ||
'amount_per_period': grant.grant_donation_amount | ||
}] | ||
}; | ||
|
||
const apiUrlGrant = `v1/api/contribute`; | ||
|
||
fetchData(apiUrlGrant, 'POST', JSON.stringify(payload)).then(response => { | ||
if (200 <= response.status && response.status <= 204) { | ||
console.log('success', response); | ||
|
||
vm.updatePaymentStatus(grant.grant_id, 'done', txn); | ||
|
||
} else { | ||
vm.updatePaymentStatus(grant.grant_id, 'failed'); | ||
_alert('Unable to make contribute to grant. Please try again later', 'error'); | ||
console.error(`error: grant contribution failed with status: ${response.status} and message: ${response.message}`); | ||
} | ||
}).catch(function (error) { | ||
vm.updatePaymentStatus(grant.grant_id, 'failed'); | ||
_alert('Unable to make contribute to grant. Please try again later', 'error'); | ||
console.log(error); | ||
}); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import requests | ||
from grants.sync.helpers import record_contribution_activity | ||
|
||
|
||
def get_binance_txn_status(contribution): | ||
txnid = contribution.tx_id | ||
|
||
if not txnid or txnid == "0x0": | ||
return None | ||
|
||
response = { 'status': 'pending' } | ||
|
||
try: | ||
binance_url = f'https://bsc-dataseed.binance.org' | ||
|
||
data = { | ||
'id': 0, | ||
'jsonrpc': '2.0', | ||
'method': 'eth_getTransactionReceipt', | ||
'params': [ txnid ] | ||
} | ||
|
||
headers = { | ||
'Host': 'gitcoin.co' | ||
} | ||
|
||
binance_response = requests.post(binance_url, json=data).json() | ||
|
||
result = binance_response['result'] | ||
|
||
response = { 'status': 'pending' } | ||
|
||
if result: | ||
tx_status = int(result.get('status'), 16) # convert hex to decimal | ||
|
||
if tx_status == 1: | ||
response = { 'status': 'done' } | ||
elif tx_status == 0: | ||
response = { 'status': 'expired' } | ||
|
||
except Exception as e: | ||
logger.error(f'error: get_binance_txn_status - {e}') | ||
|
||
finally: | ||
return response | ||
|
||
|
||
def sync_binance_payout(contribution): | ||
if contribution.tx_id or contribution.tx_id == "0x0": | ||
txn_status = get_binance_txn_status(contribution) | ||
|
||
if txn_status: | ||
status_description = txn_status.get('status') | ||
|
||
if status_description == 'done': | ||
contribution.success = True | ||
contribution.tx_cleared = True | ||
contribution.checkout_type = 'binance_std' | ||
record_contribution_activity(contribution) | ||
contribution.save() | ||
elif status_description == 'expired': | ||
contribution.success = True | ||
contribution.tx_cleared = False | ||
contribution.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops.... should be
window.BinanceChain || false;
thanks man