@bsv/expo-wallet-toolbox 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.19.0
4
+
5
+ ### Added
6
+
7
+ - **The pay and receive screens use live payments.** These changes only
8
+ apply in a host that mounts `DirectPayProvider` with `directPay.enabled`
9
+ and `@bsv/webrtpay` installed. Without it, both screens behave as before.
10
+ - **`UniversalSend` pays live first.** For a handle or identity key, the
11
+ payment is delivered live when `canSendDirect`. When the recipient isn't
12
+ online, or the link can't come up and nothing was spent, it asks "X isn't
13
+ online right now. Send it to their message box?" and then uses the
14
+ message box rail. The success screen says when a payment was delivered
15
+ live.
16
+ - **`HandleReceive` shows a live status card.** "Open to live payments",
17
+ plus connecting, off and error states, for BSV receives.
18
+ - **New strings** `direct_pay_fallback_title`, `direct_pay_fallback_send`
19
+ and `direct_pay_sent_live`, in all 12 locales.
20
+
3
21
  ## 0.18.0
4
22
 
5
23
  ### Added
@@ -1238,6 +1238,9 @@ const resources = {
1238
1238
  'Your payment to {{name}} may already have been sent. Check Activity before paying again.',
1239
1239
  direct_pay_failed_not_sent: 'The payment could not be sent. Nothing was spent.',
1240
1240
  direct_pay_failed_no_message_box: 'Connect your message box in Settings to pay a wallet identity.',
1241
+ direct_pay_fallback_title: 'Not online right now',
1242
+ direct_pay_fallback_send: 'Send to message box',
1243
+ direct_pay_sent_live: 'Paid live: it\'s already in their wallet.',
1241
1244
  direct_pay_kept_needs_attention:
1242
1245
  'A direct payment of {{amount}} sats from {{name}} needs attention: your wallet could not add it. It stays on this device.'
1243
1246
  }
@@ -2282,6 +2285,9 @@ const resources = {
2282
2285
  direct_pay_failed_maybe_sent: '你向 {{name}} 的付款可能已经发出。再次付款前,请先查看“活动”。',
2283
2286
  direct_pay_failed_not_sent: '无法发送付款。未花费任何款项。',
2284
2287
  direct_pay_failed_no_message_box: '请在设置中连接消息箱,以便向钱包身份付款。',
2288
+ direct_pay_fallback_title: '对方当前不在线',
2289
+ direct_pay_fallback_send: '发送到消息箱',
2290
+ direct_pay_sent_live: '已实时付款:款项已到对方钱包。',
2285
2291
  direct_pay_kept_needs_attention: '来自 {{name}} 的 {{amount}} sats 直接付款需要处理:你的钱包无法添加它。它仍保存在此设备上。'
2286
2292
  }
2287
2293
  },
@@ -3404,6 +3410,9 @@ const resources = {
3404
3410
  direct_pay_failed_not_sent: 'भुगतान भेजा नहीं जा सका। कुछ भी खर्च नहीं हुआ।',
3405
3411
  direct_pay_failed_no_message_box:
3406
3412
  'किसी वॉलेट आइडेंटिटी को भुगतान करने के लिए सेटिंग्स में अपना मैसेज बॉक्स जोड़ें।',
3413
+ direct_pay_fallback_title: 'अभी ऑनलाइन नहीं',
3414
+ direct_pay_fallback_send: 'मैसेज बॉक्स में भेजें',
3415
+ direct_pay_sent_live: 'लाइव भुगतान हो गया: यह पहले से उनके वॉलेट में है।',
3407
3416
  direct_pay_kept_needs_attention:
3408
3417
  '{{name}} से {{amount}} sats के सीधे भुगतान पर ध्यान देना ज़रूरी है: आपका वॉलेट इसे जोड़ नहीं सका। यह इसी डिवाइस पर रखा है।'
3409
3418
  }
@@ -4544,6 +4553,9 @@ const resources = {
4544
4553
  direct_pay_failed_not_sent: 'No se pudo enviar el pago. No se gastó nada.',
4545
4554
  direct_pay_failed_no_message_box:
4546
4555
  'Conecta tu buzón de mensajes en Ajustes para pagar a una identidad de billetera.',
4556
+ direct_pay_fallback_title: 'No está en línea ahora',
4557
+ direct_pay_fallback_send: 'Enviar al buzón de mensajes',
4558
+ direct_pay_sent_live: 'Pagado en vivo: ya está en su billetera.',
4547
4559
  direct_pay_kept_needs_attention:
4548
4560
  'Un pago directo de {{amount}} sats de {{name}} necesita atención: tu billetera no pudo añadirlo. Se conserva en este dispositivo.'
4549
4561
  }
