Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Add withdraw button #116

Merged
merged 1 commit into from
Jun 1, 2022
Merged
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
29 changes: 28 additions & 1 deletion src/lib/components/BalanceButton.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { fly } from 'svelte/transition';
import Button from 'radicle-design-system/Button.svelte';
import TopUpIcon from 'radicle-design-system/icons/Topup.svelte';
import InfoCircle from 'radicle-design-system/icons/InfoCircle.svelte';

import drips from '$lib/stores/drips';
Expand All @@ -16,6 +17,21 @@
$: withdrawable =
$drips.collectable && currencyFormat($drips.collectable.wei);
let hover = false;

let txInFlight = false;
$: collectBlocked =
$drips.collectable === undefined ||
$drips.collectable?.wei === BigInt(0) ||
txInFlight;

async function collect() {
txInFlight = true;
try {
await drips.collect();
} finally {
txInFlight = false;
}
}
</script>

<div
Expand Down Expand Up @@ -47,7 +63,7 @@
</h2>
</div>
<div class="title-value balance">
<p class="typo-text title">Current balance</p>
<p class="typo-text title">Total earned</p>
<h2 class="value">
{#if estimate}
{padFloatString(estimate)} DAI
Expand All @@ -74,6 +90,13 @@
{/if}
</p>
</div>
{#if withdrawable}
<div class="actions">
<Button disabled={collectBlocked} icon={TopUpIcon} on:click={collect}
>Withdraw {withdrawable} DAI</Button
>
</div>
{/if}
</div>
{/if}
</div>
Expand All @@ -87,6 +110,10 @@
flex-direction: column;
}

.actions {
width: fit-content;
}

.hover-pad {
position: absolute;
top: 2rem;
Expand Down
17 changes: 16 additions & 1 deletion src/lib/stores/drips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,20 @@ export default (() => {
};
}

async function collect() {
const { provider } = get(internal);

const daiDripsHubAddress = daiDripsHubInfo(
provider.network.chainId
).address;
const contract = DaiDripsHubAbi__factory.connect(
daiDripsHubAddress,
provider.getSigner()
);

return contract.collect(await provider.getSigner().getAddress(), []);
}

return {
subscribe: state.subscribe,
connect,
Expand All @@ -206,6 +220,7 @@ export default (() => {
getDripsUpdatedEvents,
getAllowance,
getDaiBalance,
approveDaiSpend
approveDaiSpend,
collect
};
})();