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';
|
2022-02-01 16:30:15 +01:00
|
|
|
import { suggestedAssets as mockSuggestedAssets } 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 {
|
2021-12-01 20:27:57 +01:00
|
|
|
title: 'Pages/ConfirmAddSuggestedToken',
|
2021-09-15 20:55:48 +02:00
|
|
|
id: __filename,
|
2022-02-01 16:30:15 +01:00
|
|
|
argTypes: {
|
|
|
|
tokens: {
|
|
|
|
control: 'array',
|
|
|
|
table: { category: 'Data' },
|
|
|
|
},
|
|
|
|
suggestedAssets: {
|
|
|
|
control: 'array',
|
|
|
|
table: { category: 'Data' },
|
|
|
|
},
|
|
|
|
},
|
2021-08-17 07:33:46 +02:00
|
|
|
};
|
|
|
|
|
2022-02-01 16:30:15 +01:00
|
|
|
const { metamask: state } = store.getState();
|
|
|
|
|
|
|
|
const PageSet = ({ children, suggestedAssets, tokens }) => {
|
2021-08-17 07:33:46 +02:00
|
|
|
const symbol = text('symbol', 'META');
|
|
|
|
const image = text('Icon URL', 'metamark.svg');
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-02-01 16:30:15 +01:00
|
|
|
if (!suggestedAssets?.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
suggestedAssets[0].asset.image = image;
|
|
|
|
suggestedAssets[0].asset.symbol = symbol;
|
|
|
|
|
2021-08-17 07:33:46 +02:00
|
|
|
store.dispatch(
|
2021-09-08 01:51:41 +02:00
|
|
|
updateMetamaskState(
|
2022-02-01 16:30:15 +01:00
|
|
|
getNewState(state, {
|
|
|
|
suggestedAssets,
|
2021-09-08 01:51:41 +02:00
|
|
|
}),
|
|
|
|
),
|
2021-08-17 07:33:46 +02:00
|
|
|
);
|
2022-02-01 16:30:15 +01:00
|
|
|
}, [image, suggestedAssets, symbol]);
|
|
|
|
|
2021-08-17 07:33:46 +02:00
|
|
|
useEffect(() => {
|
|
|
|
store.dispatch(
|
2021-09-08 01:51:41 +02:00
|
|
|
updateMetamaskState(
|
2022-02-01 16:30:15 +01:00
|
|
|
getNewState(state, {
|
|
|
|
tokens,
|
2021-09-08 01:51:41 +02:00
|
|
|
}),
|
|
|
|
),
|
2021-08-17 07:33:46 +02:00
|
|
|
);
|
2022-02-01 16:30:15 +01:00
|
|
|
}, [tokens]);
|
2021-08-17 07:33:46 +02:00
|
|
|
|
|
|
|
return children;
|
|
|
|
};
|
|
|
|
|
2022-02-01 16:30:15 +01:00
|
|
|
export const DefaultStory = ({ suggestedAssets, tokens }) => {
|
|
|
|
return (
|
|
|
|
<PageSet suggestedAssets={suggestedAssets} tokens={tokens}>
|
|
|
|
<ConfirmAddSuggestedToken />
|
|
|
|
</PageSet>
|
2021-09-08 01:51:41 +02:00
|
|
|
);
|
2022-02-01 16:30:15 +01:00
|
|
|
};
|
|
|
|
DefaultStory.storyName = 'Default';
|
|
|
|
DefaultStory.args = {
|
|
|
|
suggestedAssets: [...mockSuggestedAssets],
|
|
|
|
tokens: [],
|
|
|
|
};
|
2021-09-08 01:51:41 +02:00
|
|
|
|
2022-02-01 16:30:15 +01:00
|
|
|
export const WithDuplicateAddress = ({ suggestedAssets, tokens }) => {
|
2021-08-17 07:33:46 +02:00
|
|
|
return (
|
2022-02-01 16:30:15 +01:00
|
|
|
<PageSet suggestedAssets={suggestedAssets} tokens={tokens}>
|
2021-08-17 07:33:46 +02:00
|
|
|
<ConfirmAddSuggestedToken />
|
|
|
|
</PageSet>
|
|
|
|
);
|
|
|
|
};
|
2022-02-01 16:30:15 +01:00
|
|
|
WithDuplicateAddress.args = {
|
|
|
|
suggestedAssets: [...mockSuggestedAssets],
|
|
|
|
tokens: [
|
|
|
|
{
|
|
|
|
...mockSuggestedAssets[0].asset,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2021-12-01 20:27:57 +01:00
|
|
|
|
2022-02-01 16:30:15 +01:00
|
|
|
export const WithDuplicateSymbolAndDifferentAddress = ({
|
|
|
|
suggestedAssets,
|
|
|
|
tokens,
|
|
|
|
}) => {
|
|
|
|
return (
|
|
|
|
<PageSet suggestedAssets={suggestedAssets} tokens={tokens}>
|
|
|
|
<ConfirmAddSuggestedToken />
|
|
|
|
</PageSet>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
WithDuplicateSymbolAndDifferentAddress.args = {
|
|
|
|
suggestedAssets: [...mockSuggestedAssets],
|
|
|
|
tokens: [
|
|
|
|
{
|
|
|
|
...mockSuggestedAssets[0].asset,
|
|
|
|
address: '0xNonSuggestedAddress',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|