Skip to content

Instantly share code, notes, and snippets.

@denisborovikov
Last active October 27, 2022 22:27
Show Gist options
  • Save denisborovikov/c80c00515e1a88d7d3cb43af95b73294 to your computer and use it in GitHub Desktop.
Save denisborovikov/c80c00515e1a88d7d3cb43af95b73294 to your computer and use it in GitHub Desktop.
const getUserProfile = useAPIGetUserProfile({ enabled: false })
const createCognitoPinMutation = useAPICreateCognitoPin()
const verifyCognitoPinMutation = useAPIVerifyCognitoPin()
const tokenizeCardPinMutation = useAPITokenizePin()
const setCardPinMutation = useAPISetCardPin()
const [state, send] = useMachine(createPinMachine, {
services: {
async createCognitoPin(context) {
return await createCognitoPinMutation.mutateAsync(context.pin)
},
async verifyCognitoPin(context) {
return await verifyCognitoPinMutation.mutateAsync(context.pin)
},
async tokenizeCardPin(context) {
return await Promise.all([
tokenizeCardPinMutation.mutateAsync({pin: context.pin}),
getUserProfile.refetch({ throwOnError: true }),
])
},
async updateCardPin(context) {
setCardPinMutation.mutateAsync({
cardId: context.cardId,
tokenizedPin: context.tokenizedPin,
})
},
},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment