-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
253 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"use client"; | ||
import React, { useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { getMultisigAccounts } from "../../../store/features/multisig/multisigSlice"; | ||
import { AppDispatch } from "../../../store/store"; | ||
|
||
const Multisig = () => { | ||
const dispatch = useDispatch<AppDispatch>(); | ||
const multisigAccounts = useSelector( | ||
(state: any) => state.multisig.multisigAccounts | ||
); | ||
|
||
useEffect(() => { | ||
dispatch(getMultisigAccounts("cosmos16wnk86wkfj7a84g4d7epa2mf7fk2g7cm0rljjm")); | ||
}, [dispatch]); | ||
return <div>{JSON.stringify(multisigAccounts)}</div>; | ||
}; | ||
|
||
export default Multisig; |
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,13 @@ | ||
"use client"; | ||
|
||
import { Provider } from "react-redux"; | ||
import { store } from "./store"; | ||
import { ReactNode } from "react"; | ||
|
||
interface StoreProviderProps { | ||
children: ReactNode; | ||
} | ||
|
||
export function StoreProvider({ children }: StoreProviderProps) { | ||
return <Provider store={store}>{children}</Provider>; | ||
} |
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,14 @@ | ||
"use client"; | ||
|
||
import Axios from "axios"; | ||
|
||
const BASE_URL = "http://localhost:1323"; | ||
|
||
const GET_ACCOUNTS = "/multisig/accounts"; | ||
|
||
const getAccounts = (address: string) => | ||
Axios.get(`${BASE_URL}${GET_ACCOUNTS}/${address}`); | ||
|
||
export default { | ||
getAccounts: getAccounts, | ||
}; |
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,53 @@ | ||
"use client"; | ||
|
||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; | ||
import multisigService from "./multisigService"; | ||
|
||
const initialState = { | ||
multisigAccounts: { | ||
status: "idle", | ||
accounts: [], | ||
txnCounts: {}, | ||
total: 0, | ||
}, | ||
}; | ||
|
||
export const getMultisigAccounts = createAsyncThunk( | ||
"multisig/getMultisigAccounts", | ||
async (address: string, { rejectWithValue }) => { | ||
try { | ||
const response = await multisigService.getAccounts(address); | ||
return response.data; | ||
} catch (error) { | ||
return rejectWithValue("SOMETHING_WRONG"); | ||
} | ||
} | ||
); | ||
|
||
export const multisigSlice = createSlice({ | ||
name: "multisig", | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(getMultisigAccounts.pending, (state) => { | ||
state.multisigAccounts.status = "pending"; | ||
state.multisigAccounts.accounts = []; | ||
state.multisigAccounts.total = 0; | ||
state.multisigAccounts.txnCounts = {}; | ||
}) | ||
.addCase(getMultisigAccounts.fulfilled, (state, action) => { | ||
state.multisigAccounts.accounts = action.payload?.data?.accounts || []; | ||
state.multisigAccounts.total = action.payload?.data?.total; | ||
state.multisigAccounts.txnCounts = | ||
action.payload?.data?.pending_txns || {}; | ||
state.multisigAccounts.status = "idle"; | ||
}) | ||
.addCase(getMultisigAccounts.rejected, (state, action) => { | ||
state.multisigAccounts.status = "rejected"; | ||
state.multisigAccounts.accounts = []; | ||
}); | ||
}, | ||
}); | ||
|
||
export default multisigSlice.reducer; |
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,13 @@ | ||
"use client"; | ||
|
||
import { configureStore } from "@reduxjs/toolkit"; | ||
import multisigSlice from "./features/multisig/multisigSlice"; | ||
|
||
export const store = configureStore({ | ||
reducer: { | ||
multisig: multisigSlice | ||
}, | ||
}); | ||
|
||
export type RootState = ReturnType<typeof store.getState>; | ||
export type AppDispatch = typeof store.dispatch; |
Oops, something went wrong.