Skip to content

Instantly share code, notes, and snippets.

@sharmaadityaHQ
Last active June 15, 2021 09:01
Show Gist options
  • Save sharmaadityaHQ/9e67b6bef4c9456ef3072adb43061743 to your computer and use it in GitHub Desktop.
Save sharmaadityaHQ/9e67b6bef4c9456ef3072adb43061743 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const rentPay = Machine({
id: 'rentPay',
initial: 'landing',
context: {
isNtuUser: true,
isKycDone: false,
flow: 'new',
paymentInstrument: 'upi',
isCheckoutEnabled: false
},
states: {
landing: {
on: {
LOTTIE_COMPLETED: [{
target: 'new_user',
cond: 'isNtu',
actions: ['routePush']
},{
target: 'repeat_user'
}]
}
},
new_user: {
on: {
'': 'amount'
}
},
repeat_user: {
on: {
NEW_LANDLORD: 'amount',
PREVIOUS_LANDLORD: 'biller_bottom_sheet'
}
},
amount: {
on: {
PROCEED: [{
target: 'biller_name',
cond: 'isBillerNotSelected'
},{
target: 'pan_details',
cond: 'isPanRequired'
},{
target: 'payment_summary'
}]
}
},
biller_name: {
on: {
PROCEED: [{
target: 'upi_details',
cond: 'isUpiSelected'
},{
target: 'account_details'
}]
}
},
biller_bottom_sheet: {
on: {
SELECT: [{
target: 'amount',
cond: 'isCustomPayment'
},{
target: 'checkout_sdk',
cond: 'isCheckoutEnabled'
},{
target: 'payment_summary'
}]
}
},
pan_details: {
on: {
PROCEED: [{
target: 'payment_summary',
cond: 'isCustomRepeatOrder'
},{
target: 'sku_details'
}]
}
},
account_details: {
on: {
SWITCH: 'upi_details',
PROCEED: [{
target: 'pan_details',
cond: 'isPanRequired'
},{
target: 'sku_details'
}]
}
},
upi_details: {
on: {
SWITCH: 'account_details',
PROCEED: [{
target: 'pan_details',
cond: 'isPanRequired'
},{
target: 'sku_details'
}]
}
},
sku_details : {
on: {
PROCEED: [{
target: 'checkout_sdk',
cond: 'isCheckoutEnabled'
},{
target: 'payment_summary'
}]
}
},
payment_summary: {
on: {
'': 'payment_sdk'
}
},
checkout_sdk: {},
payment_sdk: {}
}
},
{
actions: {
routePush: (context,event,meta) => {
console.log('action performed')
console.log(context,event, meta);
}
},
guards: {
isNtu: (context,event) => context.isNtuUser,
isCustomPayment: (context,event) => context.flow === 'custom',
isPanRequired: (context,event) => !context.isKycDone && event.amount > 50000,
isCustomRepeatOrder: (context, event) => !context.isNtuUser && !context.isCheckoutEnabled && context.paymentInstrument === 'upi',
isBillerNotSelected: (context, event) => context.isNtuUser,
isUpiSelected: (context,event) => context.paymentInstrument === 'upi',
isCheckoutEnabled: (context, event) => !context.paymentInstrument === 'upi' && context.isCheckoutEnabled
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment