diff --git a/packages/state-machine/src/machine.ts b/packages/state-machine/src/machine.ts index 39fa61f..5cf5fc0 100644 --- a/packages/state-machine/src/machine.ts +++ b/packages/state-machine/src/machine.ts @@ -158,6 +158,8 @@ export function createATMMachine( ...initialContext, currency: context.currency, inventory: context.inventory, + cashInFeePercent: context.cashInFeePercent, + cashOutFeePercent: context.cashOutFeePercent, cashInSessionId: null, })), setStartTime: assign({ @@ -165,6 +167,12 @@ export function createATMMachine( txid: () => generateTxId(), cashInSessionId: () => generateSessionId(), }), + setCashInFee: assign({ + feePercent: ({ context }) => context.cashInFeePercent, + }), + setCashOutFee: assign({ + feePercent: ({ context }) => context.cashOutFeePercent, + }), addBill: assign({ billsInserted: ({ context, event }) => { if (event.type !== 'BILL_INSERTED') return context.billsInserted @@ -383,11 +391,11 @@ export function createATMMachine( on: { SELECT_CASH_IN: { target: 'cashIn', - actions: 'setStartTime', + actions: ['setStartTime', 'setCashInFee'], }, SELECT_CASH_OUT: { target: 'cashOut', - actions: 'setStartTime', + actions: ['setStartTime', 'setCashOutFee'], }, }, }, diff --git a/packages/state-machine/src/types.ts b/packages/state-machine/src/types.ts index 5a692ce..5960951 100644 --- a/packages/state-machine/src/types.ts +++ b/packages/state-machine/src/types.ts @@ -31,8 +31,12 @@ export interface ATMContext { currency: string /** Exchange rate (sats per fiat unit) */ exchangeRate: number - /** Fee percentage (0.02 = 2%) */ + /** Fee percentage (0.02 = 2%) — used at runtime for the active flow */ feePercent: number + /** Cash-in commission (0.02 = 2%) */ + cashInFeePercent: number + /** Cash-out commission (0.02 = 2%) */ + cashOutFeePercent: number /** ATM's available balance in sats (for limiting cash-in transactions) */ availableBalance: number @@ -129,7 +133,9 @@ export const initialContext: ATMContext = { satsAmount: 0, currency: 'USD', exchangeRate: 0, - feePercent: 0.02, + feePercent: 0.0333, + cashInFeePercent: 0.0333, + cashOutFeePercent: 0.0777, availableBalance: 0, invoice: null, clinkOffer: null,