adding enumeration

enumerate
lza_menace 2 years ago
parent c80bb2fe9a
commit efd89e3309

@ -3,8 +3,10 @@
import { cubicOut } from 'svelte/easing'; import { cubicOut } from 'svelte/easing';
import { defaultEvmStores as evm, selectedAccount, contracts, web3 } from 'svelte-web3'; import { defaultEvmStores as evm, selectedAccount, contracts, web3 } from 'svelte-web3';
import IERC721 from '@openzeppelin/contracts/build/contracts/IERC721.json'; import IERC721 from '@openzeppelin/contracts/build/contracts/IERC721.json';
import IERC721Enumerable from '@openzeppelin/contracts/build/contracts/IERC721Enumerable.json';
import IERC1155 from '@openzeppelin/contracts/build/contracts/IERC1155.json'; import IERC1155 from '@openzeppelin/contracts/build/contracts/IERC1155.json';
import ShipIt from './lib/shipit.json'; import ShipIt from './lib/shipit.json';
import Providers from './Providers.svelte';
const progress = tweened(0, { const progress = tweened(0, {
duration: 800, duration: 800,
@ -27,7 +29,9 @@
let approvalRequired = false; let approvalRequired = false;
let revokeRequired = false; let revokeRequired = false;
let revokePending = false; let revokePending = false;
let enumeratePending = false;
let gasCalculation = []; let gasCalculation = [];
let enumeratedTokens = [];
let selectedStandard = 1; let selectedStandard = 1;
let gasPrice = 0; let gasPrice = 0;
let gasLimit = 0; let gasLimit = 0;
@ -50,6 +54,27 @@
successMessage = ''; successMessage = '';
} }
function setupContracts() {
if (selectedStandard == 1) {
evm.attachContract('nft', contractAddress, IERC721.abi);
evm.attachContract('nftenum', contractAddress, IERC721Enumerable.abi);
} else {
evm.attachContract('nft', contractAddress, IERC1155.abi);
isERC1155 = true;
}
}
const enumerateTokens = async () => {
enumeratePending = true;
setupContracts();
let bal = await $contracts.nftenum.methods.balanceOf($selectedAccount).call();
for(let i = 0; i < bal; i++) {
let tokenId = await $contracts.nftenum.methods.tokenOfOwnerByIndex($selectedAccount, i);
enumeratedTokens.push(tokenId);
}
enumeratePending = false;
}
const approveShipIt = async () => { const approveShipIt = async () => {
try { try {
approvalPending = true; approvalPending = true;
@ -91,14 +116,7 @@
isERC1155 = false; isERC1155 = false;
checksPending = true; checksPending = true;
errorMessage = ''; errorMessage = '';
setupContracts();
// Determine ABI
if (selectedStandard == 1) {
evm.attachContract('nft', contractAddress, IERC721.abi);
} else {
evm.attachContract('nft', contractAddress, IERC1155.abi);
isERC1155 = true;
}
// Check the contract is valid // Check the contract is valid
try { try {
@ -321,11 +339,19 @@
{#if $selectedAccount} {#if $selectedAccount}
<form> <form>
<div class="row"> <div class="row">
<div class="eight columns"> <div class="six columns">
<label for="contractAddress">Contract Address</label> <label for="contractAddress">Contract Address</label>
<input class="u-full-width" type="text" placeholder="0x..." id="contractAddress" bind:value={contractAddress}> <input class="u-full-width" type="text" placeholder="0x..." id="contractAddress" bind:value={contractAddress}>
</div> </div>
<div class="four columns"> {#if contractAddress}
<div class="two columns">
<label for="findTokens">Enumerate</label>
<button id="findTokens" class="button" disabled={enumeratePending} on:click|preventDefault={enumerateTokens}>
{#if enumeratePending}finding...{:else}Find Tokens{/if}
</button>
</div>
{/if}
<div class="two columns">
<label for="tokenStandard">Token Standard</label> <label for="tokenStandard">Token Standard</label>
<select class="u-full-width" id="tokenStandard" bind:value={selectedStandard} on:change={clearMessages}> <select class="u-full-width" id="tokenStandard" bind:value={selectedStandard} on:change={clearMessages}>
{#each tokenStandards as s} {#each tokenStandards as s}
@ -387,6 +413,14 @@
{#if successMessage} {#if successMessage}
<p class="successMessage">{successMessage}</p> <p class="successMessage">{successMessage}</p>
{/if} {/if}
{#if enumeratedTokens.length > 0}
<p>Found the {enumeratedTokens.length} tokens owned by {$selectedAccount}:</p>
<ul>
{#each enumeratedTokens as t, i}
<li>{t}</li>
{/each}
</ul>
{/if}
</div> </div>
</div> </div>
{/if} {/if}

Loading…
Cancel
Save