@@ -3,15 +3,24 @@ import Offer from "./Offer"
33import { PaymentSendStatus } from "@domain/bitcoin/lightning"
44import { LedgerServiceError } from "@domain/ledger"
55import { ValidationError } from "@domain/shared"
6- import { accountLevel , isActiveAccount , isUsd , hasSufficientBalance , transferMin , validate , walletBelongsToAccount , transferMax , isBeforeExpiry } from "./Validations"
7- // import { sendBetweenAccounts } from "@services/ibex/send-between-accounts"
6+ import {
7+ accountLevel ,
8+ isActiveAccount ,
9+ isUsd ,
10+ hasSufficientBalance ,
11+ transferMin ,
12+ validate ,
13+ walletBelongsToAccount ,
14+ transferMax ,
15+ isBeforeExpiry ,
16+ } from "./Validations"
817import { RepositoryError } from "@domain/errors"
918import { AccountsRepository , WalletsRepository } from "@services/mongoose"
1019import Ibex from "@services/ibex/client"
1120import { EmailService } from "@services/email"
1221import { CashoutDetails , ValidationInputs } from "./types"
1322
14- // Only way to construct a ValidOffer is using the static method which contains validations
23+ // Only way to construct a ValidOffer is using the static method which contains validations
1524class ValidOffer extends Offer {
1625 readonly wallet : Wallet
1726 readonly account : Account
@@ -23,24 +32,26 @@ class ValidOffer extends Offer {
2332 this . account = account
2433 }
2534
26- static from = async ( details : CashoutDetails ) : Promise < ValidOffer | ValidationError > => {
35+ static from = async (
36+ details : CashoutDetails ,
37+ ) : Promise < ValidOffer | ValidationError > => {
2738 const wallet = await WalletsRepository ( ) . findById ( details . ibexTrx . userAcct )
2839 if ( wallet instanceof RepositoryError ) return new ValidationError ( wallet )
29-
40+
3041 const account = await AccountsRepository ( ) . findById ( wallet . accountId )
3142 if ( account instanceof RepositoryError ) return new ValidationError ( account )
3243
3344 const inputs : ValidationInputs = { ...details , wallet, account }
3445 const validationErrs = await validate ( inputs , [
35- isUsd ,
46+ isUsd ,
3647 transferMin ,
3748 transferMax ,
3849 isActiveAccount ,
3950 accountLevel ,
4051 walletBelongsToAccount ,
4152 hasSufficientBalance ,
4253 isBeforeExpiry ,
43- // TODO daily/weekly/monthly volume limits
54+ // TODO daily/weekly/monthly volume limits
4455 ] )
4556 if ( validationErrs . length > 0 ) return new ValidationError ( validationErrs )
4657
@@ -49,19 +60,19 @@ class ValidOffer extends Offer {
4960
5061 async execute ( ) : Promise < PaymentSendStatus | Error > {
5162 const resp = await Ibex . payInvoice ( {
52- accountId : this . details . ibexTrx . userAcct ,
53- invoice : this . details . ibexTrx . invoice . paymentRequest as unknown as Bolt11
63+ accountId : this . details . ibexTrx . userAcct ,
64+ invoice : this . details . ibexTrx . invoice . paymentRequest as unknown as Bolt11 ,
5465 } )
55- if ( resp instanceof Error ) return resp
66+ if ( resp instanceof Error ) return resp
5667
5768 // balance the diff
5869 // const ibexResp = await sendBetweenAccounts(
59- // IbexAccount.fromWallet(this.wallet),
70+ // IbexAccount.fromWallet(this.wallet),
6071 // flashWallet,
6172 // this.details.ibexTransfer,
6273 // "Withdraw to bank",
63- // )
64- // if (ibexResp instanceof Error) return ibexResp
74+ // )
75+ // if (ibexResp instanceof Error) return ibexResp
6576
6677 const ledgerResp = await LedgerService ( ) . recordCashOut ( this . details )
6778 if ( ledgerResp instanceof LedgerServiceError ) {
@@ -75,4 +86,4 @@ class ValidOffer extends Offer {
7586 }
7687}
7788
78- export default ValidOffer
89+ export default ValidOffer
0 commit comments