import { useState } from 'react' import { openMybringActivation } from '../model/activation' export interface MybringActivation { start: () => void starting: boolean failed: boolean } /** * Starts an activation that takes the merchant to Mybring, once at a time, * and tells whether it could not be started. */ export const useMybringActivation = (): MybringActivation => { const [starting, setStarting] = useState(false) const [failed, setFailed] = useState(false) const start = () => { if (starting) { return } setStarting(true) setFailed(false) openMybringActivation().catch(() => { setStarting(false) setFailed(true) }) } return { start, starting, failed } }