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

feat(signPsbt): add txid to return payload #6078

Merged
merged 1 commit into from
Jan 22, 2025
Merged
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
1 change: 1 addition & 0 deletions src/app/components/info-card/info-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export function InfoCardFooter({ children }: InfoCardFooterProps) {
alignItems="center"
bg={{ base: 'ink.background-primary', md: '' }}
bottom="0"
left="0"
justifyContent="center"
p="space.05"
position={{ base: 'fixed', md: 'unset' }}
Expand Down
48 changes: 37 additions & 11 deletions src/app/pages/rpc-sign-psbt/use-rpc-sign-psbt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface BroadcastSignedPsbtTxArgs {
addressTaprootTotal: Money;
fee: Money;
tx: string;
psbt: string;
}
export function useRpcSignPsbt() {
const navigate = useNavigate();
Expand All @@ -52,18 +53,29 @@ export function useRpcSignPsbt() {
addressTaprootTotal,
fee,
tx,
psbt,
}: BroadcastSignedPsbtTxArgs) {
void analytics.track('user_approved_sign_and_broadcast_psbt', {
origin: origin || 'no_origin',
});

const transferTotalAsMoney = sumMoney([addressNativeSegwitTotal, addressTaprootTotal]);

await broadcastTx({
return await broadcastTx({
tx,
// skip utxos check for psbt txs
skipSpendableCheckUtxoIds: 'all',
async onSuccess(txid) {
if (!requestId) throw new Error('Invalid request id');

chrome.tabs.sendMessage(
tabId,
makeRpcSuccessResponse('signPsbt', {
id: requestId,
result: { hex: psbt, txid },
})
);

await filteredUtxosQuery.refetch();

const psbtTxSummaryState = {
Expand All @@ -83,6 +95,15 @@ export function useRpcSignPsbt() {
navigate(RouteUrls.RpcSignPsbtSummary, { state: psbtTxSummaryState });
},
onError(e) {
if (!requestId) throw new Error('Invalid request id');

chrome.tabs.sendMessage(
tabId,
makeRpcErrorResponse('signPsbt', {
id: requestId,
error: { code: 4002, message: 'Failed to broadcast transaction' },
})
);
navigate(RouteUrls.RequestError, {
state: { message: isError(e) ? e.message : '', title: 'Failed to broadcast' },
});
Expand All @@ -106,16 +127,27 @@ export function useRpcSignPsbt() {

const psbt = signedTx.toPSBT();

chrome.tabs.sendMessage(
tabId,
makeRpcSuccessResponse('signPsbt', { id: requestId, result: { hex: bytesToHex(psbt) } })
);
if (!broadcast) {
chrome.tabs.sendMessage(
tabId,
makeRpcSuccessResponse('signPsbt', { id: requestId, result: { hex: bytesToHex(psbt) } })
);
return;
}

// Optional args are handled here bc we support two request apis,
// but we only support broadcasting using the rpc request method
if (broadcast && addressNativeSegwitTotal && addressTaprootTotal && fee) {
try {
signedTx.finalize();

await broadcastSignedPsbtTx({
addressNativeSegwitTotal,
addressTaprootTotal,
fee,
tx: signedTx.hex,
psbt: bytesToHex(psbt),
});
} catch (e) {
return navigate(RouteUrls.RequestError, {
state: {
Expand All @@ -125,12 +157,6 @@ export function useRpcSignPsbt() {
});
}

await broadcastSignedPsbtTx({
addressNativeSegwitTotal,
addressTaprootTotal,
fee,
tx: signedTx.hex,
});
return;
}
closeWindow();
Expand Down
2 changes: 1 addition & 1 deletion tests/page-object-models/onboarding.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createCounter, delay } from '@leather.io/utils';

import { RouteUrls } from '@shared/route-urls';

const TEST_ACCOUNT_SECRET_KEY = process.env.TEST_ACCOUNT_SECRET_KEY ?? '';
export const TEST_ACCOUNT_SECRET_KEY = process.env.TEST_ACCOUNT_SECRET_KEY ?? '';

// If default wallet state changes, we'll need to update this
export const testSoftwareAccountDefaultWalletState = {
Expand Down
Loading
Loading