diff --git a/src/features/staking/components/faucet.tsx b/src/features/staking/components/faucet.tsx deleted file mode 100644 index 791b593..0000000 --- a/src/features/staking/components/faucet.tsx +++ /dev/null @@ -1,93 +0,0 @@ -import { useAbstraxionAccount } from "@burnt-labs/abstraxion"; -import { memo, useCallback, useEffect, useState } from "react"; - -import { IS_TESTNET } from "@/config"; -import { Button } from "@/features/core/components/base"; -import { fetchUserDataAction } from "@/features/staking/context/actions"; -import { normaliseCoin } from "@/features/staking/lib/core/coins"; - -import { useStaking } from "../context/hooks"; -import type { AddressLastFaucetStatus } from "../lib/core/tx"; -import { faucetFunds, getAddressLastFaucetTimestamp } from "../lib/core/tx"; - -const Faucet = () => { - const { isConnected } = useAbstraxionAccount(); - const { address, client, staking } = useStaking(); - - const [lastFaucetStatus, setLastFaucetStatus] = - useState({ - canFaucet: false, - denom: "", - lastFaucetTimestamp: 0, - maxBalance: 0, - nextFaucetTimestamp: 0, - }); - - const [isFauceting, setIsFauceting] = useState(false); - - const updateFaucetStatus = useCallback(async () => { - if (isConnected && address && client) { - const result = await getAddressLastFaucetTimestamp(address, client); - - // We need to hide this when not on testnet. - if (staking.state.tokens?.denom !== result.denom || !IS_TESTNET) { - return; - } - - if (parseInt(staking.state.tokens?.amount) >= result.maxBalance) { - setLastFaucetStatus({ - ...result, - - canFaucet: false, - }); - } else { - setLastFaucetStatus(result); - } - } - }, [isConnected, address, client, staking.state.tokens]); - - useEffect(() => { - updateFaucetStatus(); - }, [isConnected, address, client, updateFaucetStatus]); - - if (!isConnected || !lastFaucetStatus.canFaucet) { - return null; - } - - const normalizedFaucetInfo = normaliseCoin({ - amount: lastFaucetStatus.maxBalance.toString(), - denom: lastFaucetStatus.denom, - }); - - return ( -
- {lastFaucetStatus.canFaucet && ( - - )} -
- ); -}; - -export default memo(Faucet); diff --git a/src/features/staking/components/main-page.tsx b/src/features/staking/components/main-page.tsx index aa2e51d..a83083d 100644 --- a/src/features/staking/components/main-page.tsx +++ b/src/features/staking/components/main-page.tsx @@ -2,7 +2,6 @@ import { memo, useState } from "react"; -import { IS_TESTNET } from "@/config"; import { Title } from "@/features/core/components/base"; import { useStaking } from "../context/hooks"; @@ -10,7 +9,6 @@ import DelegationDetails, { DetailsTrigger, getCanShowDetails, } from "./delegation-details"; -import Faucet from "./faucet"; import StakingModals from "./staking-modals"; import StakingOverview from "./staking-overview"; import ValidatorsTable from "./validators-table"; @@ -36,7 +34,6 @@ function StakingPage() { /> )} - {IS_TESTNET && } {isShowingDetails && canShowDetail && } diff --git a/src/features/staking/lib/core/tx.ts b/src/features/staking/lib/core/tx.ts index a9083eb..8283a14 100644 --- a/src/features/staking/lib/core/tx.ts +++ b/src/features/staking/lib/core/tx.ts @@ -15,7 +15,6 @@ import { MsgUndelegate, } from "cosmjs-types/cosmos/staking/v1beta1/tx"; -import { FAUCET_CONTRACT_ADDRESS } from "@/config"; import { MIN_CLAIMABLE_XION } from "@/constants"; import type { Unbonding } from "../../context/state"; @@ -215,74 +214,6 @@ export const cancelUnbonding = async ( .catch(handleTxError); }; -export interface AddressLastFaucetStatus { - canFaucet: boolean; - - denom: string; - lastFaucetTimestamp: number; - maxBalance: number; - nextFaucetTimestamp: number; -} - -interface GetAccountLastClaimTimestampResponse { - amount_to_faucet: number; - cooldown_period: number; - denom: string; - timestamp: string; -} - -export const getAddressLastFaucetTimestamp = async ( - address: string, - client: NonNullable, -): Promise => { - const msg = { - get_address_last_faucet_timestamp: { - address, - }, - }; - - return await client - .queryContractSmart(FAUCET_CONTRACT_ADDRESS, msg) - .then((res: GetAccountLastClaimTimestampResponse) => { - // Get the current timestamp in seconds - const currentTimestampInSeconds = Math.floor(Date.now() / 1000); - const timestamp = parseInt(res.timestamp); - - // If the timestamp is 0, the user has never claimed. - if (timestamp === 0) { - return { - canFaucet: true, - denom: res.denom, - lastFaucetTimestamp: 0, - maxBalance: res.amount_to_faucet, - nextFaucetTimestamp: currentTimestampInSeconds, - }; - } - - return { - canFaucet: timestamp + res.cooldown_period < currentTimestampInSeconds, - denom: res.denom, - lastFaucetTimestamp: timestamp, - maxBalance: res.amount_to_faucet, - nextFaucetTimestamp: timestamp + res.cooldown_period, - }; - }) - .catch(handleTxError); -}; - -export const faucetFunds = async ( - address: string, - client: NonNullable, -) => { - const msg = { - faucet: {}, - }; - - return await client - .execute(address, FAUCET_CONTRACT_ADDRESS, msg, "auto") - .catch(handleTxError); -}; - type BatchClaimAddresses = { delegator: string; validators: string[];