-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from ar-io/develop
Release v1.4.1
- Loading branch information
Showing
12 changed files
with
178 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
|
||
return res; | ||
}; | ||
|
||
export default useDelegateStakes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.