diff --git a/index.html b/index.html index 47afcec..f6f302d 100644 --- a/index.html +++ b/index.html @@ -452,7 +452,7 @@ Update price -
  • - FLO private key - - - - -
    - Select smart contract - - ${render.availableSmartContractOptions(filteredSmartContracts)} - -
    -
    - Select outcome
    - - + Select smart contract + + ${render.availableSmartContractOptions(filteredSmartContracts, `${contractName}_${contractAddress}`)} +
    -
    -
    - -
    - `) +
    + Select outcome +
    + ${userChoices.map(choice => html` + + `)} +
    +
    +
    + Contract address FLO private key + + + +
    +
    + +
    + `) } else { renderElem(getRef('smart_contract_trigger_form'), html`
    @@ -2610,67 +2613,67 @@ '--redish-orange', ] - // async function getContractInfo(name, address) { - // return new Promise((resolve, reject) => { - // if (!name) { - // name = floGlobals.smartContracts[0].contractName - // address = floGlobals.smartContracts[0].contractAddress - // } - // fetchJSON(`https://ranchimallflo.duckdns.org/api/v2/smartContractInfo?contractName=${name}&contractAddress=${address}`) - // .then(info => { - // console.log(info) - // const { - // contractInfo: { - // contractType, - // numberOfDeposits, - // numberOfParticipants, - // priceType, - // oracle_address, - // contractSubtype, - // status, - // expiryTime, - // payeeAddress, - // userChoices, - // tokenIdentification, - // acceptingToken, - // sellingToken, - // contractAmount, - // minimumsubscriptionamount, - // maximumsubscriptionamount, - // totalHonorAmount, - // totalParticipationAmount, - // price - // }, contractAddress, - // contractName - // } = info - // resolve({ - // contractName, - // contractAddress, - // contractType, - // contractSubtype, - // status, - // expiryTime, - // payeeAddress, - // userChoices, - // token: tokenIdentification, - // acceptingToken, - // sellingToken, - // participationFees: contractAmount, - // minimumsubscriptionamount, - // maximumsubscriptionamount, - // numberOfDeposits, - // numberOfParticipants, - // priceType, - // oracle_address, - // totalHonorAmount, - // totalParticipationAmount, - // price - // }) - // }).catch(error => { - // reject(error) - // }) - // }) - // } + async function getContractInfo(name, address) { + return new Promise((resolve, reject) => { + if (!name) { + name = floGlobals.smartContracts[0].contractName + address = floGlobals.smartContracts[0].contractAddress + } + fetchJSON(`${floGlobals.tokenApiUrl}/api/v2/smartContractInfo?contractName=${name}&contractAddress=${address}`) + .then(info => { + console.log(info) + const { + contractInfo: { + contractType, + numberOfDeposits, + numberOfParticipants, + priceType, + oracle_address, + contractSubtype, + status, + expiryTime, + payeeAddress, + userChoices, + tokenIdentification, + acceptingToken, + sellingToken, + contractAmount, + minimumsubscriptionamount, + maximumsubscriptionamount, + totalHonorAmount, + totalParticipationAmount, + price + }, contractAddress, + contractName + } = info + resolve({ + contractName, + contractAddress, + contractType, + contractSubtype, + status, + expiryTime, + payeeAddress, + userChoices, + token: tokenIdentification, + acceptingToken, + sellingToken, + participationFees: contractAmount, + minimumsubscriptionamount, + maximumsubscriptionamount, + numberOfDeposits, + numberOfParticipants, + priceType, + oracle_address, + totalHonorAmount, + totalParticipationAmount, + price + }) + }).catch(error => { + reject(error) + }) + }) + } function getScDetails(name, address) { return floGlobals.smartContracts[floGlobals.scMap.get(`${name}_${address}`)] || {} @@ -2814,7 +2817,7 @@ function updatePrice(e) { const selectedSmartContract = document.getElementById('selected_smart_contract').value const [contractName, contractAddress] = (selectedSmartContract).split('_') - const oraclePrivateKey = document.getElementById('oracle_private_key').value + const oraclePrivateKey = document.getElementById('oracle_private_key').value.trim() const oracleAddress = document.getElementById('oracle_address').value if (!floCrypto.verifyPrivKey(oraclePrivateKey, oracleAddress)) { return notify(`Private key doesn't match with Oracle address`, 'error') @@ -2844,6 +2847,39 @@ }) } + function triggerContract(e) { + const selectedSmartContract = document.getElementById('selected_smart_contract').value + const [contractName, contractAddress] = (selectedSmartContract).split('_') + const triggerPrivateKey = document.getElementById('trigger_private_key').value.trim() + const triggerAddress = floCrypto.getFloID(triggerPrivateKey) + const triggerOutcome = getRef('smart_contract_trigger_form').querySelector('input[name="outcome"]:checked').value + const floData = `${contractName}@ triggerCondition:"${triggerOutcome}"` + console.log(floData) + if (contractAddress !== triggerAddress) { + return notify(`Private key doesn't match with contract trigger address`, 'error') + } + getConfirmation('Trigger contract', { + message: `Triggering ${contractName} with outcome: ${triggerOutcome}`, + confirmText: 'Trigger', + cancelText: 'Cancel' + }).then((res) => { + if (!res) return + buttonLoader('trigger_contract_button', true) + floBlockchainAPI.writeData(contractAddress, floData, triggerPrivateKey, contractAddress).then((txid) => { + showTransactionResult(true, txid, { + title: 'Contract trigger initiated', + }) + getRef('smart_contract_trigger_form').reset() + document.getElementById('trigger_contract_button').disabled = true + }).catch((error) => { + showTransactionResult(false, error) + console.error(error) + }).finally(() => { + buttonLoader('trigger_contract_button', false) + }) + }) + } + function handlePriceTypeChange(e) { switch (e.target.value) { case 'static':