diff --git a/package.json b/package.json index 01e07f4..e5b51aa 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "preview": "vite preview" }, "dependencies": { - "@fireblocks/ncw-js-sdk": "^9.3.1", + "@fireblocks/ncw-js-sdk": "^9.5.0", "base58-js": "^2.0.0", "classnames": "^2.3.2", "node-forge": "^1.3.1", diff --git a/src/AppStore.ts b/src/AppStore.ts index c2db907..7b0e837 100644 --- a/src/AppStore.ts +++ b/src/AppStore.ts @@ -416,6 +416,18 @@ export const useAppStore = create()((set, get) => { set((state) => ({ ...state, web3Connections: state.web3Connections.filter((s) => s.id !== sessionId) })); }, + joinExistingWallet: async () => { + if (!fireblocksNCW) { + throw new Error("fireblocksNCW is not initialized"); + } + await fireblocksNCW.joinExistingWallet(); + }, + approveJoinWallet: async () => { + if (!fireblocksNCW) { + throw new Error("fireblocksNCW is not initialized"); + } + await fireblocksNCW.approveJoinWallet(); + }, generateMPCKeys: async () => { if (!fireblocksNCW) { throw new Error("fireblocksNCW is not initialized"); diff --git a/src/IAppState.ts b/src/IAppState.ts index 19978b5..107f26c 100644 --- a/src/IAppState.ts +++ b/src/IAppState.ts @@ -45,6 +45,8 @@ export interface IAppState { loginToDemoAppServer: () => void; assignCurrentDevice: () => Promise; generateNewDeviceId: () => Promise; + joinExistingWallet: () => Promise; + approveJoinWallet: () => Promise; generateMPCKeys: () => Promise; stopMpcDeviceSetup: () => Promise; createTransaction: () => Promise; diff --git a/src/components/GenerateMPCKeys.tsx b/src/components/GenerateMPCKeys.tsx index 9b32ac8..35e67e7 100644 --- a/src/components/GenerateMPCKeys.tsx +++ b/src/components/GenerateMPCKeys.tsx @@ -8,8 +8,10 @@ export const GenerateMPCKeys: React.FC = () => { const [err, setErr] = React.useState(null); const [isGenerateInProgress, setIsGenerateInProgress] = React.useState(false); const [isStopInProgress, setIsStopInProgress] = React.useState(false); + const [isJoinExistingInProgress, setIsJoinExistingInProgress] = React.useState(false); + const [isApproveJoinWalletInProgress, setIsApproveJoinWalletInProgress] = React.useState(false); const [generateMPCKeysResult, setGenerateMPCKeysResult] = React.useState(null); - const { keysStatus, generateMPCKeys, stopMpcDeviceSetup } = useAppStore(); + const { keysStatus, generateMPCKeys, stopMpcDeviceSetup, joinExistingWallet, approveJoinWallet } = useAppStore(); const doGenerateMPCKeys = async () => { setGenerateMPCKeysResult(null); @@ -51,6 +53,40 @@ export const GenerateMPCKeys: React.FC = () => { } }; + const doJoinExistingWallet = async () => { + setErr(null); + setIsJoinExistingInProgress(true); + try { + await joinExistingWallet(); + setIsJoinExistingInProgress(false); + } catch (err: unknown) { + if (err instanceof Error) { + setErr(err.message); + } else { + setErr("Unknown Error"); + } + } finally { + setIsJoinExistingInProgress(false); + } + }; + + const doApproveJoinWallet = async () => { + setErr(null); + setIsApproveJoinWalletInProgress(true); + try { + await approveJoinWallet(); + setIsApproveJoinWalletInProgress(false); + } catch (err: unknown) { + if (err instanceof Error) { + setErr(err.message); + } else { + setErr("Unknown Error"); + } + } finally { + setIsApproveJoinWalletInProgress(false); + } + }; + const secP256K1Status = keysStatus?.MPC_CMP_ECDSA_SECP256K1?.keyStatus ?? null; const statusToProgress = (status: TKeyStatus | null) => { switch (status) { @@ -70,22 +106,42 @@ export const GenerateMPCKeys: React.FC = () => { }; const secP256K1Ready = secP256K1Status === "READY"; + const anyActionInProgress = + isApproveJoinWalletInProgress || isJoinExistingInProgress || isStopInProgress || isGenerateInProgress; + const generateAction: ICardAction = { label: "Generate MPC Keys", action: doGenerateMPCKeys, - isDisabled: isGenerateInProgress || secP256K1Ready, + isDisabled: anyActionInProgress || secP256K1Ready, isInProgress: isGenerateInProgress, }; const stopAction: ICardAction = { label: "Stop MPC Device Setup", action: doStopMPCDeviceSetup, - isDisabled: isStopInProgress || !isGenerateInProgress, + isDisabled: anyActionInProgress || !isGenerateInProgress, isInProgress: isStopInProgress, }; + const joinExistingWalletAction: ICardAction = { + action: doJoinExistingWallet, + isDisabled: anyActionInProgress || secP256K1Ready, + label: "Join Existing Wallet", + isInProgress: isJoinExistingInProgress, + }; + + const approveJoinWalletAction: ICardAction = { + action: doApproveJoinWallet, + isDisabled: anyActionInProgress || secP256K1Ready, + label: "Approve Join Wallet", + isInProgress: isJoinExistingInProgress, + }; + return ( - +
{/* head */} diff --git a/yarn.lock b/yarn.lock index 124bafd..74951ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -732,19 +732,19 @@ resolved "https://registry.npmjs.org/@firebase/webchannel-wrapper/-/webchannel-wrapper-0.10.3.tgz" integrity sha512-+ZplYUN3HOpgCfgInqgdDAbkGGVzES1cs32JJpeqoh87SkRobGXElJx+1GZSaDqzFL+bYiX18qEcBK76mYs8uA== -"@fireblocks/ncw-js-infra@^1.0.12": - version "1.0.12" - resolved "https://registry.npmjs.org/@fireblocks/ncw-js-infra/-/ncw-js-infra-1.0.12.tgz" - integrity sha512-IT97nVqI0kDWVNeOZSq56bxvNt1ceILq3b464GhXVn2H9rA9L4d/XqKl+wcnpJVReQNP7gUSp8NxWCCeoed4dA== +"@fireblocks/ncw-js-infra@^1.0.13": + version "1.0.13" + resolved "https://registry.yarnpkg.com/@fireblocks/ncw-js-infra/-/ncw-js-infra-1.0.13.tgz#0116b05bfdec10016c24ac0fb9889432ac0c3c9d" + integrity sha512-VVR1J0MRc0ppzoWcSJjQNF0Ah2cQ8ysSjp9tvS6DvlN17oUlb1A/xceeIY8tW6zAgwFv/ZjAb+5QR9AaDjTE6g== dependencies: "@types/emscripten" "^1.39.7" -"@fireblocks/ncw-js-sdk@^9.3.1": - version "9.3.1" - resolved "https://registry.yarnpkg.com/@fireblocks/ncw-js-sdk/-/ncw-js-sdk-9.3.1.tgz#84ef4d9dd1d17ae967a0af0866ec7abee4fb0cd6" - integrity sha512-otdWkifgsuOdA5a8IMWsmnZypl+xQx2h41YvBbc5HKNviou1d2ig1QJn+2o2Sy0GdaN/56J9vmL7W/y2wWBz1g== +"@fireblocks/ncw-js-sdk@^9.5.0": + version "9.5.0" + resolved "https://registry.yarnpkg.com/@fireblocks/ncw-js-sdk/-/ncw-js-sdk-9.5.0.tgz#65cbc16fafb9df4c2af0ae4d04b5ddb572fd0fc0" + integrity sha512-/2hTgOnxbeiEVyY8PUpOK/3idbk1qyiDCUbDap2hS7GciXawdsCTslrcsZ36fEUd/I+AYmvger+RdmW/Vs15jg== dependencies: - "@fireblocks/ncw-js-infra" "^1.0.12" + "@fireblocks/ncw-js-infra" "^1.0.13" "@types/jwt-decode" "^3.1.0" "@types/node-forge" "^1.3.4" jwt-decode "^3.1.2"