mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-01 21:57:06 +01:00
c5368c152b
* added storybook test runner * added test runner in ci * updated test for ci and fixed lint error * updated lavamoat policy * updated test command * updated playwright * changed command to storybook;ci * updated command * updated instance for test-storybook * updated playwright * added playwright step * replaced concurrently with start-server-and-test * updated the static storybook directory * replaced first with last * updated lock file * replaced first with last * updated test-storybook with maxworkers * updated .depchechrc * updated yml * removed id from banner base * replaced broken stories with .stories-to-do.js extesnsion * updated token allowance story * removed duplicacies from yarn * fixed lavamoat * removed filename comment * updated links for docs * fixed file extension for stories * updated path for stories.json * updated stories.json path * yarn updated * updated stories * updated yarn * updated wait on
90 lines
2.2 KiB
JavaScript
90 lines
2.2 KiB
JavaScript
/* eslint-disable react/prop-types */
|
|
|
|
import React, { useEffect, useState } from 'react';
|
|
import { Provider } from 'react-redux';
|
|
import testData from '../../../../../.storybook/test-data';
|
|
import { calcGasTotal } from '../../../../../shared/lib/transactions-controller-utils';
|
|
import { GAS_INPUT_MODES } from '../../../../ducks/send';
|
|
import { updateMetamaskState } from '../../../../store/actions';
|
|
import configureStore from '../../../../store/store';
|
|
import README from './README.mdx';
|
|
import SendGasRow from './send-gas-row.component';
|
|
|
|
const store = configureStore(testData);
|
|
|
|
export default {
|
|
title: 'Pages/Send/SendContent/SendGasRow',
|
|
|
|
decorators: [(story) => <Provider store={store}>{story()}</Provider>],
|
|
parameters: {
|
|
docs: {
|
|
page: README,
|
|
},
|
|
},
|
|
argTypes: {
|
|
insufficientBalance: {
|
|
control: { type: 'boolean' },
|
|
},
|
|
},
|
|
args: {
|
|
insufficientBalance: false,
|
|
},
|
|
};
|
|
|
|
export const DefaultStory = (args) => {
|
|
const state = store.getState();
|
|
const { metamask } = state;
|
|
const { send } = metamask;
|
|
const [sendState, setSendState] = useState(send);
|
|
|
|
useEffect(() => {
|
|
const newState = Object.assign(metamask, {
|
|
send: sendState,
|
|
});
|
|
store.dispatch(updateMetamaskState(newState));
|
|
}, [sendState, metamask]);
|
|
|
|
const updateGasPrice = ({ gasPrice, gasLimit }) => {
|
|
let newGasTotal = send.gasTotal;
|
|
if (send.gasLimit) {
|
|
newGasTotal = calcGasTotal(gasLimit, gasPrice);
|
|
}
|
|
const newState = {
|
|
...state.metamask.send,
|
|
gasPrice,
|
|
gasTotal: newGasTotal,
|
|
};
|
|
|
|
setSendState(newState);
|
|
};
|
|
|
|
const updateGasLimit = (limit) => {
|
|
let newGasTotal = send.gasTotal;
|
|
if (send.gasPrice) {
|
|
newGasTotal = calcGasTotal(limit, send.gasPrice);
|
|
}
|
|
const newState = {
|
|
...state.metamask.send,
|
|
gasLimit: limit,
|
|
gasTotal: newGasTotal,
|
|
};
|
|
|
|
setSendState(newState);
|
|
};
|
|
|
|
return (
|
|
<div style={{ width: 500 }}>
|
|
<SendGasRow
|
|
{...args}
|
|
updateGasPrice={updateGasPrice}
|
|
updateGasLimit={updateGasLimit}
|
|
gasPrice={send.gasPrice}
|
|
gasLimit={send.gasLimit}
|
|
gasInputMode={GAS_INPUT_MODES.INLINE}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
DefaultStory.storyName = 'SendGasRow';
|