Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added two buttons to allow join to wallet #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions src/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ export const useAppStore = create<IAppState>()((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");
Expand Down
2 changes: 2 additions & 0 deletions src/IAppState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface IAppState {
loginToDemoAppServer: () => void;
assignCurrentDevice: () => Promise<void>;
generateNewDeviceId: () => Promise<void>;
joinExistingWallet: () => Promise<void>;
approveJoinWallet: () => Promise<boolean>;
generateMPCKeys: () => Promise<void>;
stopMpcDeviceSetup: () => Promise<void>;
createTransaction: () => Promise<void>;
Expand Down
64 changes: 60 additions & 4 deletions src/components/GenerateMPCKeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export const GenerateMPCKeys: React.FC = () => {
const [err, setErr] = React.useState<string | null>(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<string | null>(null);
const { keysStatus, generateMPCKeys, stopMpcDeviceSetup } = useAppStore();
const { keysStatus, generateMPCKeys, stopMpcDeviceSetup, joinExistingWallet, approveJoinWallet } = useAppStore();

const doGenerateMPCKeys = async () => {
setGenerateMPCKeysResult(null);
Expand Down Expand Up @@ -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) {
Expand All @@ -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 (
<Card title="Generate MPC Keys" actions={[generateAction, stopAction]}>
<Card
title="Generate MPC Keys"
actions={[joinExistingWalletAction, approveJoinWalletAction, generateAction, stopAction]}
>
<div className="overflow-x-auto">
<table className="table">
{/* head */}
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down