Last active
January 9, 2020 09:51
-
-
Save drivasperez/c5da8287e71b8afb35225c5582e78877 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const initialContext = { | |
betDetails: null, | |
settleDetails: null, | |
balanceDetails: null, | |
barcode: null, | |
scannedBarcode: null, | |
cashDrawerOpen: false, | |
playerDetails: null, | |
playersID: null, | |
sportsbookDetails: null, | |
deviceType: "desktop" | |
}; | |
const scanBet = { | |
initial: "please_scan", | |
states: { | |
please_scan: { | |
on: { | |
SCAN: { target: "pending", actions: "assignScannedBarcode" } | |
} | |
}, | |
pending: { | |
invoke: { | |
src: "fetchScannedBarcodeDetails", | |
onDone: { target: "settle_bet", actions: "assignSettleDetails" }, | |
onError: "error" | |
} | |
}, | |
settle_bet: { | |
invoke: { | |
src: "openCashDrawerForPayout" | |
}, | |
on: { | |
CLOSED_CASH_DRAWER: "settling", | |
CANCEL: "cancelled" | |
} | |
}, | |
settling: { | |
invoke: { | |
src: "settleBettingShopBet", | |
onError: "error", | |
onDone: "settled" | |
} | |
}, | |
cancelled: { type: "final" }, | |
settled: { type: "final" }, | |
error: { | |
on: { | |
RETRY: "please_scan" | |
} | |
} | |
}, | |
onDone: "menu" | |
}; | |
const placeBet = { | |
initial: "show_sportsbook", | |
states: { | |
show_sportsbook: { | |
on: { | |
BET_RECEIVED: { | |
target: "received_bet", | |
actions: "assignBetDetails" | |
} | |
} | |
}, | |
received_bet: { | |
invoke: { | |
src: "loadBarcode", | |
onDone: { | |
target: "print_bet", | |
actions: "assignBarcode" | |
}, | |
onError: "error" | |
} | |
}, | |
print_bet: { | |
on: { | |
CONFIRMED_BET: "open_drawer", | |
CANCELLED_BET: "cancelling" | |
} | |
}, | |
open_drawer: { | |
invoke: { | |
src: "openCashDrawer", | |
onDone: "completing", | |
onError: "completing" // currently always 405 errors on OPTIONS request. | |
} | |
}, | |
completing: { | |
invoke: { | |
src: "confirmBetMade", | |
onDone: "completed", | |
onError: "error" | |
} | |
}, | |
completed: { | |
type: "final", | |
invoke: { | |
src: "updateBalanceDetails", | |
onDone: { target: "", actions: "assignBalanceDetails" } | |
} | |
}, | |
cancelled: { type: "final" }, | |
cancelling: { | |
invoke: { | |
src: "cancelBet", | |
onDone: "cancelled", | |
onError: "error" | |
} | |
}, | |
error: {} | |
}, | |
onDone: "menu" | |
}; | |
const sportsbook = { | |
initial: "idle", | |
states: { | |
idle: { | |
on: { | |
LOAD_SPORTSBOOK: { | |
target: "connecting", | |
actions: "assignSelectedPlayer" | |
} | |
} | |
}, | |
connecting: { | |
invoke: { | |
src: "getIframeData", | |
onDone: { | |
target: "connected", | |
actions: ["assignIframeData", "updatePlayerDetails"] | |
}, | |
onError: "error" | |
} | |
}, | |
connected: { | |
on: { | |
CLEAR_SELECTED_PLAYER: { | |
target: "connecting", | |
actions: "clearSelectedPlayer" | |
}, | |
LOAD_SPORTSBOOK: { | |
target: "connecting", | |
actions: "assignSelectedPlayer" | |
} | |
} | |
}, | |
error: { | |
on: { | |
LOAD_SPORTSBOOK: { | |
target: "connecting", | |
actions: "assignSelectedPlayer" | |
} | |
} | |
} | |
} | |
}; | |
const playerProfile = { | |
initial: "idle", | |
on: { | |
LOAD_PLAYER_PROFILE: { | |
target: ".pending", | |
cond: "playerIDExists" | |
} | |
}, | |
states: { | |
idle: {}, | |
pending: { | |
invoke: { | |
src: "loadPlayerProfile", | |
onDone: { target: "idle", actions: "assignPlayerProfile" }, | |
onError: "error" | |
} | |
}, | |
error: {} | |
} | |
}; | |
const adjustCustomerBalance = { | |
initial: "idle", | |
states: { | |
idle: { | |
on: { | |
OKAY: "okay" | |
}, | |
entry: "updatePlayerDetails", | |
invoke: { | |
src: "updateBalanceDetails", | |
onDone: { target: "", actions: "assignBalanceDetails" } | |
} | |
}, | |
okay: { | |
invoke: { | |
src: "openCashDrawer", | |
onError: "idle", | |
onDone: "idle" | |
} | |
}, | |
error: { | |
on: { | |
RETRY: "idle" | |
} | |
} | |
}, | |
onDone: "menu" | |
}; | |
const POSMachine = Machine( | |
{ | |
id: "pos", | |
type: "parallel", | |
context: initialContext, | |
states: { | |
sportsbook, | |
playerProfile, | |
stages: { | |
initial: "menu", | |
on: { | |
RESET: { | |
target: "stages.menu" | |
} | |
}, | |
states: { | |
menu: { | |
invoke: { | |
src: "updateBalanceDetails", | |
onDone: { target: "", actions: "assignBalanceDetails" } | |
}, | |
on: { | |
PLACE_BET: "place_bet", | |
SCAN_BET: "scan_bet", | |
DEPOSIT: "customer_deposit", | |
PAYOUT: "customer_payout" | |
} | |
}, | |
place_bet: placeBet, | |
scan_bet: scanBet, | |
customer_deposit: adjustCustomerBalance, | |
customer_payout: adjustCustomerBalance | |
} | |
} | |
} | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment