-
Notifications
You must be signed in to change notification settings - Fork 1
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
PE-7115: remove use of delegates field on gateways and update app to use getGatewayDelegates() and getDelegations() #111
base: develop
Are you sure you want to change the base?
Changes from all commits
339bb83
b3338e8
0e3a9b2
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { AoStakeDelegation, AoVaultDelegation } from '@ar.io/sdk/web'; | ||
import { useGlobalState } from '@src/store'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
type DelegateStakes = { | ||
stakes: Array<AoStakeDelegation>; | ||
withdrawals: Array<AoVaultDelegation>; | ||
}; | ||
|
||
const useDelegateStakes = (address?: string) => { | ||
const arIOReadSDK = useGlobalState((state) => state.arIOReadSDK); | ||
|
||
const res = useQuery<DelegateStakes>({ | ||
queryKey: ['delegateStakes', address], | ||
queryFn: async () => { | ||
if (!address) { | ||
throw new Error('Address is not set'); | ||
} | ||
|
||
const retVal: DelegateStakes = { | ||
stakes: [], | ||
withdrawals: [], | ||
}; | ||
|
||
let cursor: string | undefined; | ||
|
||
do { | ||
const pageResult = await arIOReadSDK.getDelegations({ | ||
address, | ||
cursor, | ||
limit: 10, | ||
}); | ||
pageResult.items.forEach((d) => { | ||
if (d.type === 'stake') { | ||
retVal.stakes.push(d); | ||
} else { | ||
retVal.withdrawals.push(d); | ||
} | ||
}); | ||
cursor = pageResult.nextCursor; | ||
} while (cursor !== undefined); | ||
|
||
return retVal; | ||
}, | ||
staleTime: Infinity, | ||
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. any consequence of this stale time? 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. I added this in so that the query should return the same value for the duration of the session unless explicitly invalidated by user action (i.e., instant withdrawal, cancelling a stake, adding new stake). |
||
}); | ||
|
||
return res; | ||
}; | ||
|
||
export default useDelegateStakes; |
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.
i thought maybe the
_
would avoid needing this, fine to revert