Skip to content

Commit

Permalink
feat: begin implementing import approval steps
Browse files Browse the repository at this point in the history
  • Loading branch information
jurevans committed Jan 10, 2025
1 parent 7afd599 commit 14cd8e6
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 39 deletions.
5 changes: 0 additions & 5 deletions apps/extension/src/App/Accounts/UpdateRequired.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ export const UpdateRequired = (): JSX.Element => {
</li>
</ol>
</Stack>
<p className="text-yellow text-center leading-3">
* Ledger accounts will receive shielded
<br /> functions in a separate update in an
<br /> upcoming release
</p>
</Stack>
</div>
</div>
Expand Down
46 changes: 46 additions & 0 deletions apps/extension/src/Setup/Common/LedgerApprovalStep.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Heading, ProgressIndicator, Stack } from "@namada/components";

type LedgerApprovalStepProps = {
currentApprovalStep: number;
};

export const LedgerApprovalStep = ({
currentApprovalStep,
}: LedgerApprovalStepProps): JSX.Element => {
const stepText = [
"Deriving Bip44 public key...",
"Deriving Zip32 Viewing Key... This could take a few seconds!",
"Deriving Zip32 Proof-Generation Key... This could take a few seconds!",
];

// Ensure that steps are within stepText limits
const totalSteps = stepText.length;
const currentStep = Math.min(Math.max(currentApprovalStep, 1), totalSteps);

return (
<Stack gap={1} className="bg-black w-full p-4 rounded-md min-h-[240px]">
<Stack direction="horizontal" className="flex">
<span className="flex-none">
<ProgressIndicator
keyName="ledger-import"
totalSteps={totalSteps}
currentStep={currentStep}
/>
</span>
<span className="flex-1 text-white font-medium text-right">
Approval {currentStep}/{totalSteps}
</span>
</Stack>
<Heading
level="h2"
className="text-base text-center text-white font-medium"
>
Please wait for Ledger to respond!
</Heading>
{/* TODO: STYLE! */}
<p className="font-medium text-yellow text-base text-center px-12">
{stepText[currentStep - 1]}
</p>
</Stack>
);
};
76 changes: 43 additions & 33 deletions apps/extension/src/Setup/Ledger/LedgerConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { LedgerError } from "@zondax/ledger-namada";
import { LedgerStep } from "Setup/Common";
import { AdvancedOptions } from "Setup/Common/AdvancedOptions";
import Bip44Form from "Setup/Common/Bip44Form";
import { LedgerApprovalStep } from "Setup/Common/LedgerApprovalStep";
import routes from "Setup/routes";
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
Expand All @@ -29,6 +30,9 @@ export const LedgerConnect: React.FC<Props> = ({ path, setPath }) => {
const [isLedgerConnecting, setIsLedgerConnecting] = useState(false);
const [ledger, setLedger] = useState<LedgerApp>();

// Import keys steps (transparent, viewing key, proof-gen key)
const [currentApprovalStep, setCurrentApprovalStep] = useState(1);

const queryLedger = async (ledger: LedgerApp): Promise<void> => {
setError(undefined);
try {
Expand All @@ -41,6 +45,7 @@ export const LedgerConnect: React.FC<Props> = ({ path, setPath }) => {
}

setIsLedgerConnecting(true);
setCurrentApprovalStep(1);
const { address, publicKey } = await ledger.showAddressAndPublicKey(
makeBip44Path(chains.namada.bip44.coinType, path)
);
Expand All @@ -49,7 +54,11 @@ export const LedgerConnect: React.FC<Props> = ({ path, setPath }) => {
const zip32Path = makeSaplingPath(chains.namada.bip44.coinType, {
account: path.account,
});

setCurrentApprovalStep(2);
const { xfvk } = await ledger.getViewingKey(zip32Path);

setCurrentApprovalStep(3);
const { ak, nsk } = await ledger.getProofGenerationKey(zip32Path);

// SDK wasm init must be called
Expand Down Expand Up @@ -119,48 +128,49 @@ export const LedgerConnect: React.FC<Props> = ({ path, setPath }) => {

return (
<Stack gap={6} className="justify-between min-h-[470px]">
<Stack
as="ol"
gap={4}
className="flex-1 justify-center mx-auto max-w-[400px]"
>
<Stack as="ol" gap={4} className="flex-1 justify-center mx-auto w-full">
{error && (
<Alert title="Error" type="error">
{error}
</Alert>
)}

{isLedgerConnecting && (
<Alert type="warning">Review on your Ledger</Alert>
<LedgerApprovalStep currentApprovalStep={currentApprovalStep} />
)}

<AdvancedOptions>
<Bip44Form path={path} setPath={setPath} />
</AdvancedOptions>

<LedgerStep
title="Step 1"
text="Connect and unlock your ledger Hardware Wallet"
onClick={() => connectUSB()}
active={!ledger}
complete={!!ledger}
buttonDisabled={!!ledger}
image={
<Image styleOverrides={{ width: "100%" }} imageName="Ledger" />
}
/>

<LedgerStep
title="Step 2"
text="Open the Namada App on your ledger device"
active={!!ledger}
complete={false}
onClick={() => connectNamadaApp()}
buttonDisabled={!ledger || isLedgerConnecting}
image={
<Image styleOverrides={{ width: "100%" }} imageName="LogoMinimal" />
}
/>
{!isLedgerConnecting && (
<>
<AdvancedOptions>
<Bip44Form path={path} setPath={setPath} />
</AdvancedOptions>
<LedgerStep
title="Step 1"
text="Connect and unlock your ledger Hardware Wallet"
onClick={() => connectUSB()}
active={!ledger}
complete={!!ledger}
buttonDisabled={!!ledger}
image={
<Image styleOverrides={{ width: "100%" }} imageName="Ledger" />
}
/>
<LedgerStep
title="Step 2"
text="Open the Namada App on your ledger device"
active={!!ledger}
complete={false}
onClick={() => connectNamadaApp()}
buttonDisabled={!ledger || isLedgerConnecting}
image={
<Image
styleOverrides={{ width: "100%" }}
imageName="LogoMinimal"
/>
}
/>
</>
)}
</Stack>
<ActionButton size="lg" disabled={true}>
Next
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/Setup/Setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export const Setup: React.FC = () => {
<Route
path={routes.ledgerComplete()}
element={
<Wrapper onLoad={setCurrentPage("Namada Keys Imported", 3)}>
<Wrapper onLoad={setCurrentPage("Ledger Keys Imported", 3)}>
<LedgerConfirmation />
</Wrapper>
}
Expand Down

0 comments on commit 14cd8e6

Please sign in to comment.