-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: handle Ledger EVM transactions when blind signing is dis…
…abled (#434) * Add Ledger verification prompt for L2 tx * Refactor function for calculating tx value * Align UI wording with that of the ETH Ledger app * Cleanup code * Fix type check * Add logic for getting app settings * Get logic hooked up * Fix imports * Make changes per PR review * Bring close popup outside of if statement * Add logic for detecting and displaying blind signing popup * Refine logic around the send flow * Remove global polling * Fix logic around polling for Ethereum app settings * Remove unnecessary callback * refactor: combine ledger status * refactor: cleanup files * rename ledgerNanoStatus -> ledgerNanoState * refactor: more name improvements * fix use of app name * Rename to Ledger device state * Fix conditional in component * Use alert box from UI kit * Cleanup import * fix: code quality * Fix PR comments * Fix linting issue * fix: ledger api polling Co-authored-by: Matthew Maxwell <[email protected]> * chore: update polling intervals * Change constant name * Cleanup logic and bugs for EVM * Fix blind signing for L1 transactions * Make small improvements --------- Co-authored-by: Nicole O'Brien <[email protected]> Co-authored-by: Matthew Maxwell <[email protected]>
- Loading branch information
1 parent
0b9dc4b
commit 49b5396
Showing
56 changed files
with
425 additions
and
310 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
59 changes: 22 additions & 37 deletions
59
packages/desktop/components/popups/EnableLedgerBlindSigningPopup.svelte
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,50 +1,35 @@ | ||
<script lang="ts"> | ||
import { Text, Icon, TextType } from '@ui' | ||
import { Icon as IconEnum } from '@auxiliary/icon' | ||
import { onDestroy } from 'svelte' | ||
import { Alert } from '@bloomwalletio/ui' | ||
import { localize } from '@core/i18n' | ||
import { | ||
checkOrConnectLedger, | ||
ledgerNanoStatus, | ||
ledgerPreparedOutput, | ||
resetLedgerPreparedOutput, | ||
} from '@core/ledger' | ||
import { LedgerAppName, ledgerDeviceState } from '@core/ledger' | ||
import { closePopup } from '@desktop/auxiliary/popup' | ||
import { sendOutput } from '@core/wallet' | ||
import { handleError } from '@core/error/handlers' | ||
import { Text, TextType } from '@ui' | ||
import { UiEventFunction } from '@core/utils' | ||
export let appName: LedgerAppName | ||
export let onEnabled: UiEventFunction = () => {} | ||
export let onClose: UiEventFunction = () => {} | ||
const STEPS = [1, 2, 3, 4] | ||
$: if ($ledgerNanoStatus.blindSigningEnabled) { | ||
closePopup() | ||
checkOrConnectLedger(async () => { | ||
try { | ||
if ($ledgerPreparedOutput) { | ||
await sendOutput($ledgerPreparedOutput) | ||
resetLedgerPreparedOutput() | ||
} | ||
} catch (err) { | ||
handleError(err) | ||
} | ||
}) | ||
$: if ($ledgerDeviceState && $ledgerDeviceState.settings[appName]?.blindSigningEnabled) { | ||
closePopup(true) | ||
onEnabled && onEnabled() | ||
} | ||
onDestroy(() => { | ||
onClose && onClose() | ||
}) | ||
</script> | ||
|
||
<Text type={TextType.h3} classes="mb-6">{localize('popups.enableLedgerBlindSigning.title')}</Text> | ||
|
||
<div class="w-full h-full space-y-2 flex flex-auto flex-col shrink-0"> | ||
<div class="bg-yellow-50 w-full h-full space-y-6 rounded-md px-6 py-4"> | ||
<span class="flex flex-row items-center space-x-4"> | ||
<Icon boxed height={18} width={18} icon={IconEnum.InfoFilled} classes="text-yellow-700" /> | ||
<Text type={TextType.p} fontSize="14" color="gray-700" darkColor="gray-700" | ||
>{localize('popups.enableLedgerBlindSigning.info')}</Text | ||
> | ||
</span> | ||
</div> | ||
<div> | ||
{#each STEPS as step} | ||
<Text type={TextType.p} fontSize="15" color="gray-600" classes="my-2"> | ||
{step}. {localize(`popups.enableLedgerBlindSigning.step_${step}`)} | ||
</Text> | ||
{/each} | ||
</div> | ||
<Alert variant="warning" text={localize('popups.enableLedgerBlindSigning.info')} /> | ||
{#each STEPS as step} | ||
<Text type={TextType.p} fontSize="15" color="gray-600"> | ||
{step}. {localize(`popups.enableLedgerBlindSigning.step_${step}`, { appName })} | ||
</Text> | ||
{/each} | ||
</div> |
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
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
32 changes: 32 additions & 0 deletions
32
packages/shared/src/lib/core/ledger/actions/getAndUpdateLedgerDeviceState.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,32 @@ | ||
import { profileManager as _profileManager } from '@core/profile-manager/stores' | ||
import { getLedgerNanoStatus } from '@lib/core/profile-manager/api' | ||
import { Ledger } from '../classes' | ||
import { resetLedgerDeviceState, setLedgerDeviceState } from '../stores' | ||
import { sleep } from '@core/utils' | ||
|
||
let isMakingRequest: boolean = false | ||
|
||
export async function getAndUpdateLedgerDeviceState( | ||
profileManager = _profileManager, | ||
forwardErrors = false | ||
): Promise<void> { | ||
try { | ||
if (!isMakingRequest) { | ||
isMakingRequest = true | ||
const ledgerNanoStatus = await getLedgerNanoStatus(profileManager) | ||
// sleep to make sure ledger process on iota sdk is wrapped up | ||
await sleep(50) | ||
const ethereumAppSettings = await Ledger.getEthereumAppSettings() | ||
setLedgerDeviceState(ledgerNanoStatus, ethereumAppSettings) | ||
} | ||
} catch (err) { | ||
resetLedgerDeviceState() | ||
if (forwardErrors) { | ||
return Promise.reject(err) | ||
} else { | ||
console.error(err) | ||
} | ||
} finally { | ||
isMakingRequest = false | ||
} | ||
} |
Oops, something went wrong.