/* eslint-disable max-len */ import React from 'react' import { storiesOf } from '@storybook/react' import { action } from '@storybook/addon-actions' import { number, select, text } from '@storybook/addon-knobs' import { State, Store } from '@sambego/storybook-state' import { Modal, Page } from 'components/UI' import { Pay, PayButtons, PayHeader, PaySummaryLightning, PaySummaryOnChain } from 'components/Pay' const delay = time => new Promise(resolve => setTimeout(() => resolve(), time)) const store = new Store({ chain: 'bitcoin', network: 'testnet', cryptoName: 'Bitcoin', walletBalance: 10000000, channelBalance: 25000, cryptoCurrency: 'btc', cryptoCurrencyTicker: 'BTC', cryptoCurrencies: [ { key: 'btc', name: 'BTC' }, { key: 'bits', name: 'bits' }, { key: 'sats', name: 'satoshis' } ], fiatCurrency: 'USD', fiatCurrencies: ['USD', 'EUR', 'GBP'], nodes: [ { pub_key: '03c856d2dbec7454c48f311031f06bb99e3ca1ab15a9b9b35de14e139aa663b463', alias: 'htlc.me' } ], routes: [], currentTicker: { USD: { last: 6477.78 }, EUR: { last: 5656.01 }, GBP: { last: 5052.73 } }, isProcessing: false }) const mockPayInvoice = async () => { action('mockPayInvoice') store.set({ isProcessing: true }) await delay(2000) store.set({ isProcessing: false }) } const mockSendCoins = async () => { action('mockSendCoins') store.set({ isProcessing: true }) await delay(2000) store.set({ isProcessing: false }) } const mockQueryFees = async () => { action('mockQueryFees') store.set({ isQueryingFees: true }) await delay(2000) store.set({ onchainFees: { fastestFee: 8, halfHourFee: 8, hourFee: 4 } }) store.set({ isQueryingFees: false }) } const mockQueryRoutes = async pubKey => { action('mockQueryRoutes', pubKey) store.set({ isQueryingRoutes: true }) await delay(2000) const nodes = store.get('nodes') if (nodes.find(n => n.pub_key === pubKey)) { store.set({ routes: [ { total_time_lock: 547118, total_fees: '0', total_amt: '10000', hops: [ { chan_id: '565542601916153857', chan_capacity: '15698', amt_to_forward: '10000', fee: '0', expiry: 546974, amt_to_forward_msat: '10000010', fee_msat: '21' } ], total_fees_msat: '21', total_amt_msat: '10000021' }, { total_time_lock: 547118, total_fees: '0', total_amt: '10000', hops: [ { chan_id: '565542601916153857', chan_capacity: '15698', amt_to_forward: '10000', fee: '0', expiry: 546974, amt_to_forward_msat: '10000010', fee_msat: '3' } ], total_fees_msat: '3', total_amt_msat: '10000021' } ] }) } else { store.set({ routes: [] }) } store.set({ isQueryingRoutes: false }) } const setCryptoCurrency = key => { const items = store.get('cryptoCurrencies') const item = items.find(i => i.key === key) store.set({ cryptoCurrency: item.key }) store.set({ cryptoCurrencyTicker: item.name }) } const setFiatCurrency = key => { store.set({ fiatCurrency: key }) } storiesOf('Containers.Pay', module) .add('Pay', () => { const network = select( 'Network', { Testnet: 'testnet', Mainnet: 'mainnet' }, 'testnet' ) return ( ) }) .addWithChapters('PayHeader', { chapters: [ { sections: [ { title: 'On-chain', sectionFn: () => }, { title: 'Off-chain', sectionFn: () => }, { title: 'Generic', sectionFn: () => } ] } ] }) .addWithChapters('PaySummary', { chapters: [ { sections: [ { title: 'PaySummaryLightning', sectionFn: () => ( ), options: { decorator: story => {story()} } }, { title: 'PaySummaryOnChain', sectionFn: () => { mockQueryFees() return ( ) }, options: { decorator: story => {story()} } } ] } ] }) .addWithChapters('PayButtons', { chapters: [ { sections: [ { title: 'Default', sectionFn: () => }, { title: 'Disabled', sectionFn: () => }, { title: 'Processing', sectionFn: () => } ] } ] })