Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/api/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ export async function approveAsset(assetLabel, spenderName) {
getAllowance(assetLabel, spenderName);
return true;
}
return false;
} catch(e) {
if (e?.code === 4001 || e?.code === 'ACTION_REJECTED' || e?.error?.code === 4001) return false;
showError(e);
return false;
}
}
}
13 changes: 10 additions & 3 deletions src/components/modals/StakeCAP.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { focusInput, hideModal } from '@lib/ui'
import LabelValue from '../layout/LabelValue.svelte'

let amount, isSubmitting, walletBalance = "0.0";
let amount, isSubmitting, isApproving, walletBalance = "0.0";

$: formattedWalletBalance = formatCAPForDisplay(walletBalance);

Expand All @@ -35,7 +35,14 @@
}

async function _approveAsset() {
const result = await approveAsset('CAP', 'FundStore');
if (!amount) return focusInput('Amount');
isApproving = true;
try {
const result = await approveAsset('CAP', 'FundStore');
if (result) await checkAllowance();
} finally {
isApproving = false;
}
}

async function getBalance() {
Expand Down Expand Up @@ -75,7 +82,7 @@

<div>
{#if $allowances['CAP']?.['FundStore'] * 1 <= amount * 1}
<Button noSubmit={true} label={`Approve CAP`} on:click={_approveAsset} />
<Button noSubmit={true} isLoading={isApproving} label={`Approve CAP`} on:click={_approveAsset} />
{:else}
<Button isLoading={isSubmitting} label={`Stake`} />
{/if}
Expand Down