import { storiesOf } from '@storybook/react' ; import { interpret } from 'xstate' ; import React from 'react' ; import { MessagingServiceInterface , MessagingService } from '../../messaging' ; import { ethereumEnableWorkflow } from '../../workflows/ethereum-enable' ; import { EnableEthereum } from '../workflows/enable-ethereum-workflow' ; import { Store } from '../../store' ; import { WindowContext } from '../window-context' ; import { logger } from '../../logger' ; import { renderComponentInFrontOfApp } from './helpers' ; const store = new Store ( ) ; store . initialize ( [ '0x8624ebe7364bb776f891ca339f0aaa820cc64cc9fca6a28eec71e6d8fc950f29' ] ) ; const messagingService = new MessagingService ( store ) ; const testContext = { requestId : 55 } ; const windowMetamaskOk = { ethereum : { networkVersion : process . env . CHAIN_NETWORK_ID } } ; const windowNoMetamask = { } ; const windowWrongNetwork = { ethereum : { networkVersion : 3 } } ; const storyOf = ( state , window = windowMetamaskOk , name = undefined ) => { name = name || state . toString ( ) ; const machine = interpret < any , any , any > ( ethereumEnableWorkflow ( store , messagingService , testContext ) . withContext ( testContext ) , { devTools : true } ) ; machine . onEvent ( event => logger . info ( event . type ) ) . start ( state ) ; storiesOf ( 'Workflows / Enable Ethereum' , module ) . add ( name , renderComponentInFrontOfApp ( < WindowContext . Provider value = { window } > < EnableEthereum current = { machine . state } send = { machine . send } / > < /WindowContext.Provider>)); machine . stop ( ) ; } ; storyOf ( 'explainToUser' , windowNoMetamask , 'no metamask' ) ; storyOf ( 'explainToUser' , windowWrongNetwork , ' wrong network' ) ; storyOf ( 'explainToUser' ) ; storyOf ( 'enabling' ) ; storyOf ( 'done' ) ; storyOf ( 'retry' ) ; storyOf ( 'failure' ) ;