Skip to content

Commit d879250

Browse files
committed
fix(scan): enhance slashtag processing in send flow
1 parent 1a83a4a commit d879250

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/utils/scanner/scanner.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
lnurlAddress as processLnurlAddress,
44
} from '@synonymdev/react-native-lnurl';
55
import { Result, err, ok } from '@synonymdev/result';
6+
import { parse } from '@synonymdev/slashtags-url';
67
import {
78
EAddressType,
89
EAvailableNetworks,
@@ -25,7 +26,11 @@ import {
2526
setupOnChainTransaction,
2627
updateBeignetSendTransaction,
2728
} from '../../store/actions/wallet';
28-
import { dispatch, getSettingsStore } from '../../store/helpers';
29+
import {
30+
dispatch,
31+
getSettingsStore,
32+
getSlashtagsStore,
33+
} from '../../store/helpers';
2934
import { closeSheet, updateSendTransaction } from '../../store/slices/ui';
3035
import { EDenomination } from '../../store/types/wallet';
3136
import { showBottomSheet } from '../../store/utils/ui';
@@ -106,21 +111,28 @@ export const processUri = async ({
106111
paymentData = data;
107112
}
108113

109-
// If we're in the send flow and the data is a slashtag, process for slashpay.
110-
if (source === 'send' && data.type === EQRDataType.slashtag) {
111-
const slashPayResult = await processSlashPayUrl(data.url);
112-
if (slashPayResult.isErr()) {
113-
if (showErrors) {
114-
showToast({
115-
type: 'warning',
116-
title: i18n.t('slashtags:error_pay_title'),
117-
description: slashPayResult.error.message,
118-
});
114+
if (data.type === EQRDataType.slashtag) {
115+
const isSend = source === 'send';
116+
const { contacts } = getSlashtagsStore();
117+
const parsed = parse(data.url);
118+
const hasAddedContact = contacts[parsed.id];
119+
120+
// If we're in the send flow or the contact has already been added, process for slashpay.
121+
if (isSend || hasAddedContact) {
122+
const slashPayResult = await processSlashPayUrl(data.url);
123+
if (slashPayResult.isErr()) {
124+
if (showErrors) {
125+
showToast({
126+
type: 'warning',
127+
title: i18n.t('slashtags:error_pay_title'),
128+
description: slashPayResult.error.message,
129+
});
130+
}
131+
return err(slashPayResult.error.message);
119132
}
120-
return err(slashPayResult.error.message);
121-
}
122133

123-
paymentData = slashPayResult.value;
134+
paymentData = slashPayResult.value;
135+
}
124136
}
125137

126138
// Validate and process payment data.

0 commit comments

Comments
 (0)