2021-08-17 07:33:46 +02:00
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { text } from '@storybook/addon-knobs';
|
2021-09-08 01:51:41 +02:00
|
|
|
import { store, getNewState } from '../../../.storybook/preview';
|
2021-10-01 18:07:29 +02:00
|
|
|
import { suggestedAssets } from '../../../.storybook/initial-states/approval-screens/add-suggested-token';
|
2021-08-17 07:33:46 +02:00
|
|
|
import { updateMetamaskState } from '../../store/actions';
|
|
|
|
import ConfirmAddSuggestedToken from '.';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Confirmation Screens',
|
2021-09-15 20:55:48 +02:00
|
|
|
id: __filename,
|
2021-08-17 07:33:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const PageSet = ({ children }) => {
|
|
|
|
const symbol = text('symbol', 'META');
|
|
|
|
const image = text('Icon URL', 'metamark.svg');
|
|
|
|
|
|
|
|
const state = store.getState();
|
2021-10-01 18:07:29 +02:00
|
|
|
const suggestedAssetsState = state.metamask.suggestedAssets;
|
2021-08-17 07:33:46 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
2021-10-01 18:07:29 +02:00
|
|
|
suggestedAssetsState[0].symbol = symbol;
|
2021-08-17 07:33:46 +02:00
|
|
|
store.dispatch(
|
2021-09-08 01:51:41 +02:00
|
|
|
updateMetamaskState(
|
|
|
|
getNewState(state.metamask, {
|
2021-10-01 18:07:29 +02:00
|
|
|
suggestedAssets: suggestedAssetsState,
|
2021-09-08 01:51:41 +02:00
|
|
|
}),
|
|
|
|
),
|
2021-08-17 07:33:46 +02:00
|
|
|
);
|
2021-10-01 18:07:29 +02:00
|
|
|
}, [symbol, suggestedAssetsState, state.metamask]);
|
2021-08-17 07:33:46 +02:00
|
|
|
useEffect(() => {
|
2021-10-01 18:07:29 +02:00
|
|
|
suggestedAssetsState[0].image = image;
|
2021-08-17 07:33:46 +02:00
|
|
|
store.dispatch(
|
2021-09-08 01:51:41 +02:00
|
|
|
updateMetamaskState(
|
|
|
|
getNewState(state.metamask, {
|
2021-10-01 18:07:29 +02:00
|
|
|
suggestedAssets: suggestedAssetsState,
|
2021-09-08 01:51:41 +02:00
|
|
|
}),
|
|
|
|
),
|
2021-08-17 07:33:46 +02:00
|
|
|
);
|
2021-10-01 18:07:29 +02:00
|
|
|
}, [image, suggestedAssetsState, state.metamask]);
|
2021-08-17 07:33:46 +02:00
|
|
|
|
|
|
|
return children;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const AddSuggestedToken = () => {
|
2021-09-08 01:51:41 +02:00
|
|
|
const state = store.getState();
|
|
|
|
store.dispatch(
|
|
|
|
updateMetamaskState(
|
|
|
|
getNewState(state.metamask, {
|
2021-10-01 18:07:29 +02:00
|
|
|
suggestedAssets,
|
2021-09-08 01:51:41 +02:00
|
|
|
}),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2021-08-17 07:33:46 +02:00
|
|
|
return (
|
|
|
|
<PageSet>
|
|
|
|
<ConfirmAddSuggestedToken />
|
|
|
|
</PageSet>
|
|
|
|
);
|
|
|
|
};
|