add revoke, improve ux

enumerate
lza_menace 2 years ago
parent 6188cd5850
commit 8f058ead66

@ -1,4 +1,5 @@
<script> <script>
import { writable } from 'svelte/store';
import { tweened } from 'svelte/motion'; import { tweened } from 'svelte/motion';
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';
@ -10,7 +11,7 @@
duration: 800, duration: 800,
easing: cubicOut easing: cubicOut
}); });
const shipit = '0x76Ae5B6E75F6e05BcaD1028F78A83f974fc96A8B'; const shipit = '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0';
let errorMessage = ''; let errorMessage = '';
let successMessage = ''; let successMessage = '';
let contractAddress = ''; let contractAddress = '';
@ -63,6 +64,9 @@
revokePending = true; revokePending = true;
await $contracts.nft.methods.setApprovalForAll(shipit, false).send({from: $selectedAccount}); await $contracts.nft.methods.setApprovalForAll(shipit, false).send({from: $selectedAccount});
contractApproved = false; contractApproved = false;
approvalRequired = false;
revokeRequired = false;
clearMessages();
} catch(e) { } catch(e) {
errorMessage = `Failed to revoke contract: ${e.message}`; errorMessage = `Failed to revoke contract: ${e.message}`;
revokePending = false; revokePending = false;
@ -114,6 +118,7 @@
} catch { } catch {
errorMessage = `Invalid recipient address supplied (line ${i + 1})`; errorMessage = `Invalid recipient address supplied (line ${i + 1})`;
checksPending = false; checksPending = false;
return; return;
} }
@ -161,6 +166,8 @@
checksPending = false; checksPending = false;
contractApproved = false; contractApproved = false;
return; return;
} else {
approvalRequired = false;
} }
} catch { } catch {
errorMessage = 'Unable to check contract approvals'; errorMessage = 'Unable to check contract approvals';
@ -172,6 +179,7 @@
await estimateGas(); await estimateGas();
checked = true; checked = true;
revokeRequired = true;
window.scrollTo(0, document.body.scrollHeight); window.scrollTo(0, document.body.scrollHeight);
} }
@ -312,32 +320,38 @@
<label for="recipientInfo">Recipient Address, Token ID</label> <label for="recipientInfo">Recipient Address, Token ID</label>
<textarea class="u-full-width" style="height: 10em;" placeholder="0x653D2d1D10c79017b2eA5F5a6F02D9Ab6e725395,90 <textarea class="u-full-width" style="height: 10em;" placeholder="0x653D2d1D10c79017b2eA5F5a6F02D9Ab6e725395,90
0x653D2d1D10c79017b2eA5F5a6F02D9Ab6e725395,1775" id="recipientInfo" on:change={clearMessages}></textarea> 0x653D2d1D10c79017b2eA5F5a6F02D9Ab6e725395,1775" id="recipientInfo" on:change={clearMessages}></textarea>
<br /> <div class="row">
{#if checked} <div class="six columns">
<button class="button-primary" disabled={transferPending} on:click|preventDefault={executeTransfer}> {#if revokeRequired}
{#if transferPending}executing...{:else}Transfer{/if} <button class="button-fail" disabled={revokePending} on:click|preventDefault={revokeShipIt}>
</button> {#if revokePending}revoking...{:else}Revoke{/if}
{:else} </button>
<button class="button" disabled={checksPending} on:click|preventDefault={performCheck}> {/if}
{#if checksPending}checking...{:else}Check{/if} {#if approvalRequired}
</button> <button class="button-primary" disabled={approvalPending} on:click|preventDefault={approveShipIt}>
{/if} {#if approvalPending}pending...{:else}Approve{/if}
{#if revokeRequired} </button>
<button class="button-primary" disabled={revokePending} on:click|preventDefault={revokeShipIt}> {/if}
{#if revokePending}revoking...{:else}Revoke{/if} {#if checked}
</button> <button class="button-primary" disabled={transferPending} on:click|preventDefault={executeTransfer}>
{/if} {#if transferPending}executing...{:else}Transfer{/if}
{#if approvalRequired} </button>
<button class="button-primary" disabled={approvalPending} on:click|preventDefault={approveShipIt}> {:else}
{#if approvalPending}pending...{:else}Approve{/if} <button class="button" disabled={checksPending} on:click|preventDefault={performCheck}>
</button> {#if checksPending}checking...{:else}Check{/if}
{/if} </button>
{/if}
</div>
<div class="six columns">
{#if $progress > 0 && $progress < 1}
<progress value={$progress}></progress>
{/if}
</div>
</div>
</form> </form>
<div class="row"> <div class="row">
<div class="twelve columns"> <div class="twelve columns">
{#if $progress > 0 && $progress < 1} {#if gasCalculation.length > 0}
<progress value={$progress}></progress>
{/if}
<ul> <ul>
{#each gasCalculation as m, i} {#each gasCalculation as m, i}
{#if i == 3} {#if i == 3}
@ -347,6 +361,7 @@
{/if} {/if}
{/each} {/each}
</ul> </ul>
{/if}
{#if errorMessage} {#if errorMessage}
<p class="errorMessage">{errorMessage}</p> <p class="errorMessage">{errorMessage}</p>
{/if} {/if}
@ -363,9 +378,27 @@
.successMessage { .successMessage {
color: green; color: green;
} }
.button-fail {
background-color: rgba(244, 67, 54, .75);
border-color: rgba(244, 67, 54, .75);
color: white;
}
.button-fail:disabled {
background-color: rgba(244, 67, 54, .5);
border: 1px solid rgba(244, 67, 54, .5);
}
.button-primary:disabled {
background-color: rgba(51, 195, 240, .5);
border: 1px solid rgba(51, 195, 240, .5);
}
.button:disabled {
background-color: rgba(204, 204, 204, .5);
border: 1px solid rgba(204, 204, 204, .5);
}
progress { progress {
display: block; display: block;
width: 100%; width: 100%;
transition: transform 2s; transition: transform 2s;
height: 2em;
} }
</style> </style>
Loading…
Cancel
Save