@@ -7,6 +7,7 @@ import { decodeBitcoinTx } from '@shared/crypto/bitcoin/bitcoin.utils';
7
7
import { logger } from '@shared/logger' ;
8
8
import { createMoney , createMoneyFromDecimal } from '@shared/models/money.model' ;
9
9
import { RouteUrls } from '@shared/route-urls' ;
10
+ import { makeRpcSuccessResponse } from '@shared/rpc/rpc-methods' ;
10
11
11
12
import { useAnalytics } from '@app/common/hooks/analytics/use-analytics' ;
12
13
import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money' ;
@@ -19,6 +20,7 @@ import { useCurrentBtcNativeSegwitAccountAddressIndexZero } from '@app/store/acc
19
20
20
21
import { SendTransferActions } from './components/send-transfer-actions' ;
21
22
import { SendTransferConfirmationDetails } from './components/send-transfer-confirmation-details' ;
23
+ import { useRpcSendTransferRequestParams } from './use-rpc-send-transfer' ;
22
24
23
25
const symbol = 'BTC' ;
24
26
@@ -35,6 +37,7 @@ function useRpcSendTransferConfirmationState() {
35
37
export function RpcSendTransferConfirmation ( ) {
36
38
const analytics = useAnalytics ( ) ;
37
39
const navigate = useNavigate ( ) ;
40
+ const { origin, requestId, tabId } = useRpcSendTransferRequestParams ( ) ;
38
41
const { fee, recipient, time, tx } = useRpcSendTransferConfirmationState ( ) ;
39
42
const bitcoinAddress = useCurrentBtcNativeSegwitAccountAddressIndexZero ( ) ;
40
43
const { broadcastTx, isBroadcasting } = useBitcoinBroadcastTransaction ( ) ;
@@ -74,7 +77,13 @@ export function RpcSendTransferConfirmation() {
74
77
} ;
75
78
}
76
79
77
- async function initiateTransaction ( ) {
80
+ async function onUserApproveSendTransferRequest ( ) {
81
+ if ( ! tabId || ! origin ) {
82
+ logger . error ( 'Cannot send transfer: missing tabId, origin' ) ;
83
+ return ;
84
+ }
85
+ void analytics . track ( 'user_approved_send_transfer' , { origin } ) ;
86
+
78
87
await broadcastTx ( {
79
88
tx,
80
89
async onSuccess ( txid ) {
@@ -86,6 +95,15 @@ export function RpcSendTransferConfirmation() {
86
95
outputs : psbt . inputs . length ,
87
96
} ) ;
88
97
await refetch ( ) ;
98
+
99
+ chrome . tabs . sendMessage (
100
+ tabId ,
101
+ makeRpcSuccessResponse ( 'sendTransfer' , {
102
+ id : requestId ,
103
+ result : { txid } ,
104
+ } )
105
+ ) ;
106
+
89
107
navigate ( RouteUrls . RpcSendTransferSummary , {
90
108
state : formBtcTxSummaryState ( txid ) ,
91
109
} ) ;
@@ -109,7 +127,7 @@ export function RpcSendTransferConfirmation() {
109
127
< SendTransferActions
110
128
action = "Send"
111
129
isLoading = { isBroadcasting }
112
- onApprove = { initiateTransaction }
130
+ onApprove = { onUserApproveSendTransferRequest }
113
131
/>
114
132
</ >
115
133
) ;
0 commit comments