From c967fa224995f8170030b9bbaa2e7df8d79224b5 Mon Sep 17 00:00:00 2001 From: apporc Date: Sat, 22 Jun 2024 11:17:27 +0800 Subject: [PATCH] Support REX stake/unstake --- src/abi-types.ts | 18 + src/app.svelte | 4 + .../elements/input/token/selector.svelte | 1 - .../elements/input/token/selector/row.svelte | 8 +- src/components/elements/slider.svelte | 308 ++++++++++++++++++ src/components/layout/navigation/index.svelte | 6 + src/pages/earn/components/label.svelte | 53 +++ src/pages/earn/components/progress.svelte | 27 ++ src/pages/earn/index.svelte | 270 +++++++++++++++ src/pages/earn/step/bootstrap.svelte | 124 +++++++ src/pages/earn/step/confirm.svelte | 128 ++++++++ src/pages/earn/step/error.svelte | 59 ++++ src/pages/earn/step/overview.svelte | 126 +++++++ src/pages/earn/step/stake.svelte | 116 +++++++ src/pages/earn/step/unstake.svelte | 126 +++++++ src/pages/earn/types.ts | 9 + 16 files changed, 1381 insertions(+), 2 deletions(-) create mode 100644 src/components/elements/slider.svelte create mode 100644 src/pages/earn/components/label.svelte create mode 100644 src/pages/earn/components/progress.svelte create mode 100644 src/pages/earn/index.svelte create mode 100644 src/pages/earn/step/bootstrap.svelte create mode 100644 src/pages/earn/step/confirm.svelte create mode 100644 src/pages/earn/step/error.svelte create mode 100644 src/pages/earn/step/overview.svelte create mode 100644 src/pages/earn/step/stake.svelte create mode 100644 src/pages/earn/step/unstake.svelte create mode 100644 src/pages/earn/types.ts diff --git a/src/abi-types.ts b/src/abi-types.ts index 7770a8fa..309d40c5 100644 --- a/src/abi-types.ts +++ b/src/abi-types.ts @@ -121,6 +121,24 @@ export class REXDeposit extends Struct { @Struct.field('asset') amount!: Asset } +@Struct.type('rexwithdraw') +export class REXWithdraw extends Struct { + @Struct.field('name') owner!: Name + @Struct.field('asset') amount!: Asset +} + +@Struct.type('rexbuyrex') +export class REXBUYREX extends Struct { + @Struct.field('name') from!: Name + @Struct.field('asset') amount!: Asset +} + +@Struct.type('rexsellrex') +export class REXSELLREX extends Struct { + @Struct.field('name') from!: Name + @Struct.field('asset') rex!: Asset +} + @Struct.type('rexrentcpu') export class REXRentCPU extends Struct { @Struct.field('name') from!: Name diff --git a/src/app.svelte b/src/app.svelte index b6c8a310..3533c14d 100644 --- a/src/app.svelte +++ b/src/app.svelte @@ -8,6 +8,7 @@ import Login from '~/pages/login.svelte' import Dashboard from '~/pages/dashboard/index.svelte' + import Earn from '~/pages/earn/index.svelte' import Request from '~/pages/request/index.svelte' import Send from '~/pages/send/index.svelte' import TokensPurchase from '~/pages/tokens/purchase/index.svelte' @@ -178,6 +179,9 @@ + + + diff --git a/src/components/elements/input/token/selector.svelte b/src/components/elements/input/token/selector.svelte index ddf1bedf..e66d60cc 100644 --- a/src/components/elements/input/token/selector.svelte +++ b/src/components/elements/input/token/selector.svelte @@ -1,6 +1,5 @@ + + + + +
+
+
+
+
(thumbHover = true)} + on:mouseout={() => (thumbHover = false)} + > + {#if holding || thumbHover} +
+ {value + ' %'} +
+ {/if} +
+
+
+
+ + + + diff --git a/src/components/layout/navigation/index.svelte b/src/components/layout/navigation/index.svelte index 4f77dd0c..8fc5816c 100644 --- a/src/components/layout/navigation/index.svelte +++ b/src/components/layout/navigation/index.svelte @@ -30,6 +30,12 @@ name: 'Transfer', path: '/transfer', }, + { + icon: 'battery-charging', + name: 'Earn', + path: '/earn', + }, + ...(banxaIsAvailable($activeBlockchain) ? [ { diff --git a/src/pages/earn/components/label.svelte b/src/pages/earn/components/label.svelte new file mode 100644 index 00000000..a0ad8cf6 --- /dev/null +++ b/src/pages/earn/components/label.svelte @@ -0,0 +1,53 @@ + + + + +
+
+

{header}

+ {#if subheader} +

{subheader}

+ {/if} +
+ +
+ +
+ {#if changeStep} +
+ +
+ {/if} +
diff --git a/src/pages/earn/components/progress.svelte b/src/pages/earn/components/progress.svelte new file mode 100644 index 00000000..c277f404 --- /dev/null +++ b/src/pages/earn/components/progress.svelte @@ -0,0 +1,27 @@ + + + + +
+
+
+
diff --git a/src/pages/earn/index.svelte b/src/pages/earn/index.svelte new file mode 100644 index 00000000..e55c8a48 --- /dev/null +++ b/src/pages/earn/index.svelte @@ -0,0 +1,270 @@ + + + + + + + {#if $step === Step.Error} + switchStep($defaultStep)} /> + {:else if $step === Step.Bootstrap} + toStakeConfirm(Step.Bootstrap)} + /> + {:else if $step === Step.Overview} + switchStep(Step.Stake)} + toUnstake={() => switchStep(Step.Unstake)} + /> + {:else if $step === Step.Stake} + toStakeConfirm(Step.Stake)} + /> + {:else if $step === Step.Unstake} + toStakeConfirm(Step.Unstake)} + /> + {:else if $step === Step.Confirm} + + {/if} + + diff --git a/src/pages/earn/step/bootstrap.svelte b/src/pages/earn/step/bootstrap.svelte new file mode 100644 index 00000000..5d44e0bb --- /dev/null +++ b/src/pages/earn/step/bootstrap.svelte @@ -0,0 +1,124 @@ + + + + +
+
+
How to Earn
+
Earn by staking
+
+
+
+
+ selected amount to stake + + +
+ +
+ +
+
+
+
diff --git a/src/pages/earn/step/confirm.svelte b/src/pages/earn/step/confirm.svelte new file mode 100644 index 00000000..3af52a39 --- /dev/null +++ b/src/pages/earn/step/confirm.svelte @@ -0,0 +1,128 @@ + + + + +
+
+
{action}
+
Review and sign
+ +
+
+ + {action} + + +
+ + + + {amount.value} +
+ {#if usd} +
≈ $ {usd} USD
+ {/if} +
+
+
+ +
+
diff --git a/src/pages/earn/step/error.svelte b/src/pages/earn/step/error.svelte new file mode 100644 index 00000000..7db1791c --- /dev/null +++ b/src/pages/earn/step/error.svelte @@ -0,0 +1,59 @@ + + + + +
+
+

Transfer Failed

+
+ +
+

+ {error} +

+
+ +
+ +
+
diff --git a/src/pages/earn/step/overview.svelte b/src/pages/earn/step/overview.svelte new file mode 100644 index 00000000..097b7430 --- /dev/null +++ b/src/pages/earn/step/overview.svelte @@ -0,0 +1,126 @@ + + + + +
+
+
How to Earn
+
Earn by staking
+
+
+
+
currently staked balance
+
+ {rexBalance} +
+
+ + +
+
+
+
+
diff --git a/src/pages/earn/step/stake.svelte b/src/pages/earn/step/stake.svelte new file mode 100644 index 00000000..2dda38fe --- /dev/null +++ b/src/pages/earn/step/stake.svelte @@ -0,0 +1,116 @@ + + + + +
+
+
Stake
+
Add to your staked balance
+ +
+
+
+ amount to stake +
+ {}} /> +
+ + +
+
+ +
+
diff --git a/src/pages/earn/step/unstake.svelte b/src/pages/earn/step/unstake.svelte new file mode 100644 index 00000000..ff6378a2 --- /dev/null +++ b/src/pages/earn/step/unstake.svelte @@ -0,0 +1,126 @@ + + + + +
+
+
Unstake
+
Remove from your staked balance
+ +
+
+
+ amount to unstake +
+ {}} + /> +
+ + +
+
+ +
+
diff --git a/src/pages/earn/types.ts b/src/pages/earn/types.ts new file mode 100644 index 00000000..ef219601 --- /dev/null +++ b/src/pages/earn/types.ts @@ -0,0 +1,9 @@ +export const enum Step { + Bootstrap, + Overview, + Stake, + Unstake, + Confirm, + Success, + Error, +}