Skip to content

Commit

Permalink
Merge pull request #1292 from alephium/fix-consolidation
Browse files Browse the repository at this point in the history
Fix consolidation
  • Loading branch information
nop33 authored Feb 27, 2025
2 parents c87d104 + f006d29 commit 30cff33
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 72 deletions.
2 changes: 1 addition & 1 deletion apps/desktop-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alephium-desktop-wallet",
"description": "The official Alephium wallet",
"version": "3.0.0-rc.1",
"version": "3.0.0-rc.2",
"author": "Alephium dev <dev@alephium.org>",
"main": "dist-electron/main.js",
"homepage": "./",
Expand Down
147 changes: 79 additions & 68 deletions apps/desktop-wallet/src/features/send/SendModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,83 +125,92 @@ function SendModal<PT extends { fromAddress: Address }>({
setUnsignedTxId,
setContractAddress,
isSweeping,
consolidationRequired,
buildExecuteScriptTxResult,
setBuildExecuteScriptTxResult
}),
[buildExecuteScriptTxResult, consolidationRequired, isSweeping, sweepUnsignedTxs, unsignedTransaction, unsignedTxId]
[buildExecuteScriptTxResult, isSweeping, sweepUnsignedTxs, unsignedTransaction, unsignedTxId]
)

const handleSendExtended = useCallback(async () => {
if (!transactionData) return
const handleSendExtended = useCallback(
async (consolidationRequired: boolean) => {
if (!transactionData) return

setIsLoading(isLedger ? t('Please, confirm the transaction on your Ledger.') : true)
setIsLoading(isLedger ? t('Please, confirm the transaction on your Ledger.') : true)

try {
const signature =
type === 'transfer'
? await handleTransferSend(transactionData as TransferTxData, txContext, posthog, isLedger, onLedgerError)
: type === 'call-contract'
? await handleCallContractSend(
transactionData as CallContractTxData,
txContext,
posthog,
isLedger,
onLedgerError
)
: await handleDeployContractSend(
transactionData as DeployContractTxData,
try {
const signature =
type === 'transfer'
? await handleTransferSend(
transactionData as TransferTxData,
txContext,
posthog,
isLedger,
onLedgerError
onLedgerError,
consolidationRequired
)

if (signature && triggeredByWalletConnect) {
const result =
type === 'transfer'
? getTransferWalletConnectResult(txContext, signature)
: type === 'call-contract'
? getCallContractWalletConnectResult(txContext, signature)
: getDeployContractWalletConnectResult(txContext, signature, contractAddress)

sendSuccessResponse(result)
}
? await handleCallContractSend(
transactionData as CallContractTxData,
txContext,
posthog,
isLedger,
onLedgerError
)
: await handleDeployContractSend(
transactionData as DeployContractTxData,
txContext,
posthog,
isLedger,
onLedgerError
)

if (signature && triggeredByWalletConnect) {
const result =
type === 'transfer'
? getTransferWalletConnectResult(txContext, signature)
: type === 'call-contract'
? getCallContractWalletConnectResult(txContext, signature)
: getDeployContractWalletConnectResult(txContext, signature, contractAddress)

sendSuccessResponse(result)
}

dispatch(transactionsSendSucceeded({ nbOfTransactionsSent: isSweeping ? sweepUnsignedTxs.length : 1 }))
setStep('tx-sent')
} catch (error) {
dispatch(transactionSendFailed(getHumanReadableError(error, t('Error while sending the transaction'))))
sendAnalytics({ type: 'error', message: 'Could not send tx' })

if (triggeredByWalletConnect) {
sendFailureResponse({
message: getHumanReadableError(error, 'Error while sending the transaction'),
code: WALLETCONNECT_ERRORS.TRANSACTION_SEND_FAILED
})
dispatch(closeModal({ id }))
dispatch(transactionsSendSucceeded({ nbOfTransactionsSent: isSweeping ? sweepUnsignedTxs.length : 1 }))
setStep('tx-sent')
} catch (error) {
dispatch(transactionSendFailed(getHumanReadableError(error, t('Error while sending the transaction'))))
sendAnalytics({ type: 'error', message: 'Could not send tx' })

if (triggeredByWalletConnect) {
sendFailureResponse({
message: getHumanReadableError(error, 'Error while sending the transaction'),
code: WALLETCONNECT_ERRORS.TRANSACTION_SEND_FAILED
})
dispatch(closeModal({ id }))
}
} finally {
setIsLoading(false)
}
} finally {
setIsLoading(false)
}
}, [
contractAddress,
dispatch,
id,
isLedger,
isSweeping,
onLedgerError,
posthog,
sendAnalytics,
sendFailureResponse,
sendSuccessResponse,
sweepUnsignedTxs.length,
t,
transactionData,
triggeredByWalletConnect,
txContext,
type
])
},
[
contractAddress,
dispatch,
id,
isLedger,
isSweeping,
onLedgerError,
posthog,
sendAnalytics,
sendFailureResponse,
sendSuccessResponse,
sweepUnsignedTxs.length,
t,
transactionData,
triggeredByWalletConnect,
txContext,
type
]
)

const goToAddresses = useCallback(() => setStep('addresses'), [])
const goToBuildTx = useCallback(() => setStep('build-tx'), [])
Expand Down Expand Up @@ -243,7 +252,9 @@ function SendModal<PT extends { fromAddress: Address }>({
name: 'ConsolidateUTXOsModal',
props: {
fee: fees,
onConsolidateClick: passwordRequirement ? () => setStep('password-check') : handleSendExtended
onConsolidateClick: passwordRequirement
? () => setStep('password-check')
: () => handleSendExtended(true)
}
})
)
Expand Down Expand Up @@ -352,23 +363,23 @@ function SendModal<PT extends { fromAddress: Address }>({
<TransferCheckTxModalContent
data={transactionData as TransferTxData}
fees={fees}
onSubmit={passwordRequirement ? goToPasswordCheck : handleSendExtended}
onSubmit={passwordRequirement ? goToPasswordCheck : () => handleSendExtended(consolidationRequired)}
onBack={goToBuildTx}
dAppUrl={dAppUrl}
/>
) : type === 'call-contract' ? (
<CallContractCheckTxModalContent
data={transactionData as CallContractTxData}
fees={fees}
onSubmit={passwordRequirement ? goToPasswordCheck : handleSendExtended}
onSubmit={passwordRequirement ? goToPasswordCheck : () => handleSendExtended(consolidationRequired)}
onBack={goToBuildTx}
dAppUrl={dAppUrl}
/>
) : (
<DeployContractCheckTxModalContent
data={transactionData as DeployContractTxData}
fees={fees}
onSubmit={passwordRequirement ? goToPasswordCheck : handleSendExtended}
onSubmit={passwordRequirement ? goToPasswordCheck : () => handleSendExtended(consolidationRequired)}
onBack={goToBuildTx}
dAppUrl={dAppUrl}
/>
Expand All @@ -378,7 +389,7 @@ function SendModal<PT extends { fromAddress: Address }>({
text={t('Enter your password to send the transaction.')}
buttonText={t('Send')}
highlightButton
onCorrectPasswordEntered={handleSendExtended}
onCorrectPasswordEntered={() => handleSendExtended(consolidationRequired)}
onBack={goToInfoCheck}
>
<PasswordConfirmationNote>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ export const handleTransferSend = async (
context: TxContext,
posthog: PostHog,
isLedger: boolean,
onLedgerError: (error: Error) => void
onLedgerError: (error: Error) => void,
consolidationRequired: boolean
) => {
const { fromAddress, toAddress, lockTime: lockDateTime, assetAmounts } = transactionData
const { isSweeping, sweepUnsignedTxs, consolidationRequired, unsignedTxId, unsignedTransaction } = context
const { isSweeping, sweepUnsignedTxs, unsignedTxId, unsignedTransaction } = context

if (toAddress) {
const { attoAlphAmount, tokens } = getTransactionAssetAmounts(assetAmounts)
Expand Down
1 change: 0 additions & 1 deletion apps/desktop-wallet/src/features/send/sendTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export type TxContext = {
setUnsignedTxId: (txId: string) => void
setContractAddress: (contractAddress: string) => void
isSweeping: boolean
consolidationRequired: boolean
buildExecuteScriptTxResult: node.BuildExecuteScriptTxResult | undefined
setBuildExecuteScriptTxResult: (tx: node.BuildExecuteScriptTxResult | undefined) => void
}

0 comments on commit 30cff33

Please sign in to comment.