1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

GasModalPageContainer story: convert knobs and actions to controls / args (#13516)

This commit is contained in:
BoxedFruits 2022-03-30 09:46:37 -04:00 committed by GitHub
parent 69d7c51c56
commit 950de390b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { number } from '@storybook/addon-knobs';
import configureStore from '../../../store/store'; import configureStore from '../../../store/store';
import testData from '../../../../.storybook/test-data'; import testData from '../../../../.storybook/test-data';
import { formatETHFee } from '../../../helpers/utils/formatters'; import { formatETHFee } from '../../../helpers/utils/formatters';
@ -14,13 +13,112 @@ import { ETH } from '../../../helpers/constants/common';
import { calcGasTotal, isBalanceSufficient } from '../../send/send.utils'; import { calcGasTotal, isBalanceSufficient } from '../../send/send.utils';
import { conversionLessThan } from '../../../../shared/modules/conversion.utils'; import { conversionLessThan } from '../../../../shared/modules/conversion.utils';
import GasModalPageContainer from './swaps-gas-customization-modal.component'; import GasModalPageContainer from './swaps-gas-customization-modal.component';
// Using Test Data For Redux // Using Test Data For Redux
const store = configureStore(testData); const store = configureStore(testData);
export default { export default {
title: 'Pages/Swaps/GasModalPageContainer', title: 'Pages/Swaps/GasModalPageContainer',
id: __filename, id: __filename,
component: GasModalPageContainer,
argTypes: {
sendAmountArg: {
name: 'Send Amount (this should be static)',
control: { type: 'number', min: 0, step: 0.01 },
},
walletBalance: {
name: 'Wallet Balance (this should be static)',
control: { type: 'number', min: 0, step: 0.01 },
},
averageGasPrice: {
name: 'Average Gas Price',
control: { type: 'number', min: 0, step: 0.01 },
},
insufficientBalance: {
table: {
disable: true,
},
},
gasPriceButtonGroupProps: {
table: {
disable: true,
},
},
infoRowProps: {
table: {
disable: true,
},
},
onSubmit: {
table: {
disable: true,
},
},
cancelAndClose: {
table: {
disable: true,
},
},
showCustomPriceTooLowWarning: {
table: {
disable: true,
},
},
disableSave: {
table: {
disable: true,
},
},
customGasLimitMessage: {
table: {
disable: true,
},
},
usdConversionRate: {
table: {
disable: true,
},
},
customGasPrice: {
table: {
disable: true,
},
},
customGasLimit: {
table: {
disable: true,
},
},
setSwapsCustomizationModalLimit: {
table: {
disable: true,
},
},
setSwapsCustomizationModalPrice: {
table: {
disable: true,
},
},
customTotalSupplement: {
table: {
disable: true,
},
},
gasEstimateLoadingHasFailed: {
table: {
disable: true,
},
},
minimumGasLimit: {
table: {
disable: true,
},
},
},
args: {
sendAmountArg: 0.01,
walletBalance: 10,
averageGasPrice: 2,
},
decorators: [(story) => <Provider store={store}>{story()}</Provider>], decorators: [(story) => <Provider store={store}>{story()}</Provider>],
}; };
@ -38,17 +136,18 @@ const sumHexWEIsToRenderableEth = (hexWEIs, currencySymbol = 'ETH') => {
); );
}; };
export const DefaultStory = () => { export const DefaultStory = (args) => {
// Send Amount Data const { sendAmountArg, walletBalance, averageGasPrice } = args;
const hexWei = getWeiHexFromDecimalValue({ const hexWei = getWeiHexFromDecimalValue({
value: String(number('Send Amount (this should be static)', 0.01)), value: sendAmountArg,
fromCurrency: ETH, fromCurrency: ETH,
fromDenomination: ETH, fromDenomination: ETH,
}); });
// ETH Balance // ETH Balance
const balanceHexWei = getWeiHexFromDecimalValue({ const balanceHexWei = getWeiHexFromDecimalValue({
value: String(number('Wallet Balance (this should be static)', 1.582717)), value: walletBalance,
fromCurrency: ETH, fromCurrency: ETH,
fromDenomination: ETH, fromDenomination: ETH,
}); });
@ -103,11 +202,9 @@ export const DefaultStory = () => {
// Check If Gas Price Is Too Low // Check If Gas Price Is Too Low
const shouldShowCustomPriceTooLowWarning = () => { const shouldShowCustomPriceTooLowWarning = () => {
const average = number('Average Gas Price', 2);
const customGasPrice = gasPrice; const customGasPrice = gasPrice;
if (!customGasPrice || average === undefined) { if (!customGasPrice || averageGasPrice === undefined) {
return false; return false;
} }
@ -118,7 +215,7 @@ export const DefaultStory = () => {
fromDenomination: 'WEI', fromDenomination: 'WEI',
toDenomination: 'GWEI', toDenomination: 'GWEI',
}, },
{ value: average, fromNumericBase: 'dec' }, { value: averageGasPrice, fromNumericBase: 'dec' },
); );
return customPriceRisksSwapFailure; return customPriceRisksSwapFailure;