Skip to content

Commit

Permalink
fix: add proxy and undelegate message
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Feb 27, 2024
1 parent 5ef0881 commit c31fdf5
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 41 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test
on: push
jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20

- run: yarn --immutable

- run: yarn lint
- run: yarn test
- run: yarn type-check
- run: yarn build
34 changes: 0 additions & 34 deletions .github/workflows/gh-pages.yml

This file was deleted.

8 changes: 6 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const nextConfig = {
basePath: "/xion-staking",
eslint: {
ignoreDuringBuilds: process.env.QUICK_BUILD === "true",
},
output: "export",
rewrites: async () => [
{
destination: "https://rpc.xion-testnet-1.burnt.com:443",
source: "/rpc",
},
],
typescript: {
ignoreBuildErrors: process.env.QUICK_BUILD === "true",
},
Expand Down
3 changes: 2 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@burnt-labs/ui/dist/index.css";
import { Inter } from "next/font/google";

import { StakingProvider } from "@/features/staking/context/provider";
import { dashboardUrl } from "@/features/staking/lib/constants";
import { dashboardUrl, rpcEndpoint } from "@/features/staking/lib/constants";

import "./globals.css";

Expand All @@ -15,6 +15,7 @@ const inter = Inter({ subsets: ["latin"] });
const abstraxionConfig = {
contracts: [],
dashboardUrl,
rpcUrl: rpcEndpoint,
stake: true,
};

Expand Down
15 changes: 14 additions & 1 deletion src/features/staking/components/logged-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Link from "next/link";
import { memo, useState } from "react";

import type { StakingState } from "../context";
import { stakeValidator } from "../context/actions";
import { stakeValidator, unstakeValidator } from "../context/actions";
import { useStaking } from "../context/hooks";
import { formatCoin } from "../lib/coins";
import { chainId } from "../lib/constants";
Expand Down Expand Up @@ -89,6 +89,19 @@ function StakingPage() {
<Button
onClick={() => {
setIsLoading(true);

if (!client) return;

setIsLoading(true);

const addresses: StakeAddresses = {
delegator: account.bech32Address,
validator: validator.operatorAddress,
};

unstakeValidator(addresses, client, staking).then(() => {
setIsLoading(false);
});
}}
>
Undelegate
Expand Down
14 changes: 14 additions & 0 deletions src/features/staking/context/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getDelegations,
getValidatorsList,
stakeAmount,
unstakeAmount,
} from "../lib/core";
import { addDelegations, setTokens, setValidators } from "./reducer";

Expand Down Expand Up @@ -51,3 +52,16 @@ export const stakeValidator = async (

await fetchStakingData(addressess.delegator, staking);
};

export const unstakeValidator = async (
addressess: StakeAddresses,
client: SigningClient,
staking: StakingContextType,
) => {
await unstakeAmount(addressess, client, {
amount: "1000",
denom: "uxion",
});

await fetchStakingData(addressess.delegator, staking);
};
5 changes: 4 additions & 1 deletion src/features/staking/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ export const { chainId } = testnetChainInfo;
export const dashboardUrl =
process.env.NODE_ENV === "production" ? undefined : "http://localhost:3000";

export const rpcEndpoint = "https://rpc.xion-testnet-1.burnt.com:443";
export const rpcEndpoint =
typeof window === "undefined"
? "https://rpc.xion-testnet-1.burnt.com:443"
: `${window.location.origin}/rpc`;
42 changes: 40 additions & 2 deletions src/features/staking/lib/core.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import type { useAbstraxionSigningClient } from "@burnt-labs/abstraxion";
import type { Coin, MsgDelegateEncodeObject, StdFee } from "@cosmjs/stargate";
import type {
Coin,
MsgDelegateEncodeObject,
MsgUndelegateEncodeObject,
StdFee,
} from "@cosmjs/stargate";
import {
QueryClient,
StargateClient,
setupStakingExtension,
} from "@cosmjs/stargate";
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
import {
MsgDelegate,
MsgUndelegate,
} from "cosmjs-types/cosmos/staking/v1beta1/tx";

import { rpcEndpoint } from "./constants";

Expand Down Expand Up @@ -72,3 +80,33 @@ export const stakeAmount = async (

return await client.signAndBroadcast(addresses.delegator, [msgAny], fee);
};

export const unstakeAmount = async (
addresses: StakeAddresses,
client: NonNullable<SigningClient>,
amount: Coin,
) => {
const msg = MsgUndelegate.fromPartial({
amount,
delegatorAddress: addresses.delegator,
validatorAddress: addresses.validator,
});

const msgAny: MsgUndelegateEncodeObject = {
typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
value: msg,
};

const fee: StdFee = {
amount: [
{
amount: "1000",
denom: "uxion",
},
],
gas: "200000",
granter: addresses.delegator,
};

return await client.signAndBroadcast(addresses.delegator, [msgAny], fee);
};

0 comments on commit c31fdf5

Please sign in to comment.