more updates

enumerate
lza_menace 2 years ago
parent ca43da584c
commit a42756fcd1

@ -8,7 +8,7 @@
let errorMessage = ''; let errorMessage = '';
let successMessage = ''; let successMessage = '';
let contractAddress = ''; let contractAddress = '';
let contractApproved = false; let contractApproved = true;
let checked = false; let checked = false;
let selectedStandard = 1; let selectedStandard = 1;
let tokenStandards = [ let tokenStandards = [
@ -27,35 +27,34 @@
// evm.attachContract('nft', contractAddress, IERC721.abi); // evm.attachContract('nft', contractAddress, IERC721.abi);
// evm.attachContract('sendit', sendit, SendIt.abi); // evm.attachContract('sendit', sendit, SendIt.abi);
const approveSendIt = async () => {
await $contracts.nft.methods.setApprovalForAll(sendit, true).send({from: $selectedAccount});
}
const performCheck = async () => { const performCheck = async () => {
let tokenIds = []; let tokenIds = [];
errorMessage = ''; errorMessage = '';
// Check the contract is valid // Determine ABI
try {
$web3.utils.toChecksumAddress(contractAddress)
} catch {
errorMessage = 'Invalid contract address supplied';
return;
}
// Check approval on the contract
if (selectedStandard == 1) { if (selectedStandard == 1) {
evm.attachContract('nft', contractAddress, IERC721.abi); evm.attachContract('nft', contractAddress, IERC721.abi);
} else { } else {
evm.attachContract('nft', contractAddress, IERC1155.abi); evm.attachContract('nft', contractAddress, IERC1155.abi);
} }
// Check the contract is valid
try { try {
let r = await $contracts.nft.methods.isApprovedForAll($selectedAccount, sendit); $web3.utils.toChecksumAddress(contractAddress)
console.log(r);
} catch { } catch {
errorMessage = 'Unable to check contract approvals'; errorMessage = 'Invalid contract address supplied';
return; return;
} }
// Check textarea syntax // Check textarea syntax
let info = document.getElementById('recipientInfo').value; let info = document.getElementById('recipientInfo').value;
let lines = info.split(/(\s+)/); let lines = info.split(/(\s+)/);
console.log(lines);
if (lines.length < 2) { errorMessage = 'Invalid recipient info.'; return; } if (lines.length < 2) { errorMessage = 'Invalid recipient info.'; return; }
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
let line = lines[i].split(','); let line = lines[i].split(',');
@ -68,6 +67,7 @@
errorMessage = `Invalid recipient address supplied (line ${i + 1})`; errorMessage = `Invalid recipient address supplied (line ${i + 1})`;
return; return;
} }
// Check ownership of tokens // Check ownership of tokens
if (selectedStandard == 1) { if (selectedStandard == 1) {
try { 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 // Check gas consumption forecasts
// Show results // Show results
@ -133,6 +146,7 @@
</script> </script>
{#if $selectedAccount} {#if $selectedAccount}
<form> <form>
<div class="row"> <div class="row">
@ -160,6 +174,9 @@
{:else} {:else}
<input class="button" type="submit" value="Check" on:click|preventDefault={performCheck}> <input class="button" type="submit" value="Check" on:click|preventDefault={performCheck}>
{/if} {/if}
{#if !contractApproved}
<button class="button-primary" on:click|preventDefault={approveSendIt}>Approve</button>
{/if}
</form> </form>
{/if} {/if}

Loading…
Cancel
Save