-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): Managing Connections Through Connect Wallet Connection Hist…
…ory (#457) * feat(ui): remove unused style of modal * feat(ui): create common list * feat(ui): implement confirm connect wallet modal * feat(ui): implement confirm connect wallet action * feat(ui): implement redux store for wallet connections * feat(ui): implement wallet connection histories * feat(ui): update style for confirm connect wallet modal * feat(ui): create enum for action type * feat(ui): remove unecessary text func --------- Co-authored-by: Vu Van Duc <vuvanduc@Vus-MacBook-Pro.local>
- Loading branch information
1 parent
9d9c6a7
commit e17deae
Showing
32 changed files
with
1,695 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./walletConnectionsCache"; | ||
export * from "./walletConnectionsCache.types"; |
101 changes: 101 additions & 0 deletions
101
src/store/reducers/walletConnectionsCache/walletConnectionsCache.test.ts
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,101 @@ | ||
import { PayloadAction } from "@reduxjs/toolkit"; | ||
import { RootState } from "../../index"; | ||
import { | ||
getConnectedWallet, | ||
getWalletConnectionsCache, | ||
setConnectedWallet, | ||
setWalletConnectionsCache, | ||
walletConnectionsCacheSlice, | ||
} from "./walletConnectionsCache"; | ||
import { | ||
ConnectionData, | ||
WalletConnectState, | ||
} from "./walletConnectionsCache.types"; | ||
|
||
describe("walletConnectionsCacheSlice", () => { | ||
const initialState: WalletConnectState = { | ||
walletConnections: [], | ||
connectedWallet: null, | ||
}; | ||
|
||
it("should return the initial state", () => { | ||
expect( | ||
walletConnectionsCacheSlice.reducer(undefined, {} as PayloadAction) | ||
).toEqual(initialState); | ||
}); | ||
|
||
it("should handle setWalletConnectionsCache", () => { | ||
const connections: ConnectionData[] = [ | ||
{ | ||
id: 2, | ||
name: "Wallet name #2", | ||
owner: "Yoroi", | ||
url: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inb", | ||
}, | ||
]; | ||
const newState = walletConnectionsCacheSlice.reducer( | ||
initialState, | ||
setWalletConnectionsCache(connections) | ||
); | ||
expect(newState.walletConnections).toEqual(connections); | ||
}); | ||
it("should handle setConnectedWallet", () => { | ||
const connection: ConnectionData = { | ||
id: 2, | ||
name: "Wallet name #2", | ||
owner: "Yoroi", | ||
url: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inb", | ||
}; | ||
const newState = walletConnectionsCacheSlice.reducer( | ||
initialState, | ||
setConnectedWallet(connection) | ||
); | ||
expect(newState.connectedWallet).toEqual(connection); | ||
}); | ||
}); | ||
|
||
describe("Get wallet connections cache", () => { | ||
it("should return the wallet connetions cache from RootState", () => { | ||
const state = { | ||
walletConnectionsCache: { | ||
walletConnections: [ | ||
{ | ||
id: 1, | ||
name: "Wallet name #1", | ||
owner: "Nami", | ||
image: "", | ||
url: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inb", | ||
}, | ||
{ | ||
id: 2, | ||
name: "Wallet name #2", | ||
owner: "Yoroi", | ||
url: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inb", | ||
}, | ||
], | ||
}, | ||
} as RootState; | ||
const connectionCache = getWalletConnectionsCache(state); | ||
expect(connectionCache).toEqual( | ||
state.walletConnectionsCache.walletConnections | ||
); | ||
}); | ||
|
||
it("should return connected wallet from RootState", () => { | ||
const state = { | ||
walletConnectionsCache: { | ||
connectedWallet: { | ||
id: 1, | ||
name: "Wallet name #1", | ||
owner: "Nami", | ||
image: "", | ||
url: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inb", | ||
}, | ||
}, | ||
} as RootState; | ||
const connectionCache = getConnectedWallet(state); | ||
expect(connectionCache).toEqual( | ||
state.walletConnectionsCache.connectedWallet | ||
); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
src/store/reducers/walletConnectionsCache/walletConnectionsCache.ts
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,42 @@ | ||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | ||
import { RootState } from "../../index"; | ||
import { | ||
ConnectionData, | ||
WalletConnectState, | ||
} from "./walletConnectionsCache.types"; | ||
|
||
const initialState: WalletConnectState = { | ||
walletConnections: [], | ||
connectedWallet: null, | ||
}; | ||
const walletConnectionsCacheSlice = createSlice({ | ||
name: "walletConnectionsCache", | ||
initialState, | ||
reducers: { | ||
setWalletConnectionsCache: ( | ||
state, | ||
action: PayloadAction<ConnectionData[]> | ||
) => { | ||
state.walletConnections = action.payload; | ||
}, | ||
setConnectedWallet: ( | ||
state, | ||
action: PayloadAction<ConnectionData | null> | ||
) => { | ||
state.connectedWallet = action.payload; | ||
}, | ||
}, | ||
}); | ||
|
||
export { initialState, walletConnectionsCacheSlice }; | ||
|
||
export const { setWalletConnectionsCache, setConnectedWallet } = | ||
walletConnectionsCacheSlice.actions; | ||
|
||
const getWalletConnectionsCache = (state: RootState) => | ||
state.walletConnectionsCache.walletConnections; | ||
|
||
const getConnectedWallet = (state: RootState) => | ||
state.walletConnectionsCache.connectedWallet; | ||
|
||
export { getWalletConnectionsCache, getConnectedWallet }; |
15 changes: 15 additions & 0 deletions
15
src/store/reducers/walletConnectionsCache/walletConnectionsCache.types.ts
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,15 @@ | ||
// TODO: mock data type for connect wallet ui. Need update after core function completed. | ||
interface ConnectionData { | ||
id: number; | ||
name: string; | ||
owner: string; | ||
image?: string; | ||
url: string; | ||
} | ||
|
||
interface WalletConnectState { | ||
walletConnections: ConnectionData[]; | ||
connectedWallet: ConnectionData | null; | ||
} | ||
|
||
export type { ConnectionData, WalletConnectState }; |
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,33 @@ | ||
import { ConnectionData } from "../../store/reducers/walletConnectionsCache"; | ||
import KeriLogo from "../assets/images/KeriGeneric.jpg"; | ||
|
||
const walletConnectionsFix: ConnectionData[] = [ | ||
{ | ||
id: 1, | ||
name: "Wallet name #1", | ||
owner: "Nami", | ||
image: KeriLogo, | ||
url: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inb", | ||
}, | ||
{ | ||
id: 2, | ||
name: "Wallet name #2", | ||
owner: "Yoroi", | ||
url: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inb", | ||
}, | ||
{ | ||
id: 3, | ||
name: "Wallet name #3", | ||
owner: "Flint", | ||
url: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inb", | ||
image: KeriLogo, | ||
}, | ||
{ | ||
id: 4, | ||
name: "Wallet name #4", | ||
owner: "Yume", | ||
url: "ED4KeyyTKFj-72B008OTGgDCrFo6y7B2B73kfyzu5Inb", | ||
}, | ||
]; | ||
|
||
export { walletConnectionsFix }; |
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.