feat(state-machine): split fee into per-flow commission rates
Add cashInFeePercent (3.33%) and cashOutFeePercent (7.77%) to context. Set feePercent from the per-flow value on SELECT_CASH_IN/SELECT_CASH_OUT transitions. Preserve both rates across resetContext. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
3d9d85ba7f
commit
3a78fffb65
2 changed files with 18 additions and 4 deletions
|
|
@ -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'],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue