@bsv/expo-wallet-toolbox 0.11.7 → 0.12.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 +106 -0
- package/core/config.tsx +1 -1
- package/core/context/WalletContext.tsx +171 -19
- package/core/i18n/translations.tsx +120 -12
- package/core/index.ts +2 -0
- package/core/pay/beefRepair.ts +8 -3
- package/core/pay/rails/address.ts +43 -3
- package/core/pay/rails/handle.ts +1 -1
- package/core/pay/sweeper.ts +39 -4
- package/core/push/events.ts +142 -0
- package/core/push/pushAdvisory.ts +33 -0
- package/core/push/registration.ts +53 -0
- package/core/push/types.ts +31 -0
- package/core/toolboxConfig.ts +24 -1
- package/package.json +1 -1
- package/ui/components/pay/HandleReceive.tsx +141 -16
- package/ui/components/pay/NotificationAdvisoryModal.tsx +124 -0
- package/ui/components/ui/PermissionSheet.tsx +53 -8
- package/ui/index.ts +1 -0
- package/ui/screens/PayScreen.tsx +53 -0
- package/ui/screens/SettingsScreen.tsx +72 -2
|
@@ -951,10 +951,19 @@ const resources = {
|
|
|
951
951
|
home_payments_unsent: '{{count}} payments not delivered',
|
|
952
952
|
pay_copy: 'Copy',
|
|
953
953
|
pay_share_link: 'Share link',
|
|
954
|
-
pay_address_watching: 'Money sent here is added to your wallet automatically.',
|
|
954
|
+
pay_address_watching: 'Money sent here is added to your wallet automatically, but only while the app is open.',
|
|
955
955
|
pay_address_earlier_day: 'Reach an earlier day',
|
|
956
956
|
pay_address_sweep_now: 'Check this BSV address now',
|
|
957
957
|
pay_address_swept: 'Received {{amount}}',
|
|
958
|
+
push_advisory_title: "Get notified when you're paid",
|
|
959
|
+
push_advisory_body:
|
|
960
|
+
'Next, your phone will ask to allow notifications. This lets BSV Wallet tell you when a payment arrives, even while the app is in the background.',
|
|
961
|
+
push_advisory_continue: 'Continue',
|
|
962
|
+
push_advisory_not_now: 'Not now',
|
|
963
|
+
notifications: 'Notifications',
|
|
964
|
+
push_settings_row: 'Payment notifications',
|
|
965
|
+
push_settings_on: 'On',
|
|
966
|
+
push_settings_off: 'Off',
|
|
958
967
|
|
|
959
968
|
check_wallet: 'Troubleshooting',
|
|
960
969
|
settings_version: 'v{{version}}',
|
|
@@ -1952,10 +1961,19 @@ const resources = {
|
|
|
1952
1961
|
home_payments_unsent: '{{count}} 笔付款未送达',
|
|
1953
1962
|
pay_copy: '复制',
|
|
1954
1963
|
pay_share_link: '分享链接',
|
|
1955
|
-
pay_address_watching: '
|
|
1964
|
+
pay_address_watching: '发送到此地址的款项会自动添加到您的钱包,但仅限应用打开时。',
|
|
1956
1965
|
pay_address_earlier_day: '回到更早的日期',
|
|
1957
1966
|
pay_address_sweep_now: '立即检查此 BSV 地址',
|
|
1958
1967
|
pay_address_swept: '已收到 {{amount}}',
|
|
1968
|
+
push_advisory_title: '收款时收到通知',
|
|
1969
|
+
push_advisory_body:
|
|
1970
|
+
'接下来,您的手机会请求允许发送通知。这样即使应用在后台运行,BSV Wallet 也能在款项到账时通知您。',
|
|
1971
|
+
push_advisory_continue: '继续',
|
|
1972
|
+
push_advisory_not_now: '暂不',
|
|
1973
|
+
notifications: '通知',
|
|
1974
|
+
push_settings_row: '支付通知',
|
|
1975
|
+
push_settings_on: '开',
|
|
1976
|
+
push_settings_off: '关',
|
|
1959
1977
|
|
|
1960
1978
|
check_wallet: '疑难解答',
|
|
1961
1979
|
settings_version: 'v{{version}}',
|
|
@@ -2990,10 +3008,19 @@ const resources = {
|
|
|
2990
3008
|
home_payments_unsent: '{{count}} भुगतान डिलीवर नहीं हुए',
|
|
2991
3009
|
pay_copy: 'कॉपी',
|
|
2992
3010
|
pay_share_link: 'लिंक साझा करें',
|
|
2993
|
-
pay_address_watching: 'यहां भेजा गया पैसा अपने आप आपके वॉलेट में जुड़ जाता
|
|
3011
|
+
pay_address_watching: 'यहां भेजा गया पैसा अपने आप आपके वॉलेट में जुड़ जाता है, लेकिन केवल तब जब ऐप खुला हो।',
|
|
2994
3012
|
pay_address_earlier_day: 'किसी पिछले दिन तक जाएं',
|
|
2995
3013
|
pay_address_sweep_now: 'यह BSV पता अभी जांचें',
|
|
2996
3014
|
pay_address_swept: '{{amount}} प्राप्त हुआ',
|
|
3015
|
+
push_advisory_title: 'भुगतान मिलने पर सूचना पाएं',
|
|
3016
|
+
push_advisory_body:
|
|
3017
|
+
'आगे, आपका फ़ोन सूचनाओं की अनुमति माँगेगा। इससे ऐप बैकग्राउंड में होने पर भी BSV Wallet आपको बता सकेगा कि भुगतान आ गया है।',
|
|
3018
|
+
push_advisory_continue: 'जारी रखें',
|
|
3019
|
+
push_advisory_not_now: 'अभी नहीं',
|
|
3020
|
+
notifications: 'सूचनाएं',
|
|
3021
|
+
push_settings_row: 'भुगतान सूचनाएं',
|
|
3022
|
+
push_settings_on: 'चालू',
|
|
3023
|
+
push_settings_off: 'बंद',
|
|
2997
3024
|
|
|
2998
3025
|
check_wallet: 'समस्या निवारण',
|
|
2999
3026
|
settings_version: 'v{{version}}',
|
|
@@ -4052,10 +4079,19 @@ const resources = {
|
|
|
4052
4079
|
home_payments_unsent: '{{count}} pagos sin entregar',
|
|
4053
4080
|
pay_copy: 'Copiar',
|
|
4054
4081
|
pay_share_link: 'Compartir enlace',
|
|
4055
|
-
pay_address_watching: 'El dinero enviado aquí se añade a tu billetera automáticamente.',
|
|
4082
|
+
pay_address_watching: 'El dinero enviado aquí se añade a tu billetera automáticamente, pero solo mientras la app está abierta.',
|
|
4056
4083
|
pay_address_earlier_day: 'Ir a un día anterior',
|
|
4057
4084
|
pay_address_sweep_now: 'Comprobar esta dirección BSV ahora',
|
|
4058
4085
|
pay_address_swept: 'Recibido {{amount}}',
|
|
4086
|
+
push_advisory_title: 'Recibe un aviso cuando te paguen',
|
|
4087
|
+
push_advisory_body:
|
|
4088
|
+
'A continuación, tu teléfono te pedirá permiso para enviar notificaciones. Así BSV Wallet podrá avisarte cuando llegue un pago, incluso con la app en segundo plano.',
|
|
4089
|
+
push_advisory_continue: 'Continuar',
|
|
4090
|
+
push_advisory_not_now: 'Ahora no',
|
|
4091
|
+
notifications: 'Notificaciones',
|
|
4092
|
+
push_settings_row: 'Notificaciones de pago',
|
|
4093
|
+
push_settings_on: 'Activadas',
|
|
4094
|
+
push_settings_off: 'Desactivadas',
|
|
4059
4095
|
|
|
4060
4096
|
check_wallet: 'Solución de problemas',
|
|
4061
4097
|
settings_version: 'v{{version}}',
|
|
@@ -5127,10 +5163,19 @@ const resources = {
|
|
|
5127
5163
|
home_payments_unsent: '{{count}} paiements non remis',
|
|
5128
5164
|
pay_copy: 'Copier',
|
|
5129
5165
|
pay_share_link: 'Partager le lien',
|
|
5130
|
-
pay_address_watching: 'L’argent envoyé ici est ajouté automatiquement à votre portefeuille.',
|
|
5166
|
+
pay_address_watching: 'L’argent envoyé ici est ajouté automatiquement à votre portefeuille, mais uniquement lorsque l’app est ouverte.',
|
|
5131
5167
|
pay_address_earlier_day: 'Revenir à un jour précédent',
|
|
5132
5168
|
pay_address_sweep_now: 'Vérifier cette adresse BSV maintenant',
|
|
5133
5169
|
pay_address_swept: '{{amount}} reçu',
|
|
5170
|
+
push_advisory_title: 'Soyez prévenu quand vous êtes payé',
|
|
5171
|
+
push_advisory_body:
|
|
5172
|
+
'Votre téléphone va maintenant demander l’autorisation d’envoyer des notifications. Ainsi, BSV Wallet pourra vous prévenir dès qu’un paiement arrive, même lorsque l’application est en arrière-plan.',
|
|
5173
|
+
push_advisory_continue: 'Continuer',
|
|
5174
|
+
push_advisory_not_now: 'Plus tard',
|
|
5175
|
+
notifications: 'Notifications',
|
|
5176
|
+
push_settings_row: 'Notifications de paiement',
|
|
5177
|
+
push_settings_on: 'Activées',
|
|
5178
|
+
push_settings_off: 'Désactivées',
|
|
5134
5179
|
|
|
5135
5180
|
check_wallet: 'Dépannage',
|
|
5136
5181
|
settings_version: 'v{{version}}',
|
|
@@ -6154,10 +6199,19 @@ const resources = {
|
|
|
6154
6199
|
home_payments_unsent: '{{count}} دفعات لم تُسلَّم',
|
|
6155
6200
|
pay_copy: 'نسخ',
|
|
6156
6201
|
pay_share_link: 'مشاركة الرابط',
|
|
6157
|
-
pay_address_watching: 'الأموال المرسلة إلى هذا العنوان تُضاف إلى محفظتك
|
|
6202
|
+
pay_address_watching: 'الأموال المرسلة إلى هذا العنوان تُضاف إلى محفظتك تلقائيًا، ولكن فقط أثناء فتح التطبيق.',
|
|
6158
6203
|
pay_address_earlier_day: 'الانتقال إلى يوم أسبق',
|
|
6159
6204
|
pay_address_sweep_now: 'تحقق من عنوان BSV هذا الآن',
|
|
6160
6205
|
pay_address_swept: 'تم استلام {{amount}}',
|
|
6206
|
+
push_advisory_title: 'اعرف فورًا عندما تتلقى دفعة',
|
|
6207
|
+
push_advisory_body:
|
|
6208
|
+
'بعد ذلك، سيطلب هاتفك السماح بالإشعارات. يتيح ذلك لـ BSV Wallet إخبارك عند وصول دفعة، حتى عندما يكون التطبيق في الخلفية.',
|
|
6209
|
+
push_advisory_continue: 'استمرار',
|
|
6210
|
+
push_advisory_not_now: 'ليس الآن',
|
|
6211
|
+
notifications: 'الإشعارات',
|
|
6212
|
+
push_settings_row: 'إشعارات الدفع',
|
|
6213
|
+
push_settings_on: 'تشغيل',
|
|
6214
|
+
push_settings_off: 'إيقاف',
|
|
6161
6215
|
|
|
6162
6216
|
check_wallet: 'استكشاف الأخطاء',
|
|
6163
6217
|
settings_version: 'v{{version}}',
|
|
@@ -7205,10 +7259,19 @@ const resources = {
|
|
|
7205
7259
|
home_payments_unsent: '{{count}} pagamentos não entregues',
|
|
7206
7260
|
pay_copy: 'Copiar',
|
|
7207
7261
|
pay_share_link: 'Compartilhar link',
|
|
7208
|
-
pay_address_watching: 'O dinheiro enviado para cá é adicionado à sua carteira automaticamente.',
|
|
7262
|
+
pay_address_watching: 'O dinheiro enviado para cá é adicionado à sua carteira automaticamente, mas só enquanto o app estiver aberto.',
|
|
7209
7263
|
pay_address_earlier_day: 'Voltar para um dia anterior',
|
|
7210
7264
|
pay_address_sweep_now: 'Verificar este endereço BSV agora',
|
|
7211
7265
|
pay_address_swept: '{{amount}} recebido',
|
|
7266
|
+
push_advisory_title: 'Receba um aviso quando você for pago',
|
|
7267
|
+
push_advisory_body:
|
|
7268
|
+
'Em seguida, seu celular vai pedir permissão para enviar notificações. Assim, a BSV Wallet pode avisar você quando um pagamento chegar, mesmo com o app em segundo plano.',
|
|
7269
|
+
push_advisory_continue: 'Continuar',
|
|
7270
|
+
push_advisory_not_now: 'Agora não',
|
|
7271
|
+
notifications: 'Notificações',
|
|
7272
|
+
push_settings_row: 'Notificações de pagamento',
|
|
7273
|
+
push_settings_on: 'Ativadas',
|
|
7274
|
+
push_settings_off: 'Desativadas',
|
|
7212
7275
|
|
|
7213
7276
|
check_wallet: 'Solução de problemas',
|
|
7214
7277
|
settings_version: 'v{{version}}',
|
|
@@ -8255,10 +8318,19 @@ const resources = {
|
|
|
8255
8318
|
home_payments_unsent: '{{count}}টি পেমেন্ট পৌঁছায়নি',
|
|
8256
8319
|
pay_copy: 'কপি',
|
|
8257
8320
|
pay_share_link: 'লিঙ্ক শেয়ার করুন',
|
|
8258
|
-
pay_address_watching: 'এই ঠিকানায় পাঠানো অর্থ স্বয়ংক্রিয়ভাবে আপনার ওয়ালেটে যোগ
|
|
8321
|
+
pay_address_watching: 'এই ঠিকানায় পাঠানো অর্থ স্বয়ংক্রিয়ভাবে আপনার ওয়ালেটে যোগ হয়, তবে শুধু অ্যাপ খোলা থাকলে।',
|
|
8259
8322
|
pay_address_earlier_day: 'আগের কোনো দিনে যান',
|
|
8260
8323
|
pay_address_sweep_now: 'এই BSV ঠিকানাটি এখনই যাচাই করুন',
|
|
8261
8324
|
pay_address_swept: '{{amount}} পাওয়া গেছে',
|
|
8325
|
+
push_advisory_title: 'পেমেন্ট পেলে নোটিফিকেশন পান',
|
|
8326
|
+
push_advisory_body:
|
|
8327
|
+
'এরপর আপনার ফোন নোটিফিকেশনের অনুমতি চাইবে। এতে অ্যাপ ব্যাকগ্রাউন্ডে থাকলেও পেমেন্ট এলে BSV Wallet আপনাকে জানাতে পারবে।',
|
|
8328
|
+
push_advisory_continue: 'চালিয়ে যান',
|
|
8329
|
+
push_advisory_not_now: 'এখন নয়',
|
|
8330
|
+
notifications: 'নোটিফিকেশন',
|
|
8331
|
+
push_settings_row: 'পেমেন্ট নোটিফিকেশন',
|
|
8332
|
+
push_settings_on: 'চালু',
|
|
8333
|
+
push_settings_off: 'বন্ধ',
|
|
8262
8334
|
|
|
8263
8335
|
check_wallet: 'সমস্যা সমাধান',
|
|
8264
8336
|
settings_version: 'v{{version}}',
|
|
@@ -9312,10 +9384,19 @@ const resources = {
|
|
|
9312
9384
|
home_payments_unsent: 'Недоставленных платежей: {{count}}',
|
|
9313
9385
|
pay_copy: 'Копировать',
|
|
9314
9386
|
pay_share_link: 'Поделиться ссылкой',
|
|
9315
|
-
pay_address_watching: 'Деньги, отправленные на этот адрес, добавляются в ваш кошелёк
|
|
9387
|
+
pay_address_watching: 'Деньги, отправленные на этот адрес, добавляются в ваш кошелёк автоматически, но только пока приложение открыто.',
|
|
9316
9388
|
pay_address_earlier_day: 'Перейти к более раннему дню',
|
|
9317
9389
|
pay_address_sweep_now: 'Проверить этот BSV-адрес сейчас',
|
|
9318
9390
|
pay_address_swept: 'Получено {{amount}}',
|
|
9391
|
+
push_advisory_title: 'Узнавайте о поступлении платежа',
|
|
9392
|
+
push_advisory_body:
|
|
9393
|
+
'Далее телефон запросит разрешение на уведомления. Благодаря этому BSV Wallet сообщит вам о поступлении платежа, даже если приложение работает в фоновом режиме.',
|
|
9394
|
+
push_advisory_continue: 'Продолжить',
|
|
9395
|
+
push_advisory_not_now: 'Не сейчас',
|
|
9396
|
+
notifications: 'Уведомления',
|
|
9397
|
+
push_settings_row: 'Уведомления о платежах',
|
|
9398
|
+
push_settings_on: 'Вкл.',
|
|
9399
|
+
push_settings_off: 'Выкл.',
|
|
9319
9400
|
|
|
9320
9401
|
check_wallet: 'Диагностика',
|
|
9321
9402
|
settings_version: 'v{{version}}',
|
|
@@ -10369,10 +10450,19 @@ const resources = {
|
|
|
10369
10450
|
home_payments_unsent: '{{count}} pembayaran belum terkirim',
|
|
10370
10451
|
pay_copy: 'Salin',
|
|
10371
10452
|
pay_share_link: 'Bagikan tautan',
|
|
10372
|
-
pay_address_watching: 'Uang yang dikirim ke sini otomatis ditambahkan ke dompet Anda.',
|
|
10453
|
+
pay_address_watching: 'Uang yang dikirim ke sini otomatis ditambahkan ke dompet Anda, tetapi hanya saat aplikasi terbuka.',
|
|
10373
10454
|
pay_address_earlier_day: 'Buka hari sebelumnya',
|
|
10374
10455
|
pay_address_sweep_now: 'Periksa alamat BSV ini sekarang',
|
|
10375
10456
|
pay_address_swept: 'Diterima {{amount}}',
|
|
10457
|
+
push_advisory_title: 'Dapatkan pemberitahuan saat Anda dibayar',
|
|
10458
|
+
push_advisory_body:
|
|
10459
|
+
'Selanjutnya, ponsel Anda akan meminta izin untuk mengirim notifikasi. Dengan begitu, BSV Wallet dapat memberi tahu Anda saat pembayaran masuk, bahkan ketika aplikasi berjalan di latar belakang.',
|
|
10460
|
+
push_advisory_continue: 'Lanjutkan',
|
|
10461
|
+
push_advisory_not_now: 'Nanti saja',
|
|
10462
|
+
notifications: 'Pemberitahuan',
|
|
10463
|
+
push_settings_row: 'Pemberitahuan pembayaran',
|
|
10464
|
+
push_settings_on: 'Aktif',
|
|
10465
|
+
push_settings_off: 'Nonaktif',
|
|
10376
10466
|
|
|
10377
10467
|
check_wallet: 'Pemecahan masalah',
|
|
10378
10468
|
settings_version: 'v{{version}}',
|
|
@@ -11440,10 +11530,19 @@ const resources = {
|
|
|
11440
11530
|
home_payments_unsent: '{{count}} 件の支払いが未送達です',
|
|
11441
11531
|
pay_copy: 'コピー',
|
|
11442
11532
|
pay_share_link: 'リンクを共有',
|
|
11443
|
-
pay_address_watching: '
|
|
11533
|
+
pay_address_watching: 'このアドレスに送られた資金は、アプリを開いている間だけ自動でウォレットに追加されます。',
|
|
11444
11534
|
pay_address_earlier_day: 'それ以前の日にさかのぼる',
|
|
11445
11535
|
pay_address_sweep_now: 'このBSVアドレスを今すぐ確認',
|
|
11446
11536
|
pay_address_swept: '{{amount}} を受け取りました',
|
|
11537
|
+
push_advisory_title: '支払いを受け取ったら通知でお知らせ',
|
|
11538
|
+
push_advisory_body:
|
|
11539
|
+
'次に、スマートフォンが通知の許可を求めます。許可すると、アプリがバックグラウンドにあるときでも、支払いが届いたことを BSV Wallet がお知らせします。',
|
|
11540
|
+
push_advisory_continue: '続行',
|
|
11541
|
+
push_advisory_not_now: 'あとで',
|
|
11542
|
+
notifications: '通知',
|
|
11543
|
+
push_settings_row: '支払いの通知',
|
|
11544
|
+
push_settings_on: 'オン',
|
|
11545
|
+
push_settings_off: 'オフ',
|
|
11447
11546
|
|
|
11448
11547
|
check_wallet: 'トラブルシューティング',
|
|
11449
11548
|
settings_version: 'v{{version}}',
|
|
@@ -12517,10 +12616,19 @@ const resources = {
|
|
|
12517
12616
|
home_payments_unsent: 'Niedostarczone płatności: {{count}}',
|
|
12518
12617
|
pay_copy: 'Kopiuj',
|
|
12519
12618
|
pay_share_link: 'Udostępnij link',
|
|
12520
|
-
pay_address_watching: 'Pieniądze wysłane na ten adres są automatycznie dodawane do Twojego portfela.',
|
|
12619
|
+
pay_address_watching: 'Pieniądze wysłane na ten adres są automatycznie dodawane do Twojego portfela, ale tylko gdy aplikacja jest otwarta.',
|
|
12521
12620
|
pay_address_earlier_day: 'Wróć do wcześniejszego dnia',
|
|
12522
12621
|
pay_address_sweep_now: 'Sprawdź teraz ten adres BSV',
|
|
12523
12622
|
pay_address_swept: 'Otrzymano {{amount}}',
|
|
12623
|
+
push_advisory_title: 'Powiadomimy Cię, gdy dostaniesz zapłatę',
|
|
12624
|
+
push_advisory_body:
|
|
12625
|
+
'Za chwilę telefon poprosi o zgodę na powiadomienia. Dzięki temu BSV Wallet poinformuje Cię o nadejściu płatności, nawet gdy aplikacja działa w tle.',
|
|
12626
|
+
push_advisory_continue: 'Kontynuuj',
|
|
12627
|
+
push_advisory_not_now: 'Nie teraz',
|
|
12628
|
+
notifications: 'Powiadomienia',
|
|
12629
|
+
push_settings_row: 'Powiadomienia o płatnościach',
|
|
12630
|
+
push_settings_on: 'Wł.',
|
|
12631
|
+
push_settings_off: 'Wył.',
|
|
12524
12632
|
|
|
12525
12633
|
check_wallet: 'Rozwiązywanie problemów',
|
|
12526
12634
|
settings_version: 'v{{version}}',
|
package/core/index.ts
CHANGED
|
@@ -35,6 +35,7 @@ export {
|
|
|
35
35
|
getServiceConfig,
|
|
36
36
|
getMandalaEndpoints,
|
|
37
37
|
getHandleRegistryConfig,
|
|
38
|
+
getPushAdapter,
|
|
38
39
|
isAllowedServiceOrigin,
|
|
39
40
|
isMandalaAvailable,
|
|
40
41
|
isVaultEnabled,
|
|
@@ -42,6 +43,7 @@ export {
|
|
|
42
43
|
resetToolboxConfig
|
|
43
44
|
} from './toolboxConfig'
|
|
44
45
|
export type { ToolboxConfig, ToolboxServiceConfig, MandalaEndpointConfig, HandleRegistryConfig } from './toolboxConfig'
|
|
46
|
+
export type { PushAdapter, PushPermission, PushOpenedEvent } from './push/types'
|
|
45
47
|
|
|
46
48
|
// Theme tokens and providers
|
|
47
49
|
export { ThemeProvider, useTheme } from './theme/ThemeContext'
|
package/core/pay/beefRepair.ts
CHANGED
|
@@ -23,10 +23,13 @@
|
|
|
23
23
|
* and `makeBeefRepair` declines rather than burning an attempt on it.
|
|
24
24
|
*/
|
|
25
25
|
import { Beef, Utils } from '@bsv/sdk'
|
|
26
|
-
import { MAX_HEX_RESPONSE_CHARS, type WocConfig } from './rails/address'
|
|
26
|
+
import { MAX_HEX_RESPONSE_CHARS, wocRequestInit, type WocConfig } from './rails/address'
|
|
27
27
|
|
|
28
28
|
/** Injectable for tests; production uses global fetch. */
|
|
29
|
-
export type FetchLike = (
|
|
29
|
+
export type FetchLike = (
|
|
30
|
+
url: string,
|
|
31
|
+
init?: { headers?: Record<string, string> }
|
|
32
|
+
) => Promise<{ ok: boolean; status: number; text: () => Promise<string> }>
|
|
30
33
|
|
|
31
34
|
/**
|
|
32
35
|
* The current AtomicBEEF for `txid`, or undefined if the network cannot supply
|
|
@@ -46,7 +49,9 @@ export async function refetchAtomicBeef(args: {
|
|
|
46
49
|
|
|
47
50
|
let bytes: number[]
|
|
48
51
|
try {
|
|
49
|
-
const
|
|
52
|
+
const url = `${woc.apiBase}/v1/bsv/${woc.segment}/tx/${txid}/beef`
|
|
53
|
+
const init = wocRequestInit(woc)
|
|
54
|
+
const resp = init ? await doFetch(url, init) : await doFetch(url)
|
|
50
55
|
// Checked, because the body of a 404 is prose. `Utils.toArray(prose, 'hex')`
|
|
51
56
|
// throws "Invalid hex string", and an empty body parses to a Beef whose
|
|
52
57
|
// magic check fails — both of which would surface as a confusing error from
|
|
@@ -137,6 +137,14 @@ export interface WocConfig {
|
|
|
137
137
|
apiBase: string
|
|
138
138
|
segment: string
|
|
139
139
|
network: 'mainnet' | 'testnet'
|
|
140
|
+
/**
|
|
141
|
+
* A WhatsOnChain key, sent only as the `woc-api-key` header (see
|
|
142
|
+
* `wocRequestInit`); never logged. `wocConfigFor` does not set it: the
|
|
143
|
+
* host's app-wide key is shared with broadcast, and a 5 s sweep across the
|
|
144
|
+
* whole fleet would drain that quota. A caller with a key of its own may set
|
|
145
|
+
* it explicitly.
|
|
146
|
+
*/
|
|
147
|
+
apiKey?: string
|
|
140
148
|
}
|
|
141
149
|
|
|
142
150
|
export function wocConfigFor(network: AppChain): WocConfig {
|
|
@@ -147,6 +155,35 @@ export function wocConfigFor(network: AppChain): WocConfig {
|
|
|
147
155
|
}[network]
|
|
148
156
|
}
|
|
149
157
|
|
|
158
|
+
/**
|
|
159
|
+
* HTTP 429 from WhatsOnChain. A type of its own because it is the one failure
|
|
160
|
+
* of these fetches the caller must not treat like the rest: the sweep polls
|
|
161
|
+
* every 5 s, so "try again next tick" is exactly the behaviour that keeps a
|
|
162
|
+
* rate limit alive. It lets the sweep stop the pass and back off instead.
|
|
163
|
+
*/
|
|
164
|
+
export class WocRateLimited extends Error {
|
|
165
|
+
constructor() {
|
|
166
|
+
super('WhatsOnChain rate limit reached')
|
|
167
|
+
this.name = 'WocRateLimited'
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The request options carrying the WhatsOnChain key, or undefined when the
|
|
173
|
+
* config has none — so that a config without a key sends the same bare request
|
|
174
|
+
* it always did.
|
|
175
|
+
*/
|
|
176
|
+
export function wocRequestInit(woc: WocConfig): { headers: Record<string, string> } | undefined {
|
|
177
|
+
return woc.apiKey ? { headers: { 'woc-api-key': woc.apiKey } } : undefined
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function wocFetch(woc: WocConfig, url: string): Promise<Response> {
|
|
181
|
+
const init = wocRequestInit(woc)
|
|
182
|
+
const response = init ? await fetch(url, init) : await fetch(url)
|
|
183
|
+
if (response.status === 429) throw new WocRateLimited()
|
|
184
|
+
return response
|
|
185
|
+
}
|
|
186
|
+
|
|
150
187
|
export interface AddressDerivingWallet {
|
|
151
188
|
getPublicKey(args: unknown, originator?: string): Promise<{ publicKey: string }>
|
|
152
189
|
}
|
|
@@ -201,7 +238,7 @@ export const MAX_UTXO_LISTING_ROWS = 2000
|
|
|
201
238
|
export const MAX_HEX_RESPONSE_CHARS = 8_000_000
|
|
202
239
|
|
|
203
240
|
export async function getUtxosForAddress(woc: WocConfig, address: string): Promise<Utxo[]> {
|
|
204
|
-
const response = await
|
|
241
|
+
const response = await wocFetch(woc, `${woc.apiBase}/v1/bsv/${woc.segment}/address/${address}/unspent/all`)
|
|
205
242
|
const rp = await response.json()
|
|
206
243
|
// A live receive address never legitimately carries anywhere near this many
|
|
207
244
|
// UTXOs; sweepAddress fetches one BEEF per distinct txid in the result, so
|
|
@@ -396,7 +433,7 @@ export async function sweepAddress(args: {
|
|
|
396
433
|
for (const txid of txids) {
|
|
397
434
|
const relevant = byTxid.get(txid) as Utxo[]
|
|
398
435
|
try {
|
|
399
|
-
const resp = await
|
|
436
|
+
const resp = await wocFetch(woc, `${woc.apiBase}/v1/bsv/${woc.segment}/tx/${txid}/beef`)
|
|
400
437
|
const bytes = parseWocBeefBody({ ok: resp.ok, text: await resp.text() })
|
|
401
438
|
if (!bytes) {
|
|
402
439
|
failureCount++
|
|
@@ -450,7 +487,10 @@ export async function sweepAddress(args: {
|
|
|
450
487
|
if (response?.accepted) {
|
|
451
488
|
importedSatoshis += verified.reduce((sum, o) => sum + (tx.outputs[o.vout]?.satoshis ?? 0), 0)
|
|
452
489
|
} else failureCount++
|
|
453
|
-
} catch {
|
|
490
|
+
} catch (error) {
|
|
491
|
+
// A rate limit is not this payment's failure: the rest of the pass would
|
|
492
|
+
// only be refused the same way, so let it stop the sweep (see runSweep).
|
|
493
|
+
if (error instanceof WocRateLimited) throw error
|
|
454
494
|
failureCount++
|
|
455
495
|
}
|
|
456
496
|
}
|
package/core/pay/rails/handle.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { TaskDrainOutbox } from '../../monitor/TaskDrainOutbox'
|
|
|
26
26
|
import type { MandalaRuntime, TokenSendResult } from '../../mandala/runtime'
|
|
27
27
|
|
|
28
28
|
export const MESSAGE_BOX_URL_KEY = 'message_box_url'
|
|
29
|
-
export const DEFAULT_MESSAGE_BOX_URL = 'https://
|
|
29
|
+
export const DEFAULT_MESSAGE_BOX_URL = 'https://messagebox.bsvblockchain.tech'
|
|
30
30
|
/** The previous default. A saved preference equal to it is treated as "use the
|
|
31
31
|
* default", so existing installs follow the default forward. */
|
|
32
32
|
export const LEGACY_MESSAGE_BOX_URL = 'https://messagebox.babbage.systems'
|
package/core/pay/sweeper.ts
CHANGED
|
@@ -10,11 +10,43 @@
|
|
|
10
10
|
* Every bound is deliberate and tested: see shouldSweepNow for when a pass may
|
|
11
11
|
* run at all, and pay/watchlist.ts for which addresses it may touch.
|
|
12
12
|
*/
|
|
13
|
-
import { sweepAddress, type AddressRailWallet, type WocConfig } from './rails/address'
|
|
13
|
+
import { sweepAddress, WocRateLimited, type AddressRailWallet, type WocConfig } from './rails/address'
|
|
14
14
|
import { getWatchlist, touchWatched, type KVStorage } from './watchlist'
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* One poll every 5s, foreground only (shouldSweepNow refuses in the background).
|
|
18
|
+
*
|
|
19
|
+
* An address payment announces itself to no one: unlike the handle and nearby
|
|
20
|
+
* rails there is no MessageBox message to push, so the only way this wallet
|
|
21
|
+
* learns of one is to look. 5s is what makes "show the address, money appears"
|
|
22
|
+
* feel immediate to a user watching the screen. The cost is up to ~1.6 WhatsOnChain
|
|
23
|
+
* requests/s on a device with the full 8 watched addresses. The requests carry
|
|
24
|
+
* no API key on purpose: the host's app-wide key is shared with broadcast, and
|
|
25
|
+
* a fleet polling at 5s would drain its quota. So the sweep runs on WhatsOnChain's
|
|
26
|
+
* anonymous limit, and a 429 backs it off (SWEEP_BACKOFF_TICKS) rather than
|
|
27
|
+
* being retried on the next tick.
|
|
28
|
+
*/
|
|
29
|
+
export const SWEEP_INTERVAL_MS = 5_000
|
|
30
|
+
|
|
31
|
+
/** Ticks to sit out after a WhatsOnChain 429: 30s at SWEEP_INTERVAL_MS. */
|
|
32
|
+
export const SWEEP_BACKOFF_TICKS = 6
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Spend one tick of a pending backoff. Pure so the caller's counter (a plain
|
|
36
|
+
* variable in the sweep effect's closure) is tested here rather than through a
|
|
37
|
+
* provider.
|
|
38
|
+
*/
|
|
39
|
+
export function consumeBackoff(remaining: number): { skip: boolean; remaining: number } {
|
|
40
|
+
return remaining > 0 ? { skip: true, remaining: remaining - 1 } : { skip: false, remaining: 0 }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The backoff after a failed pass: a full SWEEP_BACKOFF_TICKS for a rate limit,
|
|
45
|
+
* unchanged for anything else (those stay best-effort — the next tick retries).
|
|
46
|
+
*/
|
|
47
|
+
export function backoffAfterSweepError(error: unknown, remaining: number): number {
|
|
48
|
+
return error instanceof WocRateLimited ? SWEEP_BACKOFF_TICKS : remaining
|
|
49
|
+
}
|
|
18
50
|
|
|
19
51
|
export interface SweepOutcome {
|
|
20
52
|
address: string
|
|
@@ -61,7 +93,10 @@ export async function runSweep(args: {
|
|
|
61
93
|
// rather than retiring it the moment it pays out. A funded address whose
|
|
62
94
|
// import failed must stay watched too, or a bad BEEF fetch TTL-drops it.
|
|
63
95
|
if (importedSatoshis > 0 || foundOnChain) await touchWatched(storage, watched.address)
|
|
64
|
-
} catch {
|
|
96
|
+
} catch (error) {
|
|
97
|
+
// A rate limit is the one failure that does stop the pass: the other
|
|
98
|
+
// addresses would be refused the same way and only deepen the limit.
|
|
99
|
+
if (error instanceof WocRateLimited) throw error
|
|
65
100
|
// A dead WoC host or a locked wallet must not stop the rest of the pass.
|
|
66
101
|
// The entry stays watched and the next pass retries it.
|
|
67
102
|
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import type { PushAdapter } from './types'
|
|
2
|
+
|
|
3
|
+
let initialConsumed = false
|
|
4
|
+
/** Test-only. */
|
|
5
|
+
export function __resetInitialNotificationForTests(): void {
|
|
6
|
+
initialConsumed = false
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Push failures are contained, never thrown, but they are not silent: a
|
|
11
|
+
* swallowed failure with no trace is how "push never works on this build"
|
|
12
|
+
* becomes impossible to diagnose. Only the error message is logged — never the
|
|
13
|
+
* push payload, the FCM token or an identity key.
|
|
14
|
+
*/
|
|
15
|
+
function warn(what: string, e: unknown): void {
|
|
16
|
+
console.warn(`[push] ${what} failed: ${e instanceof Error ? e.message : String(e)}`)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Run `fn`, containing a throw: push is an enhancement and must never break its caller. */
|
|
20
|
+
function guarded(what: string, fn: () => void): void {
|
|
21
|
+
try {
|
|
22
|
+
fn()
|
|
23
|
+
} catch (e) {
|
|
24
|
+
warn(what, e)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Subscribe inside its own try/catch. An adapter can throw synchronously when
|
|
30
|
+
* subscribing (the native Firebase app missing on an old dev-client binary);
|
|
31
|
+
* that listener is then simply absent, and the others still attach.
|
|
32
|
+
*/
|
|
33
|
+
function subscribe(what: string, attach: () => () => void): () => void {
|
|
34
|
+
try {
|
|
35
|
+
const off = attach()
|
|
36
|
+
return typeof off === 'function' ? off : () => {}
|
|
37
|
+
} catch (e) {
|
|
38
|
+
warn(`${what} subscribe`, e)
|
|
39
|
+
return () => {}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Route push events into the existing inbox machinery. A push only ever means
|
|
45
|
+
* "look at the inbox now": the credit, sound and toast come from the normal
|
|
46
|
+
* TaskCreditInbox pass, so nothing is shown or credited twice.
|
|
47
|
+
*
|
|
48
|
+
* Never throws — a broken adapter leaves the wallet exactly as it was without
|
|
49
|
+
* push.
|
|
50
|
+
*/
|
|
51
|
+
export function attachPushHandlers(args: {
|
|
52
|
+
adapter: PushAdapter
|
|
53
|
+
requestInboxPass: () => void
|
|
54
|
+
openActivity: () => void
|
|
55
|
+
onTokenRefresh: () => void
|
|
56
|
+
}): () => void {
|
|
57
|
+
const { adapter, requestInboxPass, openActivity, onTokenRefresh } = args
|
|
58
|
+
const opened = () => {
|
|
59
|
+
guarded('requestInboxPass', requestInboxPass)
|
|
60
|
+
guarded('openActivity', openActivity)
|
|
61
|
+
}
|
|
62
|
+
if (!initialConsumed) {
|
|
63
|
+
initialConsumed = true
|
|
64
|
+
try {
|
|
65
|
+
void adapter
|
|
66
|
+
.getInitialNotification()
|
|
67
|
+
.then(e => {
|
|
68
|
+
if (e) opened()
|
|
69
|
+
})
|
|
70
|
+
.catch(e => warn('getInitialNotification', e))
|
|
71
|
+
} catch (e) {
|
|
72
|
+
warn('getInitialNotification', e)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const offs = [
|
|
76
|
+
subscribe('onNotificationOpened', () => adapter.onNotificationOpened(opened)),
|
|
77
|
+
subscribe('onForegroundMessage', () =>
|
|
78
|
+
adapter.onForegroundMessage(() => guarded('requestInboxPass', requestInboxPass))
|
|
79
|
+
),
|
|
80
|
+
subscribe('onTokenRefresh', () => adapter.onTokenRefresh(() => guarded('onTokenRefresh', onTokenRefresh)))
|
|
81
|
+
]
|
|
82
|
+
return () => offs.forEach(off => guarded('unsubscribe', off))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* How long one registration sync may run before it is given up on. React
|
|
87
|
+
* Native's Android fetch has no default timeout, so a stalled connection would
|
|
88
|
+
* otherwise hold the lock below until the next wallet build.
|
|
89
|
+
*/
|
|
90
|
+
export const PUSH_SYNC_TIMEOUT_MS = 30_000
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Race one run against PUSH_SYNC_TIMEOUT_MS. The run itself cannot be cancelled,
|
|
94
|
+
* so on a timeout it is simply abandoned: whatever it settles with later (its
|
|
95
|
+
* rejection included) is handled by the race and ignored.
|
|
96
|
+
*/
|
|
97
|
+
async function runWithTimeout(run: () => Promise<void>): Promise<void> {
|
|
98
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
99
|
+
const timeout = new Promise<never>((_, reject) => {
|
|
100
|
+
timer = setTimeout(() => reject(new Error('timed out')), PUSH_SYNC_TIMEOUT_MS)
|
|
101
|
+
})
|
|
102
|
+
try {
|
|
103
|
+
await Promise.race([run(), timeout])
|
|
104
|
+
} finally {
|
|
105
|
+
clearTimeout(timer)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Serialize an async job that several triggers can fire at once (startup,
|
|
111
|
+
* token refresh, return to foreground). Never two runs at the same time; calls
|
|
112
|
+
* that land while one is in flight are folded into a single rerun after it
|
|
113
|
+
* finishes, not one rerun each. A run that does not finish within
|
|
114
|
+
* PUSH_SYNC_TIMEOUT_MS is logged and let go, so a hung request cannot block
|
|
115
|
+
* every later sync. The returned promise settles once the work it asked for
|
|
116
|
+
* has run, and never rejects.
|
|
117
|
+
*/
|
|
118
|
+
export function coalesceRuns(run: () => Promise<void>): () => Promise<void> {
|
|
119
|
+
let inFlight: Promise<void> | undefined
|
|
120
|
+
let rerun = false
|
|
121
|
+
return () => {
|
|
122
|
+
if (inFlight) {
|
|
123
|
+
rerun = true
|
|
124
|
+
return inFlight
|
|
125
|
+
}
|
|
126
|
+
inFlight = (async () => {
|
|
127
|
+
try {
|
|
128
|
+
do {
|
|
129
|
+
rerun = false
|
|
130
|
+
try {
|
|
131
|
+
await runWithTimeout(run)
|
|
132
|
+
} catch (e) {
|
|
133
|
+
warn('registration sync', e)
|
|
134
|
+
}
|
|
135
|
+
} while (rerun)
|
|
136
|
+
} finally {
|
|
137
|
+
inFlight = undefined
|
|
138
|
+
}
|
|
139
|
+
})()
|
|
140
|
+
return inFlight
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Has this device already seen the push notification advisory?
|
|
3
|
+
*
|
|
4
|
+
* This flag gates the one-time NotificationAdvisoryModal shown the first time
|
|
5
|
+
* the user picks "Share remote link" on "Get paid". The modal explains that
|
|
6
|
+
* the phone will next ask to allow notifications so BSV Wallet can tell the
|
|
7
|
+
* user when a MessageBox payment arrives, even while the app is in the
|
|
8
|
+
* background. This flag is a device-level UX preference, not a security
|
|
9
|
+
* record, so unlike backupAttestation it is not scoped per wallet identity —
|
|
10
|
+
* there is no per-identity harm in a shared device remembering "already
|
|
11
|
+
* explained this."
|
|
12
|
+
*/
|
|
13
|
+
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
14
|
+
|
|
15
|
+
const KEY = 'push_advisory_shown_v1'
|
|
16
|
+
|
|
17
|
+
export const pushAdvisory = {
|
|
18
|
+
async get(): Promise<boolean> {
|
|
19
|
+
try {
|
|
20
|
+
return (await AsyncStorage.getItem(KEY)) === 'true'
|
|
21
|
+
} catch {
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
async set(): Promise<void> {
|
|
27
|
+
try {
|
|
28
|
+
await AsyncStorage.setItem(KEY, 'true')
|
|
29
|
+
} catch {
|
|
30
|
+
// Advisory only — a failed write just means the modal shows again next time.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|