@@ -5698,6 +5710,9 @@ const resources = {
5698
5710
  direct_pay_failed_not_sent: "Le paiement n'a pas pu être envoyé. Rien n'a été dépensé.",
5699
5711
  direct_pay_failed_no_message_box:
5700
5712
  'Connectez votre boîte aux lettres dans les réglages pour payer une identité de portefeuille.',
5713
+ direct_pay_fallback_title: 'Pas en ligne pour le moment',
5714
+ direct_pay_fallback_send: 'Envoyer à la boîte aux lettres',
5715
+ direct_pay_sent_live: 'Payé en direct : c\'est déjà dans son portefeuille.',
5701
5716
  direct_pay_kept_needs_attention:
5702
5717
  "Un paiement direct de {{amount}} sats de {{name}} demande votre attention : votre portefeuille n'a pas pu l'ajouter. Il reste sur cet appareil."
5703
5718
  }
@@ -6778,6 +6793,9 @@ const resources = {
6778
6793
  direct_pay_failed_maybe_sent: 'ربما تم إرسال دفعتك إلى {{name}} بالفعل. تحقق من النشاط قبل الدفع مرة أخرى.',
6779
6794
  direct_pay_failed_not_sent: 'تعذّر إرسال الدفعة. لم يتم إنفاق أي مبلغ.',
6780
6795
  direct_pay_failed_no_message_box: 'اربط صندوق رسائلك من الإعدادات للدفع إلى هوية محفظة.',
6796
+ direct_pay_fallback_title: 'غير متصل الآن',
6797
+ direct_pay_fallback_send: 'أرسل إلى صندوق الرسائل',
6798
+ direct_pay_sent_live: 'تم الدفع مباشرة: المبلغ في محفظته بالفعل.',
6781
6799
  direct_pay_kept_needs_attention:
6782
6800
  'دفعة مباشرة بقيمة {{amount}} sats من {{name}} تحتاج إلى انتباهك: لم تتمكن محفظتك من إضافتها. تبقى محفوظة على هذا الجهاز.'
6783
6801
  }
@@ -7917,6 +7935,9 @@ const resources = {
7917
7935
  direct_pay_failed_not_sent: 'Não foi possível enviar o pagamento. Nada foi gasto.',
7918
7936
  direct_pay_failed_no_message_box:
7919
7937
  'Conecte sua caixa de mensagens em Configurações para pagar uma identidade de carteira.',
7938
+ direct_pay_fallback_title: 'Não está online agora',
7939
+ direct_pay_fallback_send: 'Enviar para a caixa de mensagens',
7940
+ direct_pay_sent_live: 'Pago ao vivo: já está na carteira da pessoa.',
7920
7941
  direct_pay_kept_needs_attention:
7921
7942
  'Um pagamento direto de {{amount}} sats de {{name}} precisa de atenção: sua carteira não conseguiu adicioná-lo. Ele continua neste dispositivo.'
7922
7943
  }
@@ -9034,6 +9055,9 @@ const resources = {
9034
9055
  '{{name}}-এর কাছে আপনার পেমেন্ট হয়তো ইতিমধ্যে পাঠানো হয়ে গেছে। আবার পেমেন্ট করার আগে কার্যকলাপ দেখুন।',
9035
9056
  direct_pay_failed_not_sent: 'পেমেন্ট পাঠানো যায়নি। কিছুই খরচ হয়নি।',
9036
9057
  direct_pay_failed_no_message_box: 'ওয়ালেট আইডেন্টিটিকে পেমেন্ট করতে সেটিংসে আপনার মেসেজ বক্স যুক্ত করুন।',
9058
+ direct_pay_fallback_title: 'এখন অনলাইনে নেই',
9059
+ direct_pay_fallback_send: 'মেসেজ বক্সে পাঠান',
9060
+ direct_pay_sent_live: 'সরাসরি পেমেন্ট হয়েছে: এটি ইতিমধ্যে তাদের ওয়ালেটে আছে।',
9037
9061
  direct_pay_kept_needs_attention:
9038
9062
  '{{name}}-এর কাছ থেকে {{amount}} sats-এর একটি সরাসরি পেমেন্টে মনোযোগ প্রয়োজন: আপনার ওয়ালেট এটি যোগ করতে পারেনি। এটি এই ডিভাইসেই রাখা আছে।'
9039
9063
  }
