import * as React from 'react' ; import { Provider } from 'react-redux' ; import { createStore } from '@emeraldwallet/store' ; import { ApiMock , BackendMock , VaultMock } from "./backendMock" ; import { StoryContext , StoryFn } from "@storybook/addons/dist/types" ; import { IApi , WalletStateStorage } from "@emeraldwallet/core" ; import { WalletState } from '@emeraldpay/emerald-vault-core' ; import { AddressRole , EntryId } from "@emeraldpay/emerald-vault-core/lib/types" ; function createApi ( backend ) { return new ApiMock ( new VaultMock ( backend . vault ) ) ; } class WalletStateMock implements WalletStateStorage { load ( ) { return Promise . resolve ( { accountIndexes : [ ] } ) ; } next ( entryId , type ) { return Promise . resolve ( { accountIndexes : [ ] } ) ; } update ( entryId , receive , change ) { return Promise . resolve ( undefined ) ; } } const defaultBackend = new BackendMock ( ) ; const defaultWalletState = new WalletStateMock ( ) ; const defaultStore = createStore ( createApi ( defaultBackend ) , defaultBackend , defaultWalletState ) ; export function providerForStore ( backend , init = [ ] ) { const store = createStore ( createApi ( backend ) , backend , defaultWalletState ) ; init ?. forEach ( ( action ) => store . dispatch ( action ) ) ; return ( story , c ) => ( < Provider store = { store } > { story ( ) } < /Provider>); } const withProvider = ( story ) => ( < Provider store = { defaultStore } > { story ( ) } < /Provider>); export default withProvider ;