From e7b2b6a07e1f85280508a9269853b2c404d6dd83 Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Sat, 4 Nov 2023 19:45:31 +0100 Subject: [PATCH 1/2] fix(ledger): stacks contract call signing, closes #4478 --- .../transaction-request.tsx | 33 ++++++++--------- .../store/transactions/transaction.hooks.ts | 35 +------------------ 2 files changed, 18 insertions(+), 50 deletions(-) diff --git a/src/app/pages/transaction-request/transaction-request.tsx b/src/app/pages/transaction-request/transaction-request.tsx index 54b69a7bd49..36514eb0429 100644 --- a/src/app/pages/transaction-request/transaction-request.tsx +++ b/src/app/pages/transaction-request/transaction-request.tsx @@ -7,6 +7,7 @@ import get from 'lodash.get'; import * as yup from 'yup'; import { HIGH_FEE_WARNING_LEARN_MORE_URL_STX } from '@shared/constants'; +import { logger } from '@shared/logger'; import { FeeTypes } from '@shared/models/fees/fees.model'; import { StacksTransactionFormValues } from '@shared/models/form.model'; import { RouteUrls } from '@shared/route-urls'; @@ -15,7 +16,6 @@ import { useAnalytics } from '@app/common/hooks/analytics/use-analytics'; import { LoadingKeys, useLoading } from '@app/common/hooks/use-loading'; import { useOnMount } from '@app/common/hooks/use-on-mount'; import { useRouteHeader } from '@app/common/hooks/use-route-header'; -import { useWalletType } from '@app/common/use-wallet-type'; import { stxFeeValidator } from '@app/common/validation/forms/fee-validators'; import { nonceValidator } from '@app/common/validation/nonce-validators'; import { EditNonceButton } from '@app/components/edit-nonce-button'; @@ -23,7 +23,6 @@ import { NonceSetter } from '@app/components/nonce-setter'; import { PopupHeader } from '@app/features/current-account/popup-header'; import { RequestingTabClosedWarningMessage } from '@app/features/errors/requesting-tab-closed-error-msg'; import { HighFeeDrawer } from '@app/features/high-fee-drawer/high-fee-drawer'; -import { useLedgerNavigate } from '@app/features/ledger/hooks/use-ledger-navigate'; import { ContractCallDetails } from '@app/features/stacks-transaction-request/contract-call-details/contract-call-details'; import { ContractDeployDetails } from '@app/features/stacks-transaction-request/contract-deploy-details/contract-deploy-details'; import { FeeForm } from '@app/features/stacks-transaction-request/fee-form'; @@ -40,41 +39,43 @@ import { useNextNonce } from '@app/query/stacks/nonce/account-nonces.hooks'; import { useTransactionRequestState } from '@app/store/transactions/requests.hooks'; import { useGenerateUnsignedStacksTransaction, - useSoftwareWalletTransactionRequestBroadcast, + useSignStacksTransaction, + useStacksTransactionBroadcast, useUnsignedStacksTransactionBaseState, } from '@app/store/transactions/transaction.hooks'; function TransactionRequestBase() { const transactionRequest = useTransactionRequestState(); const { setIsLoading, setIsIdle } = useLoading(LoadingKeys.SUBMIT_TRANSACTION_REQUEST); - const handleBroadcastTransaction = useSoftwareWalletTransactionRequestBroadcast(); + // const handleBroadcastTransaction = useSoftwareWalletTransactionRequestBroadcast(); const unsignedTx = useUnsignedStacksTransactionBaseState(); const { data: stxFees } = useCalculateStacksTxFees(unsignedTx.transaction); const analytics = useAnalytics(); - const { walletType } = useWalletType(); const generateUnsignedTx = useGenerateUnsignedStacksTransaction(); const { data: stacksBalances } = useCurrentStacksAccountAnchoredBalances(); - const ledgerNavigate = useLedgerNavigate(); const { data: nextNonce } = useNextNonce(); const navigate = useNavigate(); + const signStacksTransaction = useSignStacksTransaction(); + const txBroadcast = useStacksTransactionBroadcast(); useRouteHeader(); - useOnMount(() => { - void analytics.track('view_transaction_signing'), [analytics]; - }); + useOnMount(() => void analytics.track('view_transaction_signing')); const onSubmit = async (values: StacksTransactionFormValues) => { - if (walletType === 'ledger') { - const tx = await generateUnsignedTx(values); - if (!tx) return; - ledgerNavigate.toConnectAndSignTransactionStep(tx); - return; - } + const unsignedTx = await generateUnsignedTx(values); + + if (!unsignedTx) + return logger.error('Failed to generate unsigned transaction in transaction-request'); + + const signedTx = await signStacksTransaction(unsignedTx); + + if (!signedTx) return logger.error('Failed to sign transaction in transaction-request'); + setIsLoading(); try { - await handleBroadcastTransaction(values); + await txBroadcast({ signedTx }); setIsIdle(); } catch (e) { navigate(RouteUrls.TransactionBroadcastError, { state: { message: get(e, 'message') } }); diff --git a/src/app/store/transactions/transaction.hooks.ts b/src/app/store/transactions/transaction.hooks.ts index 25f8049e0c8..21c884e5dba 100644 --- a/src/app/store/transactions/transaction.hooks.ts +++ b/src/app/store/transactions/transaction.hooks.ts @@ -95,7 +95,7 @@ export function useUnsignedPrepareTransactionDetails(values: StacksTransactionFo return useMemo(() => unsignedStacksTransaction, [unsignedStacksTransaction]); } -function useStacksTransactionBroadcast() { +export function useStacksTransactionBroadcast() { const submittedTransactionsActions = useSubmittedTransactionsActions(); const { tabId } = useDefaultRequestParams(); const requestToken = useTransactionRequest(); @@ -133,39 +133,6 @@ function useStacksTransactionBroadcast() { }; } -export function useSoftwareWalletTransactionRequestBroadcast() { - const { data: nextNonce } = useNextNonce(); - const signSoftwareWalletTx = useSignTransactionSoftwareWallet(); - const stacksTxBaseState = useUnsignedStacksTransactionBaseState(); - const { tabId } = useDefaultRequestParams(); - const requestToken = useTransactionRequest(); - const account = useCurrentStacksAccount(); - const txBroadcast = useStacksTransactionBroadcast(); - - return async (values: StacksTransactionFormValues) => { - if (!stacksTxBaseState) return; - const { options } = stacksTxBaseState as any; - const unsignedStacksTransaction = await generateUnsignedTransaction({ - ...options, - fee: stxToMicroStx(values.fee).toNumber(), - nonce: Number(values.nonce) ?? nextNonce?.nonce, - }); - - if (!account || !requestToken || !unsignedStacksTransaction) { - return { error: { message: 'No pending transaction' } }; - } - - if (!tabId) throw new Error('tabId not defined'); - - const signedTx = signSoftwareWalletTx(unsignedStacksTransaction); - if (!signedTx) { - logger.error('Cannot sign transaction, no account in state'); - return; - } - return txBroadcast({ signedTx }); - }; -} - interface PostConditionsOptions { contractAddress: string; contractAssetName: string; From 95476befb1ebcb1ed04b5db6c752900eb6d8d261 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sat, 4 Nov 2023 19:15:03 +0000 Subject: [PATCH 2/2] chore(release): 6.15.1 ## [6.15.1](https://github.com/leather-wallet/extension/compare/v6.15.0...v6.15.1) (2023-11-04) ### Bug Fixes * **ledger:** stacks contract call signing, closes [#4478](https://github.com/leather-wallet/extension/issues/4478) ([e7b2b6a](https://github.com/leather-wallet/extension/commit/e7b2b6a07e1f85280508a9269853b2c404d6dd83)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 944394783a7..8d7a2994583 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [6.15.1](https://github.com/leather-wallet/extension/compare/v6.15.0...v6.15.1) (2023-11-04) + + +### Bug Fixes + +* **ledger:** stacks contract call signing, closes [#4478](https://github.com/leather-wallet/extension/issues/4478) ([e7b2b6a](https://github.com/leather-wallet/extension/commit/e7b2b6a07e1f85280508a9269853b2c404d6dd83)) + ## [6.15.0](https://github.com/leather-wallet/extension/compare/v6.14.0...v6.15.0) (2023-11-02) diff --git a/package.json b/package.json index 0d3db2982d5..2e296e43080 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@stacks/wallet-web", "description": "Leather is browser extension for interacting with Stacks apps", "private": true, - "version": "6.15.0", + "version": "6.15.1", "author": "Hiro Systems PBC", "scripts": { "dev": "concurrently --raw \"node webpack/dev-server.js\" \"redux-devtools --hostname=localhost --port=8000\"",