@@ -48,6 +48,7 @@ import { get } from 'lodash';
48
48
import { getAuthToken } from '@/utils/localStorage' ;
49
49
import multisigSigning from '@/app/(routes)/multisig/utils/multisigSigning' ;
50
50
import { setError } from '../common/commonSlice' ;
51
+ import stakingService from '../staking/stakingService' ;
51
52
52
53
const initialState : MultisigState = {
53
54
createMultisigAccountRes : {
@@ -88,6 +89,21 @@ const initialState: MultisigState = {
88
89
status : TxStatus . INIT ,
89
90
error : '' ,
90
91
} ,
92
+ delegations : {
93
+ status : TxStatus . INIT ,
94
+ delegations : {
95
+ delegation_responses : [ ] ,
96
+ pagination : {
97
+ next_key : '' ,
98
+ total : '' ,
99
+ } ,
100
+ } ,
101
+ hasDelegations : false ,
102
+ errMsg : '' ,
103
+ pagination : undefined ,
104
+ delegatedTo : { } ,
105
+ totalStaked : 0.0 ,
106
+ } ,
91
107
createTxnRes : {
92
108
status : TxStatus . INIT ,
93
109
error : '' ,
@@ -287,6 +303,49 @@ export const getMultisigBalances = createAsyncThunk(
287
303
}
288
304
) ;
289
305
306
+ export const getDelegations = createAsyncThunk (
307
+ 'multisig/delegations' ,
308
+ async (
309
+ data : {
310
+ baseURLs : string [ ] ;
311
+ address : string ;
312
+ chainID : string ;
313
+ } ,
314
+ { rejectWithValue }
315
+ ) => {
316
+ try {
317
+ const delegations = [ ] ;
318
+ let nextKey = null ;
319
+ const limit = 100 ;
320
+ while ( true ) {
321
+ const response = await stakingService . delegations (
322
+ data . baseURLs ,
323
+ data . address ,
324
+ data . chainID ,
325
+ nextKey
326
+ ? {
327
+ key : nextKey ,
328
+ limit : limit ,
329
+ }
330
+ : { }
331
+ ) ;
332
+ delegations . push ( ...( response . data ?. delegation_responses || [ ] ) ) ;
333
+ if ( ! response . data . pagination ?. next_key ) {
334
+ break ;
335
+ }
336
+ nextKey = response . data . pagination . next_key ;
337
+ }
338
+
339
+ return {
340
+ delegations : delegations ,
341
+ } ;
342
+ } catch ( error ) {
343
+ if ( error instanceof AxiosError ) return rejectWithValue ( error . message ) ;
344
+ return rejectWithValue ( ERR_UNKNOWN ) ;
345
+ }
346
+ }
347
+ ) ;
348
+
290
349
export const createTxn = createAsyncThunk (
291
350
'multisig/createTxn' ,
292
351
async ( data : CreateTxnInputs , { rejectWithValue } ) => {
@@ -731,6 +790,35 @@ export const multisigSlice = createSlice({
731
790
const payload = action . payload as { message : string } ;
732
791
state . balance . error = payload . message || '' ;
733
792
} ) ;
793
+ builder
794
+ . addCase ( getDelegations . pending , ( state ) => {
795
+ state . delegations . status = TxStatus . PENDING ;
796
+ state . delegations . errMsg = '' ;
797
+ } )
798
+ . addCase ( getDelegations . fulfilled , ( state , action ) => {
799
+ const delegation_responses = action . payload . delegations ;
800
+ if ( delegation_responses ?. length ) {
801
+ state . delegations . hasDelegations = true ;
802
+ }
803
+ state . delegations . status = TxStatus . IDLE ;
804
+ state . delegations . delegations . delegation_responses =
805
+ delegation_responses ;
806
+ state . delegations . errMsg = '' ;
807
+
808
+ let total = 0.0 ;
809
+ for ( let i = 0 ; i < delegation_responses . length ; i ++ ) {
810
+ const delegation = delegation_responses [ i ] ;
811
+ state . delegations . delegatedTo [
812
+ delegation ?. delegation ?. validator_address
813
+ ] = true ;
814
+ total += parseFloat ( delegation ?. delegation ?. shares ) ;
815
+ }
816
+ state . delegations . totalStaked = total ;
817
+ } )
818
+ . addCase ( getDelegations . rejected , ( state , action ) => {
819
+ state . delegations . status = TxStatus . REJECTED ;
820
+ state . delegations . errMsg = action . error . message || '' ;
821
+ } ) ;
734
822
builder
735
823
. addCase ( createTxn . pending , ( state ) => {
736
824
state . createTxnRes . status = TxStatus . PENDING ;
0 commit comments