Better transaction results
This commit is contained in:
parent
8e89a5c4d8
commit
456f49f65f
35
index.html
35
index.html
@ -403,7 +403,7 @@
|
||||
onclick="removeInvalid()">Fix</button>
|
||||
<div class="multi-state-button">
|
||||
<button id="send_button" class="button button--primary cta" type="submit"
|
||||
onclick="sendMessage()">Send</button>
|
||||
onclick="initTransaction()">Send</button>
|
||||
</div>
|
||||
</div>
|
||||
</sm-form>
|
||||
@ -2470,7 +2470,7 @@
|
||||
})
|
||||
}
|
||||
|
||||
function sendMessage() {
|
||||
function initTransaction() {
|
||||
const privKey = getRef('get_private_key_field').value.trim();
|
||||
const sender = floCrypto.getFloID(privKey)
|
||||
const floAmount = parseFloat(getRef('tx_flo_amount').value.trim());
|
||||
@ -2500,7 +2500,13 @@
|
||||
})
|
||||
}
|
||||
|
||||
function showTransactionResult(success, result) {
|
||||
function showTransactionResult(success, result, options = {}) {
|
||||
let { title, description } = options
|
||||
if (!title)
|
||||
title = success ? 'Transaction request sent' : 'Transaction failed'
|
||||
if (!description)
|
||||
description = success ? 'This might take upto 30 mins to complete and reflect on blockchain.' : result
|
||||
|
||||
renderElem(getRef('transaction_result'), html`
|
||||
${success ? html`
|
||||
<svg class="icon icon--success" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"> <path d="M0 0h24v24H0z" fill="none" /> <path d="M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z" /> </svg>
|
||||
@ -2508,8 +2514,8 @@
|
||||
${!success ? html`
|
||||
<svg class="icon icon--failed" xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"> <path d="M0 0h24v24H0z" fill="none" /> <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z" /> </svg>
|
||||
` : ''}
|
||||
<h3 id="transaction_result__title">${success ? 'Transaction request sent' : 'Transaction failed'}</h3>
|
||||
<p id="transaction_result__description"> ${success ? 'This might take upto 30 mins to complete and reflect on blockchain.' : result} </p>
|
||||
<h3 id="transaction_result__title">${title}</h3>
|
||||
<p id="transaction_result__description"> ${description} </p>
|
||||
${success ? html`
|
||||
<div class="grid gap-1">
|
||||
<a id="transaction_link" href=${`${floBlockchainAPI.current_server}tx/${result}`} style="margin-top: 1.5rem;" target="_blank">See transaction on blockchain</a>
|
||||
@ -2706,7 +2712,10 @@
|
||||
}).then(res => {
|
||||
if (!res) return
|
||||
floBlockchainAPI.sendTx(depositorAddress, contractAddress, floGlobals.sendAmt, depositorPrivateKey, floData).then(txid => {
|
||||
showTransactionResult(true, txid)
|
||||
showTransactionResult(true, txid, {
|
||||
title: `${sellingToken} tokens deposited`,
|
||||
description: `If your tokens are not exchanged before the expiry time, you will get them back.`
|
||||
})
|
||||
getRef('smart_contract_deposit_form').reset()
|
||||
document.getElementById('deposit_button').disabled = true
|
||||
}).catch(error => {
|
||||
@ -2732,18 +2741,21 @@
|
||||
const participantPrivateKey = document.getElementById('participant_private_key').value.trim()
|
||||
const participantAddress = floCrypto.getFloID(participantPrivateKey)
|
||||
let floData
|
||||
let title = 'Participation successful'
|
||||
switch (contractType) {
|
||||
case 'one-time-event': {
|
||||
// check min,max subscription and participation amount
|
||||
switch (contractSubType) {
|
||||
case 'time-trigger':
|
||||
floData = `send ${participationAmount} ${tokenIdentification}# to ${contractName}@`
|
||||
description = `You have participated in the event. Check out details <a href=${`https://ranchimall.github.io/floscout/#/contract/${contractName}-${contractAddress}`} target='_blank'>here</a>`
|
||||
break
|
||||
case 'external-trigger':
|
||||
const userChoice = getRef('smart_contract_participate_form').querySelector('input[name="choice"]:checked').value
|
||||
if (!userChoice)
|
||||
return notify('Please select a choice', 'error')
|
||||
floData = `send ${participationAmount} ${tokenIdentification}# to ${contractName}@ to FLO address ${contractAddress} with the userchoice: ${userChoice}`
|
||||
description = html`You have casted your vote. Check out details <a href=${`https://ranchimall.github.io/floscout/#/contract/${contractName}-${contractAddress}`} target='_blank'>here</a>`
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -2752,6 +2764,8 @@
|
||||
switch (contractSubType) {
|
||||
case 'tokenswap':
|
||||
floData = `send ${participationAmount} ${acceptingToken}# to ${contractName}@`
|
||||
title = 'Token swap initiated'
|
||||
description = html`Check your transactions and token balance <a href=${`https://ranchimall.github.io/flowallet/#/transactions/${participantAddress}`} target='_blank'>here</a>`
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -2773,7 +2787,10 @@
|
||||
}).then(res => {
|
||||
if (!res) return
|
||||
floBlockchainAPI.sendTx(participantAddress, contractAddress, floGlobals.sendAmt, participantPrivateKey, floData).then(txid => {
|
||||
showTransactionResult(true, txid)
|
||||
showTransactionResult(true, txid, {
|
||||
title,
|
||||
description
|
||||
})
|
||||
getRef('smart_contract_participate_form').reset()
|
||||
document.getElementById('participate_button').disabled = true
|
||||
}).catch(error => {
|
||||
@ -2809,7 +2826,9 @@
|
||||
if (!res) return
|
||||
buttonLoader(e.target.closest('button'), true)
|
||||
floBlockchainAPI.writeData(oracleAddress, floData, oraclePrivateKey, contractAddress).then((txid) => {
|
||||
showTransactionResult(true, txid)
|
||||
showTransactionResult(true, txid, {
|
||||
title: 'Price update initiated',
|
||||
})
|
||||
getRef('smart_contract_update_form').reset()
|
||||
document.getElementById('update_price_button').disabled = true
|
||||
}).catch((error) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user