-
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
feat(staking): create a stake account on initial deposit #1887
Conversation
@cprussin is attempting to deploy a commit to the pyth-web Team on Vercel. A member of the Team first needs to authorize it. |
apps/staking/src/api.ts
Outdated
} | ||
}; | ||
|
||
const loadPublisherData = async (client: PythStakingClient) => { |
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.
@keyvankhademi FYI, this stuff is separated out because there are now two separate flows for fetching dashboard data -- one for when there is a stake account and one for when there isn't. The publisher data is common between the two.
@@ -221,6 +262,13 @@ export const loadAccountHistory = async ( | |||
return mkMockHistory(); | |||
}; | |||
|
|||
export const createStakeAccountAndDeposit = async ( |
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
isDisabled={availableToWithdraw === 0n} | ||
{...(api.type === ApiStateType.Loaded && { | ||
transfer: api.withdraw, | ||
})} |
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.
Note to reviewer: in this PR I made the <TransferButton>
component render a disabled button if the max is 0n
or if transfer
is undefined. That makes it a lot easier to just use it all over and let it disable itself correctly if there's no function to call (generally meaning the API is in a state where this transfer is impossible) or if there's no tokens to transfer. So you'll see here and a few other places where I removed some checks that control the button states, since those are now handled by the button itself.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
2ccb362
to
7c7aa8d
Compare
7c7aa8d
to
20ce372
Compare
This PR includes a fairly significant refactor to restructure some hooks:
useStakeAccount
has been replaced by a very similar hook calleduseApi
. The biggest difference here, apart from some renaming, is that the states inuseApi
expose wrapped functions fromapi.ts
, bound to the current stake account & client. So there's no need to interact with the stake account or staking client orapi.ts
anywhere else in the app any more.useTransfer
is replaced by a more generic hookuseAsync
, which takes an async callback and returns a function to trigger execution and the current execution satate. I did this because, once moving everything touseApi
, everything specific to transferring, including busting the swr cache, got moved to theuseApi
wrapper functions, and what was left was just really a generic mechanism for running and tracking state of an async function.useAccountHistory
anduseDashboardData
have been replaced byuseData
, which takesuseSwr
and wraps it to bind the output to enum types. Both of the original hooks were doing mostly the same thing but with marginally different ways to set up their fetch functions; withuseApi
those things are now abstracted in the API states.With those in place, I was able to use the states in
useApi
to abstract away how to handle depositing & fetching data when a stake account exists from when it doesn't, and I was able to leverage the type system to guarantee that an API method can't be called in an invalid state, which cleaned up a lot of other code too and removed the possibility of some class of runtime exceptions.