@@ -10169,6 +10193,9 @@ const resources = {
10169
10193
  direct_pay_failed_not_sent: 'Не удалось отправить платёж. Ничего не потрачено.',
10170
10194
  direct_pay_failed_no_message_box:
10171
10195
  'Подключите почтовый ящик в настройках, чтобы платить по идентификатору кошелька.',
10196
+ direct_pay_fallback_title: 'Сейчас не в сети',
10197
+ direct_pay_fallback_send: 'Отправить в почтовый ящик',
10198
+ direct_pay_sent_live: 'Оплачено напрямую: деньги уже в кошельке получателя.',
10172
10199
  direct_pay_kept_needs_attention:
10173
10200
  'Прямой платёж на {{amount}} sats от {{name}} требует внимания: кошелёк не смог его добавить. Он сохранён на этом устройстве.'
10174
10201
  }
@@ -11301,6 +11328,9 @@ const resources = {
11301
11328
  'Pembayaran Anda ke {{name}} mungkin sudah terkirim. Periksa Aktivitas sebelum membayar lagi.',
11302
11329
  direct_pay_failed_not_sent: 'Pembayaran tidak dapat dikirim. Tidak ada dana yang terpakai.',
11303
11330
  direct_pay_failed_no_message_box: 'Hubungkan kotak pesan Anda di Pengaturan untuk membayar identitas dompet.',
11331
+ direct_pay_fallback_title: 'Sedang tidak online',
11332
+ direct_pay_fallback_send: 'Kirim ke kotak pesan',
11333
+ direct_pay_sent_live: 'Dibayar langsung: sudah masuk ke dompet mereka.',
11304
11334
  direct_pay_kept_needs_attention:
11305
11335
  'Pembayaran langsung {{amount}} sats dari {{name}} perlu perhatian: dompet Anda tidak dapat menambahkannya. Pembayaran ini tetap tersimpan di perangkat ini.'
11306
11336
  }
@@ -12432,6 +12462,9 @@ const resources = {
12432
12462
  '{{name}}への支払いはすでに送信されている可能性があります。もう一度支払う前に、アクティビティを確認してください。',
12433
12463
  direct_pay_failed_not_sent: '支払いを送信できませんでした。何も使われていません。',
12434
12464
  direct_pay_failed_no_message_box: 'ウォレットIDに支払うには、設定でメッセージボックスを接続してください。',
12465
+ direct_pay_fallback_title: '現在オンラインではありません',
12466
+ direct_pay_fallback_send: 'メッセージボックスに送る',
12467
+ direct_pay_sent_live: 'ライブで支払い済み:すでに相手のウォレットに入っています。',
12435
12468
  direct_pay_kept_needs_attention: '{{name}} からの {{amount}} sats のダイレクト支払いに対応が必要です。ウォレットに追加できませんでした。この端末に保存されています。'
12436
12469
  }
12437
12470
  },
