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

fix: send transfer success response #3601

Merged
merged 1 commit into from
Apr 26, 2023
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
22 changes: 20 additions & 2 deletions src/app/pages/rpc-send-transfer/rpc-send-transfer-confirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { decodeBitcoinTx } from '@shared/crypto/bitcoin/bitcoin.utils';
import { logger } from '@shared/logger';
import { createMoney, createMoneyFromDecimal } from '@shared/models/money.model';
import { RouteUrls } from '@shared/route-urls';
import { makeRpcSuccessResponse } from '@shared/rpc/rpc-methods';

import { useAnalytics } from '@app/common/hooks/analytics/use-analytics';
import { baseCurrencyAmountInQuote } from '@app/common/money/calculate-money';
Expand All @@ -19,6 +20,7 @@ import { useCurrentBtcNativeSegwitAccountAddressIndexZero } from '@app/store/acc

import { SendTransferActions } from './components/send-transfer-actions';
import { SendTransferConfirmationDetails } from './components/send-transfer-confirmation-details';
import { useRpcSendTransferRequestParams } from './use-rpc-send-transfer';

const symbol = 'BTC';

Expand All @@ -35,6 +37,7 @@ function useRpcSendTransferConfirmationState() {
export function RpcSendTransferConfirmation() {
const analytics = useAnalytics();
const navigate = useNavigate();
const { origin, requestId, tabId } = useRpcSendTransferRequestParams();
const { fee, recipient, time, tx } = useRpcSendTransferConfirmationState();
const bitcoinAddress = useCurrentBtcNativeSegwitAccountAddressIndexZero();
const { broadcastTx, isBroadcasting } = useBitcoinBroadcastTransaction();
Expand Down Expand Up @@ -74,7 +77,13 @@ export function RpcSendTransferConfirmation() {
};
}

async function initiateTransaction() {
async function onUserApproveSendTransferRequest() {
if (!tabId || !origin) {
logger.error('Cannot send transfer: missing tabId, origin');
return;
}
void analytics.track('user_approved_send_transfer', { origin });

await broadcastTx({
tx,
async onSuccess(txid) {
Expand All @@ -86,6 +95,15 @@ export function RpcSendTransferConfirmation() {
outputs: psbt.inputs.length,
});
await refetch();

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

navigate(RouteUrls.RpcSendTransferSummary, {
state: formBtcTxSummaryState(txid),
});
Expand All @@ -109,7 +127,7 @@ export function RpcSendTransferConfirmation() {
<SendTransferActions
action="Send"
isLoading={isBroadcasting}
onApprove={initiateTransaction}
onApprove={onUserApproveSendTransferRequest}
/>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/rpc-send-transfer/use-rpc-send-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useDefaultRequestParams } from '@app/common/hooks/use-default-request-s
import { initialSearchParams } from '@app/common/initial-search-params';
import { useWalletType } from '@app/common/use-wallet-type';

function useRpcSendTransferRequestParams() {
export function useRpcSendTransferRequestParams() {
const defaultParams = useDefaultRequestParams();
return useMemo(
() => ({
Expand Down