-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(staking): create a stake account on initial deposit #1887
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,15 @@ import { | |
} from "react-aria-components"; | ||
|
||
import background from "./background.png"; | ||
import { deposit, withdraw, claim } from "../../api"; | ||
import { StateType, useTransfer } from "../../hooks/use-transfer"; | ||
import { type States, StateType as ApiStateType } from "../../hooks/use-api"; | ||
import { StateType, useAsync } from "../../hooks/use-async"; | ||
import { Button } from "../Button"; | ||
import { ModalDialog } from "../ModalDialog"; | ||
import { Tokens } from "../Tokens"; | ||
import { TransferButton } from "../TransferButton"; | ||
|
||
type Props = { | ||
api: States[ApiStateType.Loaded] | States[ApiStateType.LoadedNoStakeAccount]; | ||
total: bigint; | ||
locked: bigint; | ||
unlockSchedule: { | ||
|
@@ -38,6 +39,7 @@ type Props = { | |
}; | ||
|
||
export const AccountSummary = ({ | ||
api, | ||
locked, | ||
unlockSchedule, | ||
lastSlash, | ||
|
@@ -114,7 +116,7 @@ export const AccountSummary = ({ | |
actionDescription="Add funds to your balance" | ||
actionName="Add Tokens" | ||
max={walletAmount} | ||
transfer={deposit} | ||
transfer={api.deposit} | ||
/> | ||
</div> | ||
</div> | ||
|
@@ -130,16 +132,25 @@ export const AccountSummary = ({ | |
actionDescription="Move funds from your account back to your wallet" | ||
actionName="Withdraw" | ||
max={availableToWithdraw} | ||
transfer={withdraw} | ||
isDisabled={availableToWithdraw === 0n} | ||
{...(api.type === ApiStateType.Loaded && { | ||
transfer: api.withdraw, | ||
})} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to reviewer: in this PR I made the |
||
/> | ||
} | ||
/> | ||
<BalanceCategory | ||
name="Available Rewards" | ||
amount={availableRewards} | ||
description="Rewards you have earned from OIS" | ||
action={<ClaimButton isDisabled={availableRewards === 0n} />} | ||
action={ | ||
api.type === ApiStateType.Loaded ? ( | ||
<ClaimButton isDisabled={availableRewards === 0n} api={api} /> | ||
) : ( | ||
<Button size="small" variant="secondary" isDisabled={true}> | ||
Claim | ||
</Button> | ||
) | ||
} | ||
{...(expiringRewards !== undefined && | ||
expiringRewards.amount > 0n && { | ||
warning: ( | ||
|
@@ -187,13 +198,15 @@ const BalanceCategory = ({ | |
</div> | ||
); | ||
|
||
const ClaimButton = ( | ||
props: Omit< | ||
ComponentProps<typeof Button>, | ||
"onClick" | "disabled" | "loading" | ||
>, | ||
) => { | ||
const { state, execute } = useTransfer(claim); | ||
type ClaimButtonProps = Omit< | ||
ComponentProps<typeof Button>, | ||
"onClick" | "disabled" | "loading" | ||
> & { | ||
api: States[ApiStateType.Loaded]; | ||
}; | ||
|
||
const ClaimButton = ({ api, ...props }: ClaimButtonProps) => { | ||
const { state, execute } = useAsync(api.claim); | ||
|
||
const doClaim = useCallback(() => { | ||
execute().catch(() => { | ||
|
@@ -207,7 +220,7 @@ const ClaimButton = ( | |
variant="secondary" | ||
onPress={doClaim} | ||
isDisabled={state.type !== StateType.Base} | ||
isLoading={state.type === StateType.Submitting} | ||
isLoading={state.type === StateType.Running} | ||
{...props} | ||
> | ||
Claim | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi @keyvankhademi