@@ -7,11 +7,7 @@ import {
7
7
PaymentSendStatus ,
8
8
} from "@domain/bitcoin/lightning"
9
9
import { AlreadyPaidError , CouldNotFindLightningPaymentFlowError } from "@domain/errors"
10
- import {
11
- DisplayCurrency ,
12
- NewDisplayCurrencyConverter ,
13
- usdMinorToMajorUnit ,
14
- } from "@domain/fiat"
10
+ import { DisplayCurrency , usdMinorToMajorUnit } from "@domain/fiat"
15
11
import {
16
12
checkedToBtcPaymentAmount ,
17
13
checkedToUsdPaymentAmount ,
@@ -48,6 +44,7 @@ import { addAttributesToCurrentSpan } from "@services/tracing"
48
44
49
45
import { Wallets } from "@app"
50
46
import { validateIsBtcWallet , validateIsUsdWallet } from "@app/wallets"
47
+ import { getCurrentPriceAsDisplayPriceRatio } from "@app/prices"
51
48
52
49
import { ResourceExpiredLockServiceError } from "@domain/lock"
53
50
@@ -94,9 +91,16 @@ export const payInvoiceByWalletId = async ({
94
91
paymentFlow,
95
92
senderWallet,
96
93
senderUsername : senderAccount . username ,
94
+ senderDisplayCurrency : senderAccount . displayCurrency ,
95
+ memo,
96
+ } )
97
+ : executePaymentViaLn ( {
98
+ decodedInvoice,
99
+ paymentFlow,
100
+ senderWallet,
101
+ senderDisplayCurrency : senderAccount . displayCurrency ,
97
102
memo,
98
103
} )
99
- : executePaymentViaLn ( { decodedInvoice, paymentFlow, senderWallet, memo } )
100
104
}
101
105
102
106
const payNoAmountInvoiceByWalletId = async ( {
@@ -133,9 +137,16 @@ const payNoAmountInvoiceByWalletId = async ({
133
137
paymentFlow,
134
138
senderWallet,
135
139
senderUsername : senderAccount . username ,
140
+ senderDisplayCurrency : senderAccount . displayCurrency ,
141
+ memo,
142
+ } )
143
+ : executePaymentViaLn ( {
144
+ decodedInvoice,
145
+ paymentFlow,
146
+ senderWallet,
147
+ senderDisplayCurrency : senderAccount . displayCurrency ,
136
148
memo,
137
149
} )
138
- : executePaymentViaLn ( { decodedInvoice, paymentFlow, senderWallet, memo } )
139
150
}
140
151
141
152
export const payNoAmountInvoiceByWalletIdForBtcWallet = async (
@@ -322,11 +333,13 @@ const executePaymentViaIntraledger = async <
322
333
paymentFlow,
323
334
senderWallet,
324
335
senderUsername,
336
+ senderDisplayCurrency,
325
337
memo,
326
338
} : {
327
339
paymentFlow : PaymentFlow < S , R >
328
340
senderWallet : WalletDescriptor < S >
329
341
senderUsername : Username | undefined
342
+ senderDisplayCurrency : DisplayCurrency
330
343
memo : string | null
331
344
} ) : Promise < PaymentSendStatus | ApplicationError > => {
332
345
addAttributesToCurrentSpan ( {
@@ -380,14 +393,13 @@ const executePaymentViaIntraledger = async <
380
393
const balanceCheck = paymentFlow . checkBalanceForSend ( balance )
381
394
if ( balanceCheck instanceof Error ) return balanceCheck
382
395
383
- const priceRatio = WalletPriceRatio ( {
384
- usd : paymentFlow . usdPaymentAmount ,
385
- btc : paymentFlow . btcPaymentAmount ,
396
+ const displayPriceRatio = await getCurrentPriceAsDisplayPriceRatio ( {
397
+ currency : senderDisplayCurrency ,
386
398
} )
387
- if ( priceRatio instanceof Error ) return priceRatio
388
- const displayCentsPerSat = priceRatio . usdPerSat ( )
389
-
390
- const converter = NewDisplayCurrencyConverter ( displayCentsPerSat )
399
+ if ( displayPriceRatio instanceof Error ) return displayPriceRatio
400
+ const amountDisplayCurrencyAsNumber = Number (
401
+ displayPriceRatio . convertFromWallet ( paymentFlow . btcPaymentAmount ) . amountInMinor ,
402
+ ) as DisplayCurrencyBaseAmount
391
403
392
404
if ( signal . aborted ) {
393
405
return new ResourceExpiredLockServiceError ( signal . error ?. message )
@@ -404,9 +416,9 @@ const executePaymentViaIntraledger = async <
404
416
pubkey : recipientPubkey ,
405
417
paymentAmounts : paymentFlow ,
406
418
407
- amountDisplayCurrency : converter . fromUsdAmount ( paymentFlow . usdPaymentAmount ) ,
419
+ amountDisplayCurrency : amountDisplayCurrencyAsNumber ,
408
420
feeDisplayCurrency : 0 as DisplayCurrencyBaseAmount ,
409
- displayCurrency : DisplayCurrency . Usd ,
421
+ displayCurrency : senderDisplayCurrency ,
410
422
411
423
memoOfPayer : memo || undefined ,
412
424
} ) )
@@ -417,9 +429,9 @@ const executePaymentViaIntraledger = async <
417
429
pubkey : recipientPubkey ,
418
430
paymentAmounts : paymentFlow ,
419
431
420
- amountDisplayCurrency : converter . fromUsdAmount ( paymentFlow . usdPaymentAmount ) ,
432
+ amountDisplayCurrency : amountDisplayCurrencyAsNumber ,
421
433
feeDisplayCurrency : 0 as DisplayCurrencyBaseAmount ,
422
- displayCurrency : DisplayCurrency . Usd ,
434
+ displayCurrency : senderDisplayCurrency ,
423
435
424
436
memoOfPayer : memo || undefined ,
425
437
senderUsername,
@@ -483,11 +495,13 @@ const executePaymentViaLn = async ({
483
495
decodedInvoice,
484
496
paymentFlow,
485
497
senderWallet,
498
+ senderDisplayCurrency,
486
499
memo,
487
500
} : {
488
501
decodedInvoice : LnInvoice
489
502
paymentFlow : PaymentFlow < WalletCurrency , WalletCurrency >
490
503
senderWallet : Wallet
504
+ senderDisplayCurrency : DisplayCurrency
491
505
memo : string | null
492
506
} ) : Promise < PaymentSendStatus | ApplicationError > => {
493
507
addAttributesToCurrentSpan ( {
@@ -525,22 +539,25 @@ const executePaymentViaLn = async ({
525
539
const lndService = LndService ( )
526
540
if ( lndService instanceof Error ) return lndService
527
541
528
- const priceRatio = WalletPriceRatio ( {
529
- usd : paymentFlow . usdPaymentAmount ,
530
- btc : paymentFlow . btcPaymentAmount ,
542
+ const displayPriceRatio = await getCurrentPriceAsDisplayPriceRatio ( {
543
+ currency : senderDisplayCurrency ,
531
544
} )
532
- if ( priceRatio instanceof Error ) return priceRatio
533
- const displayCentsPerSat = priceRatio . usdPerSat ( )
534
-
535
- const converter = NewDisplayCurrencyConverter ( displayCentsPerSat )
545
+ if ( displayPriceRatio instanceof Error ) return displayPriceRatio
546
+ const amountDisplayCurrencyAsNumber = Number (
547
+ displayPriceRatio . convertFromWallet ( paymentFlow . btcPaymentAmount ) . amountInMinor ,
548
+ ) as DisplayCurrencyBaseAmount
549
+ const feeDisplayCurrencyAsNumber = Number (
550
+ displayPriceRatio . convertFromWallet ( paymentFlow . btcProtocolAndBankFee )
551
+ . amountInMinor ,
552
+ ) as DisplayCurrencyBaseAmount
536
553
537
554
if ( signal . aborted ) {
538
555
return new ResourceExpiredLockServiceError ( signal . error ?. message )
539
556
}
540
557
541
558
const metadata = LedgerFacade . LnSendLedgerMetadata ( {
542
- amountDisplayCurrency : converter . fromUsdAmount ( paymentFlow . usdPaymentAmount ) ,
543
- feeDisplayCurrency : converter . fromUsdAmount ( paymentFlow . usdProtocolAndBankFee ) ,
559
+ amountDisplayCurrency : amountDisplayCurrencyAsNumber ,
560
+ feeDisplayCurrency : feeDisplayCurrencyAsNumber ,
544
561
displayCurrency : DisplayCurrency . Usd ,
545
562
546
563
paymentAmounts : paymentFlow ,
@@ -573,6 +590,12 @@ const executePaymentViaLn = async ({
573
590
if ( journal instanceof Error ) return journal
574
591
const { journalId } = journal
575
592
593
+ const walletPriceRatio = WalletPriceRatio ( {
594
+ usd : paymentFlow . usdPaymentAmount ,
595
+ btc : paymentFlow . btcPaymentAmount ,
596
+ } )
597
+ if ( walletPriceRatio instanceof Error ) return walletPriceRatio
598
+
576
599
let payResult : PayInvoiceResult | LightningServiceError
577
600
if ( rawRoute ) {
578
601
payResult = await lndService . payInvoiceViaRoutes ( {
@@ -584,7 +607,7 @@ const executePaymentViaLn = async ({
584
607
const maxFeeCheckArgs = {
585
608
maxFeeAmount : paymentFlow . btcProtocolAndBankFee ,
586
609
btcPaymentAmount : paymentFlow . btcPaymentAmount ,
587
- priceRatio,
610
+ priceRatio : walletPriceRatio ,
588
611
senderWalletCurrency : paymentFlow . senderWalletDescriptor ( ) . currency ,
589
612
}
590
613
const maxFeeCheck = LnFees ( ) . verifyMaxFee ( maxFeeCheckArgs )
@@ -638,6 +661,8 @@ const executePaymentViaLn = async ({
638
661
if ( ! rawRoute ) {
639
662
const reimbursed = await Wallets . reimburseFee ( {
640
663
paymentFlow,
664
+ senderDisplayAmount : amountDisplayCurrencyAsNumber ,
665
+ senderDisplayCurrency,
641
666
journalId,
642
667
actualFee : payResult . roundedUpFee ,
643
668
revealedPreImage : payResult . revealedPreImage ,
0 commit comments