-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: devire import identities from seed phrase
- [x] Add signature options for identity import - [x] Minor refactoring
- Loading branch information
Showing
26 changed files
with
485 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export type { IDropdownButtonMenuItem, IDropdownButtonProps } from "./DropdownButton"; | ||
export type { IDropdownButtonOption, IDropdownButtonProps } from "./DropdownButton"; | ||
export { default as DropdownButton } from "./DropdownButton"; |
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
65 changes: 65 additions & 0 deletions
65
packages/app/src/ui/hooks/wallet/__tests__/useSignatureOptions.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,65 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
|
||
import { renderHook } from "@testing-library/react"; | ||
|
||
import { defaultWalletHookData } from "@src/config/mock/wallet"; | ||
|
||
import { useSignatureOptions } from ".."; | ||
import { useEthWallet } from "../useEthWallet"; | ||
|
||
jest.mock("../useEthWallet", (): unknown => ({ | ||
useEthWallet: jest.fn(), | ||
})); | ||
|
||
describe("ui/hooks/useSignatureOptions", () => { | ||
const defaultHookArgs = { | ||
isLoading: false, | ||
}; | ||
|
||
beforeEach(() => { | ||
(useEthWallet as jest.Mock).mockReturnValue({ ...defaultWalletHookData, isActive: true }); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("should return cryptkeeper and eth wallet options", () => { | ||
const { result } = renderHook(() => useSignatureOptions(defaultHookArgs)); | ||
|
||
expect(result.current.options[0].id).toBe("ck"); | ||
expect(result.current.options[0].title).toBe("Sign with CryptKeeper"); | ||
expect(result.current.options[0].checkDisabledItem()).toBe(defaultHookArgs.isLoading); | ||
expect(result.current.options[1].id).toBe("eth"); | ||
expect(result.current.options[1].title).toBe("Sign with MetaMask"); | ||
expect(result.current.options[1].checkDisabledItem()).toBe(defaultHookArgs.isLoading); | ||
}); | ||
|
||
test("should return cryptkeeper and connect eth wallet options", () => { | ||
(useEthWallet as jest.Mock).mockReturnValue({ ...defaultWalletHookData, isActive: false }); | ||
|
||
const { result } = renderHook(() => useSignatureOptions(defaultHookArgs)); | ||
|
||
expect(result.current.options[0].id).toBe("ck"); | ||
expect(result.current.options[0].title).toBe("Sign with CryptKeeper"); | ||
expect(result.current.options[0].checkDisabledItem()).toBe(defaultHookArgs.isLoading); | ||
expect(result.current.options[1].id).toBe("eth"); | ||
expect(result.current.options[1].title).toBe("Connect to MetaMask"); | ||
expect(result.current.options[1].checkDisabledItem()).toBe(defaultHookArgs.isLoading); | ||
}); | ||
|
||
test("should return cryptkeeper and install eth wallet options", () => { | ||
(useEthWallet as jest.Mock).mockReturnValue({ ...defaultWalletHookData, isActive: false, isInjectedWallet: false }); | ||
|
||
const { result } = renderHook(() => useSignatureOptions(defaultHookArgs)); | ||
|
||
expect(result.current.options[0].id).toBe("ck"); | ||
expect(result.current.options[0].title).toBe("Sign with CryptKeeper"); | ||
expect(result.current.options[0].checkDisabledItem()).toBe(defaultHookArgs.isLoading); | ||
expect(result.current.options[1].id).toBe("eth"); | ||
expect(result.current.options[1].title).toBe("Install MetaMask"); | ||
expect(result.current.options[1].checkDisabledItem()).toBe(true); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { useCryptKeeperWallet } from "./useCryptKeeper"; | ||
export { useEthWallet } from "./useEthWallet"; | ||
export { useSignatureOptions } from "./useSignatureOptions"; |
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 { useEthWallet } from "./useEthWallet"; | ||
|
||
export interface IUseSignatureOptionsArgs { | ||
isLoading: boolean; | ||
} | ||
|
||
export interface IUseSignatureOptionsData { | ||
options: ISignatureOption[]; | ||
} | ||
|
||
export interface ISignatureOption { | ||
id: string; | ||
title: string; | ||
checkDisabledItem: () => boolean; | ||
} | ||
|
||
export const useSignatureOptions = ({ isLoading }: IUseSignatureOptionsArgs): IUseSignatureOptionsData => { | ||
const ethWallet = useEthWallet(); | ||
|
||
const { isActive: isWalletConnected, isInjectedWallet: isWalletInstalled } = ethWallet; | ||
const ethWalletTitle = isWalletConnected ? "Sign with MetaMask" : "Connect to MetaMask"; | ||
|
||
const options = [ | ||
{ id: "ck", title: "Sign with CryptKeeper", checkDisabledItem: () => isLoading }, | ||
{ | ||
id: "eth", | ||
title: isWalletInstalled ? ethWalletTitle : "Install MetaMask", | ||
checkDisabledItem: () => isLoading || !isWalletInstalled, | ||
}, | ||
]; | ||
|
||
return { options }; | ||
}; |
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.