@@ -13589,6 +13622,9 @@ const resources = {
13589
13622
  direct_pay_failed_not_sent: 'Nie udało się wysłać płatności. Nic nie wydano.',
13590
13623
  direct_pay_failed_no_message_box:
13591
13624
  'Połącz swoją skrzynkę wiadomości w ustawieniach, aby płacić tożsamości portfela.',
13625
+ direct_pay_fallback_title: 'Teraz nie jest online',
13626
+ direct_pay_fallback_send: 'Wyślij do skrzynki wiadomości',
13627
+ direct_pay_sent_live: 'Zapłacono na żywo: środki są już w jego portfelu.',
13592
13628
  direct_pay_kept_needs_attention:
13593
13629
  'Płatność bezpośrednia {{amount}} sats od {{name}} wymaga uwagi: portfel nie mógł jej dodać. Pozostaje na tym urządzeniu.'
13594
13630
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/expo-wallet-toolbox",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "private": false,
5
5
  "description": "Wallet screens and P2P local-payment backend for Expo/React Native apps, extracted from BSV Wallet.",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
@@ -25,6 +25,7 @@ import {
25
25
  TouchableOpacity,
26
26
  View
27
27
  } from 'react-native'
28
+ import { useDirectPay } from '../../../core/directpay/DirectPayProvider'
28
29
  import { useTranslation } from 'react-i18next'
29
30
  import { PeerPayClient, type IncomingPayment } from '@bsv/message-box-client'
30
31
  import { type DisplayableIdentity } from '@bsv/sdk'
@@ -408,6 +409,7 @@ export default function HandleReceive({
408
409
  }: HandleReceiveProps = {}) {
409
410
  const { t } = useTranslation()
410
411
  const { colors } = useTheme()
412
+ const directPay = useDirectPay()
411
413
  const Ionicons = loadIonicons()
412
414
  const QRCode = loadQRCode()
413
415
  const { useFocusEffect } = loadExpoRouter()
@@ -948,6 +950,34 @@ export default function HandleReceive({
948
950
  // Scrolls, because a 240pt QR plus the inbox overflows a small screen and a
949
951
  // note being edited puts the keyboard over the row that owns it.
950
952
  <ScrollView contentContainerStyle={styles.container} keyboardShouldPersistTaps="handled">
953
+ {/* Live payments: whether this wallet can be paid directly while the app is open. Only in a
954
+ build that offers them, and only for BSV (a token always arrives by message box). */}
955
+ {directPay.available && !asset && (
956
+ <View
957
+ style={[styles.liveCard, { backgroundColor: colors.surfaceRaised, borderColor: colors.surfaceRaisedBorder }]}
958
+ accessibilityLiveRegion="polite"
959
+ >
960
+ <View
961
+ style={[
962
+ styles.liveDot,
963
+ {
964
+ backgroundColor:
965
+ directPay.live.tone === 'on'
966
+ ? colors.success
967
+ : directPay.live.tone === 'error'
968
+ ? colors.error
969
+ : directPay.live.tone === 'connecting'
970
+ ? colors.warning
971
+ : colors.separator
972
+ }
973
+ ]}
974
+ />
975
+ <View style={styles.liveText}>
976
+ <Text style={[styles.liveTitle, { color: colors.textPrimary }]}>{t(directPay.live.titleKey)}</Text>
977
+ <Text style={[styles.liveBody, { color: colors.textSecondary }]}>{t(directPay.live.bodyKey)}</Text>
978
+ </View>
979
+ </View>
980
+ )}
951
981
  {/* Your handle. The QR is the focal element — it is the thing physically
952
982
  held up to another device. */}
953
983
  {/* The figure the code asks for, as its price. Only when one was named. */}
@@ -1071,6 +1101,19 @@ export default function HandleReceive({
1071
1101
  }
1072
1102
 
1073
1103
  const styles = StyleSheet.create({
1104
+ liveCard: {
1105
+ flexDirection: 'row',
1106
+ alignItems: 'flex-start',
1107
+ gap: 10,
1108
+ padding: 14,
1109
+ borderRadius: 14,
1110
+ borderWidth: StyleSheet.hairlineWidth,
1111
+ marginBottom: 16
1112
+ },
1113
+ liveDot: { width: 10, height: 10, borderRadius: 5, marginTop: 5 },
1114
+ liveText: { flex: 1 },
1115
+ liveTitle: { fontSize: 15, fontWeight: '600' },
1116
+ liveBody: { fontSize: 13, marginTop: 2 },
1074
1117
  container: {
1075
1118
  paddingHorizontal: spacing.lg,
1076
1119
  paddingTop: spacing.lg
@@ -25,6 +25,9 @@ import AmountDisplay from '../wallet/AmountDisplay'
25
25
  import { showAlert } from '../ui/AlertCard'
26
26
  import { showChoiceSheet } from '../ui/ChoiceSheet'
27
27
  import { promptCheckWallet } from '../../screens/WalletCheckScreen'
28
+ import { useDirectPay } from '../../../core/directpay/DirectPayProvider'
29
+ import { fallbackPrompt, payIdentity } from '../../../core/directpay/payFlow'
30
+ import type { PayOutcome } from '../../../core/directpay/types'
28
31
  import { userFacingPayError } from '../../../core/pay/userError'
29
32
  import PressableScale from '../ui/PressableScale'
30
33
  import { showToast } from '../ui/Toast'
@@ -847,23 +850,64 @@ function UniversalSendInner(
847
850
  [t]
848
851
  )
849
852
 
853
+ const directPay = useDirectPay()
854
+
850
855
  const sendHandle = useCallback(
851
856
  async (to: Extract<RecipientTarget, { kind: 'handle' }>, sats: number) => {
852
857
  const client = peerPayClient
853
858
  if (!client) throw new Error(t('message_box_off_hint'))
854
859
  if (!storage || !wallet) throw new Error(t('wallet_not_ready'))
855
- const { satoshis: paidSats } = await sendViaHandle({
856
- wallet: wallet as any,
857
- adminOriginator,
858
- client,
859
- storage,
860
- recipient: to.identityKey,
861
- recipientHost: to.messageBoxUrl,
862
- satoshis: sats,
863
- messageBoxUrl,
864
- note,
865
- recipientName: recipient.selectedIdentity?.name
866
- })
860
+ const recipientName = recipient.selectedIdentity?.name
861
+ const name = recipientName || abbreviateKey(to.identityKey)
862
+ let paidSats = sats
863
+ const viaMessageBox = async () => {
864
+ const result = await sendViaHandle({
865
+ wallet: wallet as any,
866
+ adminOriginator,
867
+ client,
868
+ storage,
869
+ recipient: to.identityKey,
870
+ recipientHost: to.messageBoxUrl,
871
+ satoshis: sats,
872
+ messageBoxUrl,
873
+ note,
874
+ recipientName
875
+ })
876
+ paidSats = result.satoshis
877
+ }
878
+ // Live first when this build and wallet can pay directly; the message box is the fallback,
879
+ // offered only when the live attempt proved nothing was spent (see payIdentity).
880
+ const viaDirect = directPay.canSendDirect
881
+ ? async () => {
882
+ const result = await directPay.sendDirect({
883
+ recipient: to.identityKey,
884
+ satoshis: sats,
885
+ note,
886
+ recipientName,
887
+ recipientHost: to.messageBoxUrl
888
+ })
889
+ paidSats = result.satoshis
890
+ return result
891
+ }
892
+ : undefined
893
+ let outcome: PayOutcome = await payIdentity({ direct: viaDirect, messageBox: viaMessageBox, name })
894
+ if (outcome.kind === 'ask_fallback') {
895
+ const prompt = fallbackPrompt(outcome.reason, name)
896
+ const choice = await showAlert({
897
+ title: t('direct_pay_fallback_title'),
898
+ message: t(prompt.key, prompt.params),
899
+ buttons: [
900
+ { text: t('cancel'), key: 'cancel', style: 'cancel' },
901
+ { text: t('direct_pay_fallback_send'), key: 'send' }
902
+ ]
903
+ })
904
+ if (choice !== 'send') throw new Error(t('direct_pay_failed_cancelled'))
905
+ outcome = await payIdentity({ messageBox: viaMessageBox, name })
906
+ }
907
+ if (outcome.kind === 'failed') {
908
+ if (outcome.detail) console.warn('[pay] direct pay failed:', outcome.key, outcome.detail)
909
+ throw new Error(t(outcome.key, outcome.params))
910
+ }
867
911
  await loadOutbox()
868
912
  // The overlay stages its own haptic (inside Celebration) and tone; firing
869
913
  // haptics.success() here would double the beat. Only a human-readable
@@ -875,11 +919,12 @@ function UniversalSendInner(
875
919
  // The handle rail always drops the payment in the recipient's message
876
920
  // box rather than handing it over in person — worth saying explicitly
877
921
  // here, since it is the one thing an in-person (Nearby) payer never
878
- // has to wonder about (ux §4.2/§8 "Success / arrival").
879
- statusNote: t('pay_sent_handed_to_wallet')
922
+ // has to wonder about (ux §4.2/§8 "Success / arrival"). A live payment is already in
923
+ // the recipient's wallet, so it says that instead.
924
+ statusNote: outcome.kind === 'paid_live' ? t('direct_pay_sent_live') : t('pay_sent_handed_to_wallet')
880
925
  })
881
926
  },
882
- [peerPayClient, storage, wallet, adminOriginator, messageBoxUrl, note, recipient.selectedIdentity, loadOutbox, t]
927
+ [peerPayClient, storage, wallet, adminOriginator, messageBoxUrl, note, recipient.selectedIdentity, loadOutbox, t, directPay]
883
928
  )
884
929
 
885
930
  const sendAddress = useCallback(