From a42756fcd1ada74f9ed5bba68a6f1b7424abb030 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Fri, 18 Nov 2022 00:01:21 -0800 Subject: [PATCH] more updates --- src/Contracts.svelte | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/src/Contracts.svelte b/src/Contracts.svelte index 4be1c65..e30b0e4 100644 --- a/src/Contracts.svelte +++ b/src/Contracts.svelte @@ -8,7 +8,7 @@ let errorMessage = ''; let successMessage = ''; let contractAddress = ''; - let contractApproved = false; + let contractApproved = true; let checked = false; let selectedStandard = 1; let tokenStandards = [ @@ -27,35 +27,34 @@ // evm.attachContract('nft', contractAddress, IERC721.abi); // evm.attachContract('sendit', sendit, SendIt.abi); + const approveSendIt = async () => { + await $contracts.nft.methods.setApprovalForAll(sendit, true).send({from: $selectedAccount}); + } + const performCheck = async () => { let tokenIds = []; errorMessage = ''; - // Check the contract is valid - try { - $web3.utils.toChecksumAddress(contractAddress) - } catch { - errorMessage = 'Invalid contract address supplied'; - return; - } - // Check approval on the contract + // Determine ABI if (selectedStandard == 1) { evm.attachContract('nft', contractAddress, IERC721.abi); } else { evm.attachContract('nft', contractAddress, IERC1155.abi); } + + // Check the contract is valid try { - let r = await $contracts.nft.methods.isApprovedForAll($selectedAccount, sendit); - console.log(r); + $web3.utils.toChecksumAddress(contractAddress) } catch { - errorMessage = 'Unable to check contract approvals'; + errorMessage = 'Invalid contract address supplied'; return; } + + // Check textarea syntax let info = document.getElementById('recipientInfo').value; let lines = info.split(/(\s+)/); - console.log(lines); if (lines.length < 2) { errorMessage = 'Invalid recipient info.'; return; } for (let i = 0; i < lines.length; i++) { let line = lines[i].split(','); @@ -68,6 +67,7 @@ errorMessage = `Invalid recipient address supplied (line ${i + 1})`; return; } + // Check ownership of tokens if (selectedStandard == 1) { try { @@ -94,6 +94,19 @@ } } + + // Check approval on the contract + try { + let approved = await $contracts.nft.methods.isApprovedForAll($selectedAccount, sendit).call(); + if (!approved) { + errorMessage = 'SendIt requires approval to bulk transfer tokens; click the "Approve" button below'; + contractApproved = false; + return; + } + } catch { + errorMessage = 'Unable to check contract approvals'; + return; + } // Check gas consumption forecasts // Show results @@ -133,6 +146,7 @@ + {#if $selectedAccount}
@@ -160,6 +174,9 @@ {:else} {/if} + {#if !contractApproved} + + {/if} {/if}