import { storiesOf } from '@storybook/react' ; import { interpret } from 'xstate' ; import React from 'react' ; import { Participant , DomainBudget , ethBudget , BN , makeAddress } from '@statechannels/wallet-core' ; import { utils } from 'ethers' ; import { MessagingService , MessagingServiceInterface } from '../../messaging' ; import { CloseLedgerAndWithdraw } from '../workflows/close-ledger-and-withdraw' ; import { Store } from '../../store' ; import { logger } from '../../logger' ; import { workflow as closeLedgerWithdrawWorkflow , config , WorkflowContext } from '../../workflows/close-ledger-and-withdraw' ; import { renderComponentInFrontOfApp } from './helpers' ; const store = new Store ( ) ; store . initialize ( [ '0x8624ebe7364bb776f891ca339f0aaa820cc64cc9fca6a28eec71e6d8fc950f29' ] ) ; const messagingService = new MessagingService ( store ) ; const alice = { participantId : 'a' , signingAddress : makeAddress ( '0x1000000000000000000000000000000000000001' ) , destination : '0xad' as any } ; const bob = { participantId : 'b' , signingAddress : makeAddress ( '0x1000000000000000000000000000000000000002' ) , destination : '0xbd' as any } ; const budget = ethBudget ( 'rps.statechannels.org' , { availableReceiveCapacity : BN . from ( utils . parseEther ( '0.05' ) ) , availableSendCapacity : BN . from ( utils . parseEther ( '0.05' ) ) } ) ; const testContext = { player : alice , opponent : bob , requestId : 123 , ledgerId : 'ledger-id-123' , domain : 'abc.com' , budget } ; if ( config . states ) { Object . keys ( config . states ) . forEach ( state => { const machine = interpret < any , any , any > ( closeLedgerWithdrawWorkflow ( store , messagingService , testContext ) . withContext ( testContext ) , { devTools : true } ) ; machine . onEvent ( event => logger . info ( event . type ) ) . start ( state ) ; storiesOf ( 'Workflows / Close And Withdraw' , module ) . add ( state . toString ( ) , renderComponentInFrontOfApp ( < CloseLedgerAndWithdraw service = { machine } / > ) ) ; machine . stop ( ) ; } ) ; }