ux improve

enumerate
lza_menace 2 years ago
parent 38563d7b69
commit fb308aedca

@ -12,6 +12,7 @@
let contractApproved = true; let contractApproved = true;
let checked = false; let checked = false;
let checksPending = false; let checksPending = false;
let transferPending = false;
let gasCalculation = []; let gasCalculation = [];
let selectedStandard = 1; let selectedStandard = 1;
let gasPrice = 0; let gasPrice = 0;
@ -36,14 +37,17 @@
} }
const approveShipIt = async () => { const approveShipIt = async () => {
await $contracts.nft.methods.setApprovalForAll(shipit, true).send({from: $selectedAccount}); try {
await $contracts.nft.methods.setApprovalForAll(shipit, true).send({from: $selectedAccount});
contractApproved = true;
} catch(e) {
errorMessage = `Failed to approve contract: ${e.message}`;
return;
}
} }
const isApproved = async () => { const isApproved = async () => {
return await $contracts.nft.methods.isApprovedForAll($selectedAccount, shipit).call({from: $selectedAccount}); return await $contracts.nft.methods.isApprovedForAll($selectedAccount, shipit).call({from: $selectedAccount});
// if (!i) {
// await $contracts.nft.methods.setApprovalForAll(shipit, true).send({from: $selectedAccount});
// }
} }
const performCheck = async () => { const performCheck = async () => {
@ -120,7 +124,7 @@
try { try {
let approved = await $contracts.nft.methods.isApprovedForAll($selectedAccount, shipit).call(); let approved = await $contracts.nft.methods.isApprovedForAll($selectedAccount, shipit).call();
if (!approved) { if (!approved) {
errorMessage = 'ShipIt requires approval to bulk transfer tokens; click the "Approve" button below'; errorMessage = 'ShipIt requires approval to bulk transfer tokens; click the "Approve" button to view gas estimations and savings';
checksPending = false; checksPending = false;
contractApproved = false; contractApproved = false;
return; return;
@ -173,21 +177,34 @@
async function executeTransfer() { async function executeTransfer() {
console.log('executing transfer') console.log('executing transfer')
let fee = await $contracts.shipit.methods.usageFee().call(); let fee = await $contracts.shipit.methods.usageFee().call();
if (isERC1155) { let res;
let {new_addr, new_token, new_amount} = deriveTokenTotals(); transferPending = true;
await $contracts.shipit.methods.erc1155BulkTransfer(contractAddress, new_addr, new_token, new_amount).send({ try {
from: $selectedAccount, if (isERC1155) {
value: fee * recipients.length, let {new_addr, new_token, new_amount} = deriveTokenTotals();
gasPrice: gasPrice, res = await $contracts.shipit.methods.erc1155BulkTransfer(contractAddress, new_addr, new_token, new_amount).send({
gas: si_gasLimit from: $selectedAccount,
}); value: fee * recipients.length,
} else { gasPrice: gasPrice,
await $contracts.shipit.methods.erc721BulkTransfer(contractAddress, recipients, tokenIds).send({ gas: si_gasLimit
from: $selectedAccount, });
value: fee * recipients.length, } else {
gasPrice: gasPrice, res = await $contracts.shipit.methods.erc721BulkTransfer(contractAddress, recipients, tokenIds).send({
gas: si_gasLimit from: $selectedAccount,
}); value: fee * recipients.length,
gasPrice: gasPrice,
gas: si_gasLimit
});
}
if (res.status) {
successMessage = `Success! <a target=_blank href="https://etherscan.io/tx/${res.transactionHash}">View Tx</a>`;
} else {
// $('#mintMessage').html(`Failed. ${res}`);
throw new Error(`Transaction failed: ${res}`)
}
} catch(e) {
errorMessage = `Failed to execute bulk transfer: ${e.message}`;
transferPending = false;
} }
} }
@ -264,7 +281,9 @@
0x653D2d1D10c79017b2eA5F5a6F02D9Ab6e725395,1775" id="recipientInfo" on:change={clearMessages}></textarea> 0x653D2d1D10c79017b2eA5F5a6F02D9Ab6e725395,1775" id="recipientInfo" on:change={clearMessages}></textarea>
<br /> <br />
{#if checked} {#if checked}
<input class="button-primary" type="submit" value="Transfer" on:click|preventDefault={executeTransfer}> <button class="button-primary" disabled={transferPending} on:click|preventDefault={executeTransfer}>
{#if transferPending}executing...{:else}Transfer{/if}
</button>
{:else} {:else}
<button class="button" disabled={checksPending} on:click|preventDefault={performCheck}> <button class="button" disabled={checksPending} on:click|preventDefault={performCheck}>
{#if checksPending}checking...{:else}Check{/if} {#if checksPending}checking...{:else}Check{/if}
@ -289,7 +308,7 @@
<p class="errorMessage">{errorMessage}</p> <p class="errorMessage">{errorMessage}</p>
{/if} {/if}
{#if errorMessage} {#if successMessage}
<p class="successMessage">{successMessage}</p> <p class="successMessage">{successMessage}</p>
{/if} {/if}
{/if} {/if}

Loading…
Cancel
Save