2021-05-25 02:20:09 +02:00
|
|
|
/* eslint-disable react/prop-types */
|
|
|
|
import React, { useEffect } from 'react';
|
|
|
|
import { text } from '@storybook/addon-knobs';
|
|
|
|
import { useParams } from 'react-router-dom';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { updateMetamaskState } from '../../store/actions';
|
|
|
|
import { currentNetworkTxListSelector } from '../../selectors/transactions';
|
2021-09-08 01:51:41 +02:00
|
|
|
import { store, getNewState } from '../../../.storybook/preview';
|
2021-05-25 02:20:09 +02:00
|
|
|
|
2021-09-08 01:51:41 +02:00
|
|
|
import { domainMetadata } from '../../../.storybook/initial-states/approval-screens/token-approval';
|
2021-05-25 02:20:09 +02:00
|
|
|
import ConfirmApprove from '.';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Confirmation Screens',
|
2021-09-15 20:55:48 +02:00
|
|
|
id: __filename,
|
2021-05-25 02:20:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// transaction ID, maps to entry in state.metamask.currentNetworkTxList
|
|
|
|
const txId = 7900715443136469;
|
|
|
|
|
|
|
|
const PageSet = ({ children }) => {
|
|
|
|
const origin = text('Origin', 'https://metamask.github.io');
|
|
|
|
const domainIconUrl = text(
|
|
|
|
'Icon URL',
|
|
|
|
'https://metamask.github.io/test-dapp/metamask-fox.svg',
|
|
|
|
);
|
2021-09-08 01:51:41 +02:00
|
|
|
const state = store.getState();
|
2021-05-25 02:20:09 +02:00
|
|
|
const currentNetworkTxList = useSelector(currentNetworkTxListSelector);
|
|
|
|
const transaction = currentNetworkTxList.find(({ id }) => id === txId);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
transaction.origin = origin;
|
|
|
|
store.dispatch(
|
2021-09-08 01:51:41 +02:00
|
|
|
updateMetamaskState(
|
|
|
|
getNewState(state.metamask, {
|
|
|
|
currentNetworkTxList: [transaction],
|
|
|
|
}),
|
|
|
|
),
|
2021-05-25 02:20:09 +02:00
|
|
|
);
|
2021-09-08 01:51:41 +02:00
|
|
|
}, [origin, transaction, state.metamask]);
|
2021-05-25 02:20:09 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
store.dispatch(
|
2021-09-08 01:51:41 +02:00
|
|
|
updateMetamaskState(
|
|
|
|
getNewState(state.metamask, {
|
|
|
|
domainMetadata: {
|
|
|
|
[origin]: {
|
|
|
|
icon: domainIconUrl,
|
|
|
|
},
|
2021-05-25 02:20:09 +02:00
|
|
|
},
|
2021-09-08 01:51:41 +02:00
|
|
|
}),
|
|
|
|
),
|
2021-05-25 02:20:09 +02:00
|
|
|
);
|
2021-09-08 01:51:41 +02:00
|
|
|
}, [domainIconUrl, origin, state.metamask]);
|
2021-05-25 02:20:09 +02:00
|
|
|
|
|
|
|
const params = useParams();
|
|
|
|
params.id = txId;
|
|
|
|
return children;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ApproveTokens = () => {
|
2021-09-08 01:51:41 +02:00
|
|
|
const state = store.getState();
|
2021-05-25 02:20:09 +02:00
|
|
|
store.dispatch(
|
2021-09-08 01:51:41 +02:00
|
|
|
updateMetamaskState(
|
|
|
|
getNewState(state.metamask, {
|
|
|
|
domainMetadata,
|
|
|
|
}),
|
|
|
|
),
|
2021-05-25 02:20:09 +02:00
|
|
|
);
|
|
|
|
return (
|
|
|
|
<PageSet>
|
|
|
|
<ConfirmApprove />
|
|
|
|
</PageSet>
|
|
|
|
);
|
|
|
|
};
|