1
1
"use client" ;
2
2
3
3
import { HermesClient } from "@pythnetwork/hermes-client" ;
4
- import {
5
- type StakeAccountPositions ,
6
- PythStakingClient ,
7
- } from "@pythnetwork/staking-sdk" ;
4
+ import { PythStakingClient } from "@pythnetwork/staking-sdk" ;
8
5
import { useConnection , useWallet } from "@solana/wallet-adapter-react" ;
9
6
import type { PublicKey } from "@solana/web3.js" ;
10
7
import {
@@ -46,7 +43,7 @@ const State = {
46
43
[ StateType . LoadedNoStakeAccount ] : (
47
44
client : PythStakingClient ,
48
45
hermesClient : HermesClient ,
49
- onCreateAccount : ( newAccount : StakeAccountPositions ) => void ,
46
+ onCreateAccount : ( newAccount : PublicKey ) => void ,
50
47
) => ( {
51
48
type : StateType . LoadedNoStakeAccount as const ,
52
49
client,
@@ -62,18 +59,18 @@ const State = {
62
59
[ StateType . Loaded ] : (
63
60
client : PythStakingClient ,
64
61
hermesClient : HermesClient ,
65
- account : StakeAccountPositions ,
66
- allAccounts : [ StakeAccountPositions , ...StakeAccountPositions [ ] ] ,
67
- selectAccount : ( account : StakeAccountPositions ) => void ,
62
+ account : PublicKey ,
63
+ allAccounts : [ PublicKey , ...PublicKey [ ] ] ,
64
+ selectAccount : ( account : PublicKey ) => void ,
68
65
mutate : ReturnType < typeof useSWRConfig > [ "mutate" ] ,
69
66
) => {
70
- const dashboardDataCacheKey = account . address . toBase58 ( ) ;
71
- const accountHisoryCacheKey = `${ account . address . toBase58 ( ) } /history` ;
67
+ const dashboardDataCacheKey = account . toBase58 ( ) ;
68
+ const accountHistoryCacheKey = `${ account . toBase58 ( ) } /history` ;
72
69
73
70
const reload = async ( ) => {
74
71
await Promise . all ( [
75
72
mutate ( dashboardDataCacheKey ) ,
76
- mutate ( accountHisoryCacheKey ) ,
73
+ mutate ( accountHistoryCacheKey ) ,
77
74
] ) ;
78
75
} ;
79
76
@@ -86,7 +83,7 @@ const State = {
86
83
) => Promise < void > ,
87
84
) =>
88
85
async ( ...args : T ) => {
89
- await fn ( client , account . address , ...args ) ;
86
+ await fn ( client , account , ...args ) ;
90
87
await reload ( ) ;
91
88
} ;
92
89
@@ -98,10 +95,10 @@ const State = {
98
95
allAccounts,
99
96
selectAccount,
100
97
dashboardDataCacheKey,
101
- accountHisoryCacheKey ,
98
+ accountHistoryCacheKey ,
102
99
103
100
loadData : ( ) => api . loadData ( client , hermesClient , account ) ,
104
- loadAccountHistory : ( ) => api . loadAccountHistory ( client , account . address ) ,
101
+ loadAccountHistory : ( ) => api . loadAccountHistory ( client , account ) ,
105
102
106
103
claim : bindApi ( api . claim ) ,
107
104
deposit : bindApi ( api . deposit ) ,
@@ -157,7 +154,7 @@ const useApiContext = (hermesUrl: string) => {
157
154
const { mutate } = useSWRConfig ( ) ;
158
155
159
156
const setAccount = useCallback (
160
- ( account : StakeAccountPositions ) => {
157
+ ( account : PublicKey ) => {
161
158
setState ( ( cur ) =>
162
159
cur . type === StateType . Loaded
163
160
? State [ StateType . Loaded ] (
@@ -195,7 +192,7 @@ const useApiContext = (hermesUrl: string) => {
195
192
const hermesClient = new HermesClient ( hermesUrl ) ;
196
193
setState ( State [ StateType . LoadingStakeAccounts ] ( client , hermesClient ) ) ;
197
194
api
198
- . getStakeAccounts ( client )
195
+ . getAllStakeAccountAddresses ( client )
199
196
. then ( ( accounts ) => {
200
197
const [ firstAccount , ...otherAccounts ] = accounts ;
201
198
if ( firstAccount ) {
0 commit comments