From 2ebea4bc2bb0c848fce7bda2b46aa9289e507e1a Mon Sep 17 00:00:00 2001 From: Ignacio Date: Wed, 28 Feb 2024 15:45:13 +0800 Subject: [PATCH] feat: add modal button on logged in --- README.md | 4 + src/app/page.tsx | 2 +- src/features/staking/components/logged-in.tsx | 74 +++++++++++++------ src/features/staking/context/actions.ts | 26 +++++-- src/features/staking/context/hooks.ts | 4 +- src/features/staking/lib/core/base.ts | 25 +++++++ src/features/staking/lib/core/coins.ts | 3 +- 7 files changed, 105 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index e69de29..d484211 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,4 @@ +# Xion Staking + +A proof of concept application to stake tokens in Xion, using the native +authentication via the dashboard. diff --git a/src/app/page.tsx b/src/app/page.tsx index 1f5bf74..a7a0058 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,5 +1,5 @@ import StakingPage from "@/features/staking/components/page"; -export default function Page(): JSX.Element { +export default function Page() { return ; } diff --git a/src/features/staking/components/logged-in.tsx b/src/features/staking/components/logged-in.tsx index a2bfa36..38b3903 100644 --- a/src/features/staking/components/logged-in.tsx +++ b/src/features/staking/components/logged-in.tsx @@ -1,16 +1,17 @@ "use client"; -import { useAbstraxionSigningClient } from "@burnt-labs/abstraxion"; +import { useAbstraxionSigningClient, useModal } from "@burnt-labs/abstraxion"; import { Button } from "@burnt-labs/ui"; import type { Validator } from "cosmjs-types/cosmos/staking/v1beta1/staking"; import Link from "next/link"; -import { memo, useState } from "react"; +import { memo, useMemo, useState } from "react"; import type { StakingState } from "../context"; import { claimRewardsAction, - stakeValidator, - unstakeValidator, + setRedelegateAction, + stakeValidatorAction, + unstakeValidatorAction, } from "../context/actions"; import { useStaking } from "../context/hooks"; import type { StakeAddresses } from "../lib/core/base"; @@ -58,16 +59,20 @@ function StakingPage() { const [isLoading, setIsLoading] = useState(false); const { delegations, tokens, unbondings, validators } = staking.state; const { client } = useAbstraxionSigningClient(); - - const validatorsMap: Record = - validators?.items.reduce>( - (acc, validator) => { - acc[validator.operatorAddress] = validator; - - return acc; - }, - {}, - ) || {}; + const [, setShowAbstraxion] = useModal(); + + const validatorsMap: Record = useMemo( + () => + validators?.items.reduce>( + (acc, validator) => { + acc[validator.operatorAddress] = validator; + + return acc; + }, + {}, + ) || {}, + [validators], + ); return ( <> @@ -76,6 +81,15 @@ function StakingPage() {
{account.bech32Address}
+
+ +
{tokens && (
Tokens: {formatCoin(tokens)} @@ -112,11 +126,13 @@ function StakingPage() { validator: validator.operatorAddress, }; - unstakeValidator(addresses, client, staking).finally( - () => { - setIsLoading(false); - }, - ); + unstakeValidatorAction( + addresses, + client, + staking, + ).finally(() => { + setIsLoading(false); + }); }} > Undelegate @@ -147,7 +163,17 @@ function StakingPage() {