From bc6bf1bb62a4e1cdd7d4de024cec42e48455febd Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Tue, 30 Nov 2021 15:11:07 +0100 Subject: [PATCH 01/12] Move files around --- src/components/index.ts | 1 - .../RepTokenMigration/RepTokenMigration.tsx | 0 .../RepTokenMigration/config.ts | 0 .../RepTokenMigration/helpers.spec.ts | 0 .../RepTokenMigration/helpers.ts | 0 .../RepTokenMigration/index.ts | 0 .../TokenMigrationStepper.reducer.tsx | 4 ++++ .../TokenMigration/TokenMigrationStepper.tsx | 16 +++++++++------- .../__tests__/TokenMigrationConfirm.test.tsx | 4 ++-- .../__tests__/TokenMigrationForm.test.tsx | 0 .../__tests__/TokenMigrationMultiTx.test.tsx | 0 .../__tests__/TokenMigrationReceipt.test.tsx | 0 .../__tests__/TokenMigrationStepper.test.tsx | 0 .../components/TokenMigrationConfirm.tsx | 0 .../components/TokenMigrationForm.tsx | 0 .../components/TokenMigrationMultiTx.tsx | 0 .../components/TokenMigrationReceipt.tsx | 0 .../TokenMigration/components/index.ts | 0 src/features/TokenMigration/config.ts | 9 +++++++++ .../TokenMigration/helpers.spec.ts | 0 .../TokenMigration/helpers.ts | 0 .../TokenMigration/index.ts | 4 ++++ src/features/index.ts | 1 - src/routing/routes.tsx | 12 ++++++------ src/types/index.ts | 7 +------ src/types/tokenMigration.ts | 7 +++++++ 26 files changed, 42 insertions(+), 23 deletions(-) rename src/features/{ => TokenMigration}/RepTokenMigration/RepTokenMigration.tsx (100%) rename src/features/{ => TokenMigration}/RepTokenMigration/config.ts (100%) rename src/features/{ => TokenMigration}/RepTokenMigration/helpers.spec.ts (100%) rename src/features/{ => TokenMigration}/RepTokenMigration/helpers.ts (100%) rename src/features/{ => TokenMigration}/RepTokenMigration/index.ts (100%) rename src/{components => features}/TokenMigration/TokenMigrationStepper.reducer.tsx (79%) rename src/{components => features}/TokenMigration/TokenMigrationStepper.tsx (91%) rename src/{components => features}/TokenMigration/__tests__/TokenMigrationConfirm.test.tsx (90%) rename src/{components => features}/TokenMigration/__tests__/TokenMigrationForm.test.tsx (100%) rename src/{components => features}/TokenMigration/__tests__/TokenMigrationMultiTx.test.tsx (100%) rename src/{components => features}/TokenMigration/__tests__/TokenMigrationReceipt.test.tsx (100%) rename src/{components => features}/TokenMigration/__tests__/TokenMigrationStepper.test.tsx (100%) rename src/{components => features}/TokenMigration/components/TokenMigrationConfirm.tsx (100%) rename src/{components => features}/TokenMigration/components/TokenMigrationForm.tsx (100%) rename src/{components => features}/TokenMigration/components/TokenMigrationMultiTx.tsx (100%) rename src/{components => features}/TokenMigration/components/TokenMigrationReceipt.tsx (100%) rename src/{components => features}/TokenMigration/components/index.ts (100%) create mode 100644 src/features/TokenMigration/config.ts rename src/{components => features}/TokenMigration/helpers.spec.ts (100%) rename src/{components => features}/TokenMigration/helpers.ts (100%) rename src/{components => features}/TokenMigration/index.ts (56%) diff --git a/src/components/index.ts b/src/components/index.ts index 9961e3cfc48..a2c78d7a64b 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -69,7 +69,6 @@ export { default as TimeElapsed } from './TimeElapsed'; export { default as Icon, TIcon, getSVGIcon } from './Icon'; export { default as IFrame } from './IFrame'; export { Downloader } from './Downloader'; -export { TokenMigrationStepper } from './TokenMigration'; export { Heading, SubHeading, Body, Label, Text, TextProps } from './NewTypography'; export { ActionPanel, ActionButtonProps, ActionButton } from './ActionsPanel'; export { default as AppLoading } from './AppLoading'; diff --git a/src/features/RepTokenMigration/RepTokenMigration.tsx b/src/features/TokenMigration/RepTokenMigration/RepTokenMigration.tsx similarity index 100% rename from src/features/RepTokenMigration/RepTokenMigration.tsx rename to src/features/TokenMigration/RepTokenMigration/RepTokenMigration.tsx diff --git a/src/features/RepTokenMigration/config.ts b/src/features/TokenMigration/RepTokenMigration/config.ts similarity index 100% rename from src/features/RepTokenMigration/config.ts rename to src/features/TokenMigration/RepTokenMigration/config.ts diff --git a/src/features/RepTokenMigration/helpers.spec.ts b/src/features/TokenMigration/RepTokenMigration/helpers.spec.ts similarity index 100% rename from src/features/RepTokenMigration/helpers.spec.ts rename to src/features/TokenMigration/RepTokenMigration/helpers.spec.ts diff --git a/src/features/RepTokenMigration/helpers.ts b/src/features/TokenMigration/RepTokenMigration/helpers.ts similarity index 100% rename from src/features/RepTokenMigration/helpers.ts rename to src/features/TokenMigration/RepTokenMigration/helpers.ts diff --git a/src/features/RepTokenMigration/index.ts b/src/features/TokenMigration/RepTokenMigration/index.ts similarity index 100% rename from src/features/RepTokenMigration/index.ts rename to src/features/TokenMigration/RepTokenMigration/index.ts diff --git a/src/components/TokenMigration/TokenMigrationStepper.reducer.tsx b/src/features/TokenMigration/TokenMigrationStepper.reducer.tsx similarity index 79% rename from src/components/TokenMigration/TokenMigrationStepper.reducer.tsx rename to src/features/TokenMigration/TokenMigrationStepper.reducer.tsx index 5b25c4bf9e4..f30f9f94868 100644 --- a/src/components/TokenMigration/TokenMigrationStepper.reducer.tsx +++ b/src/features/TokenMigration/TokenMigrationStepper.reducer.tsx @@ -9,6 +9,9 @@ export const tokenMigrationReducer = ( action: ReducerAction ): TokenMigrationState => { switch (action.type) { + case tokenMigrationReducer.actionTypes.SELECT_MIGRATION: { + return { ...state, migration: action.payload }; + } case tokenMigrationReducer.actionTypes.FORM_SUBMIT: { const { account, amount } = action.payload; return { ...state, account, amount }; @@ -20,5 +23,6 @@ export const tokenMigrationReducer = ( }; tokenMigrationReducer.actionTypes = { + SELECT_MIGRATION: 'SELECT_MIGRATION', FORM_SUBMIT: 'FORM_SUBMIT' }; diff --git a/src/components/TokenMigration/TokenMigrationStepper.tsx b/src/features/TokenMigration/TokenMigrationStepper.tsx similarity index 91% rename from src/components/TokenMigration/TokenMigrationStepper.tsx rename to src/features/TokenMigration/TokenMigrationStepper.tsx index 74dcaa58c07..01d73d14415 100644 --- a/src/components/TokenMigration/TokenMigrationStepper.tsx +++ b/src/features/TokenMigration/TokenMigrationStepper.tsx @@ -9,6 +9,7 @@ import { ITokenMigrationConfig, ITokenMigrationFormFull, ITxStatus, + MigrationType, TokenMigrationState } from '@types'; @@ -16,18 +17,19 @@ import ConfirmTokenMigration from './components/TokenMigrationConfirm'; import TokenMigrationForm from './components/TokenMigrationForm'; import ConfirmTokenMigrationMultiTx from './components/TokenMigrationMultiTx'; import TokenMigrationReceipt from './components/TokenMigrationReceipt'; +import { MIGRATION_CONFIGS } from './config'; import { tokenMigrationReducer } from './TokenMigrationStepper.reducer'; -interface Props { - tokenMigrationConfig: ITokenMigrationConfig; -} - -const TokenMigrationStepper = ({ tokenMigrationConfig }: Props) => { - const [reducerState, dispatch] = useReducer(tokenMigrationReducer, {}); +const TokenMigrationStepper = () => { + const [reducerState, dispatch] = useReducer(tokenMigrationReducer, { + migration: MigrationType.REP + }); const { state, prepareTx, sendTx, stopYield, initWith } = useTxMulti(); const { canYield, isSubmitting, transactions, error } = state; - const { account, amount }: TokenMigrationState = reducerState; + const { account, amount, migration }: TokenMigrationState = reducerState; + + const tokenMigrationConfig = MIGRATION_CONFIGS[migration]; const steps: IStepperPath[] = [ { diff --git a/src/components/TokenMigration/__tests__/TokenMigrationConfirm.test.tsx b/src/features/TokenMigration/__tests__/TokenMigrationConfirm.test.tsx similarity index 90% rename from src/components/TokenMigration/__tests__/TokenMigrationConfirm.test.tsx rename to src/features/TokenMigration/__tests__/TokenMigrationConfirm.test.tsx index 3f74a41308a..5993dc93469 100644 --- a/src/components/TokenMigration/__tests__/TokenMigrationConfirm.test.tsx +++ b/src/features/TokenMigration/__tests__/TokenMigrationConfirm.test.tsx @@ -3,17 +3,17 @@ import { ComponentProps } from 'react'; import { mockAppState, simpleRender } from 'test-utils'; import { REPV1UUID } from '@config'; -import { repTokenMigrationConfig } from '@features/RepTokenMigration/config'; import { fAccounts, fAssets, fNetworks, fSettings, fTokenMigrationTxs } from '@fixtures'; import { ITxMultiConfirmProps, StoreAccount } from '@types'; import ConfirmTokenMigration from '../components/TokenMigrationConfirm'; +import { MIGRATION_CONFIGS } from '../config'; const defaultProps: ITxMultiConfirmProps & { amount: string; account: StoreAccount; } = { - flowConfig: repTokenMigrationConfig, + flowConfig: MIGRATION_CONFIGS.REP, currentTxIdx: 0, amount: '1', account: fAccounts[0], diff --git a/src/components/TokenMigration/__tests__/TokenMigrationForm.test.tsx b/src/features/TokenMigration/__tests__/TokenMigrationForm.test.tsx similarity index 100% rename from src/components/TokenMigration/__tests__/TokenMigrationForm.test.tsx rename to src/features/TokenMigration/__tests__/TokenMigrationForm.test.tsx diff --git a/src/components/TokenMigration/__tests__/TokenMigrationMultiTx.test.tsx b/src/features/TokenMigration/__tests__/TokenMigrationMultiTx.test.tsx similarity index 100% rename from src/components/TokenMigration/__tests__/TokenMigrationMultiTx.test.tsx rename to src/features/TokenMigration/__tests__/TokenMigrationMultiTx.test.tsx diff --git a/src/components/TokenMigration/__tests__/TokenMigrationReceipt.test.tsx b/src/features/TokenMigration/__tests__/TokenMigrationReceipt.test.tsx similarity index 100% rename from src/components/TokenMigration/__tests__/TokenMigrationReceipt.test.tsx rename to src/features/TokenMigration/__tests__/TokenMigrationReceipt.test.tsx diff --git a/src/components/TokenMigration/__tests__/TokenMigrationStepper.test.tsx b/src/features/TokenMigration/__tests__/TokenMigrationStepper.test.tsx similarity index 100% rename from src/components/TokenMigration/__tests__/TokenMigrationStepper.test.tsx rename to src/features/TokenMigration/__tests__/TokenMigrationStepper.test.tsx diff --git a/src/components/TokenMigration/components/TokenMigrationConfirm.tsx b/src/features/TokenMigration/components/TokenMigrationConfirm.tsx similarity index 100% rename from src/components/TokenMigration/components/TokenMigrationConfirm.tsx rename to src/features/TokenMigration/components/TokenMigrationConfirm.tsx diff --git a/src/components/TokenMigration/components/TokenMigrationForm.tsx b/src/features/TokenMigration/components/TokenMigrationForm.tsx similarity index 100% rename from src/components/TokenMigration/components/TokenMigrationForm.tsx rename to src/features/TokenMigration/components/TokenMigrationForm.tsx diff --git a/src/components/TokenMigration/components/TokenMigrationMultiTx.tsx b/src/features/TokenMigration/components/TokenMigrationMultiTx.tsx similarity index 100% rename from src/components/TokenMigration/components/TokenMigrationMultiTx.tsx rename to src/features/TokenMigration/components/TokenMigrationMultiTx.tsx diff --git a/src/components/TokenMigration/components/TokenMigrationReceipt.tsx b/src/features/TokenMigration/components/TokenMigrationReceipt.tsx similarity index 100% rename from src/components/TokenMigration/components/TokenMigrationReceipt.tsx rename to src/features/TokenMigration/components/TokenMigrationReceipt.tsx diff --git a/src/components/TokenMigration/components/index.ts b/src/features/TokenMigration/components/index.ts similarity index 100% rename from src/components/TokenMigration/components/index.ts rename to src/features/TokenMigration/components/index.ts diff --git a/src/features/TokenMigration/config.ts b/src/features/TokenMigration/config.ts new file mode 100644 index 00000000000..109ca7944f5 --- /dev/null +++ b/src/features/TokenMigration/config.ts @@ -0,0 +1,9 @@ +import { MigrationType } from '@types'; + +import { repTokenMigrationConfig } from './RepTokenMigration/config'; + +export const MIGRATION_CONFIGS = { + [MigrationType.REP]: repTokenMigrationConfig, + [MigrationType.ANT]: null, + [MigrationType.GOLEM]: null +}; diff --git a/src/components/TokenMigration/helpers.spec.ts b/src/features/TokenMigration/helpers.spec.ts similarity index 100% rename from src/components/TokenMigration/helpers.spec.ts rename to src/features/TokenMigration/helpers.spec.ts diff --git a/src/components/TokenMigration/helpers.ts b/src/features/TokenMigration/helpers.ts similarity index 100% rename from src/components/TokenMigration/helpers.ts rename to src/features/TokenMigration/helpers.ts diff --git a/src/components/TokenMigration/index.ts b/src/features/TokenMigration/index.ts similarity index 56% rename from src/components/TokenMigration/index.ts rename to src/features/TokenMigration/index.ts index 980a8d605a9..2907807fffc 100644 --- a/src/components/TokenMigration/index.ts +++ b/src/features/TokenMigration/index.ts @@ -1,2 +1,6 @@ +import TokenMigrationStepper from './TokenMigrationStepper'; + export { default as TokenMigrationStepper } from './TokenMigrationStepper'; export { makeTokenMigrationTxConfig } from './helpers'; + +export default TokenMigrationStepper; diff --git a/src/features/index.ts b/src/features/index.ts index 63b3cf93e3d..5dd0dc19043 100644 --- a/src/features/index.ts +++ b/src/features/index.ts @@ -3,6 +3,5 @@ export { default as PageNotFound } from './PageNotFound'; export { useNotifications } from './NotificationsPanel'; export { useToasts } from './Toasts'; export { ErrorProvider, ErrorContext } from './ErrorHandling'; -export { default as RepTokenMigration } from './RepTokenMigration'; export { Dashboard } from './Dashboard'; export { default as GolemTokenMigration } from './GolemTokenMigration'; diff --git a/src/routing/routes.tsx b/src/routing/routes.tsx index 870d5f93346..847ae2df4d1 100644 --- a/src/routing/routes.tsx +++ b/src/routing/routes.tsx @@ -78,10 +78,6 @@ const TxStatus = lazy(() => import(/* webpackChunkName: "TxStatus" */ '@features/TxStatus/TxStatus') ); -const RepTokenMigration = lazy(() => - import(/* webpackChunkName: "TokenMigration" */ '@features/RepTokenMigration') -); - const AaveTokenMigration = lazy(() => import(/* webpackChunkName: "TokenMigration" */ '@features/AaveTokenMigration') ); @@ -95,6 +91,10 @@ const GolemTokenMigration = lazy(() => import(/* webpackChunkName: "TokenMigration" */ '@features/GolemTokenMigration') ); +const Migrations = lazy(() => + import(/* webpackChunkName: "TokenMigration" */ '@features/TokenMigration') +); + export interface IAppRoutes { [K: string]: IAppRoute; } @@ -282,8 +282,8 @@ export const getStaticAppRoutes = (featureFlags: FeatureFlags): IAppRoute[] => [ path: ROUTE_PATHS.REP_TOKEN_MIGRATION.path, exact: true, requireAccounts: true, - enabled: isTruthy(featureFlags.REP_TOKEN_MIGRATION), - component: RepTokenMigration + enabled: true, + component: Migrations }, { name: ROUTE_PATHS.AAVE_TOKEN_MIGRATION.name, diff --git a/src/types/index.ts b/src/types/index.ts index 1ce8392bcfb..8b7c10d47f5 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -75,12 +75,7 @@ export { IPrimaryAccountPermission, IExposedAccountsPermission } from './web3Permissions'; -export { - ITokenMigrationConfig, - ITokenMigrationTxConfig, - ITokenMigrationFormFull, - TokenMigrationState -} from './tokenMigration'; +export * from './tokenMigration'; export { IUniDistributor } from './uniDistributor'; export { UserAction, diff --git a/src/types/tokenMigration.ts b/src/types/tokenMigration.ts index 14849f3a3ac..6bd0a9af442 100644 --- a/src/types/tokenMigration.ts +++ b/src/types/tokenMigration.ts @@ -1,6 +1,13 @@ import { ISimpleTxFormFull, ITxObject, ITxType, StoreAccount, TAddress, TUuid } from '@types'; +export enum MigrationType { + REP = 'REP', + GOLEM = 'GOLEM', + ANT = 'ANT' +} + export interface TokenMigrationState { + migration: MigrationType; account?: StoreAccount; amount?: string; } From d3a7dd3982b342ce4cc5b1f2e92575601e9fdbf2 Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Tue, 30 Nov 2021 15:22:13 +0100 Subject: [PATCH 02/12] Move more files --- .../__fixtures__/tokenMigrationMultiTx.ts | 9 +++-- .../TransactionFlow/helpers.spec.ts | 9 ++--- src/components/TransactionFlow/helpers.ts | 2 +- .../AaveTokenMigration/AaveTokenMigration.tsx | 7 ---- src/features/AaveTokenMigration/index.ts | 3 -- .../AntTokenMigration/AntTokenMigration.tsx | 9 ----- src/features/AntTokenMigration/index.ts | 3 -- .../GolemTokenMigration.tsx | 9 ----- src/features/GolemTokenMigration/index.ts | 3 -- src/features/Layout/Navigation/constants.ts | 21 ---------- .../AaveTokenMigration/config.ts | 0 .../AaveTokenMigration/helpers.spec.ts | 0 .../AaveTokenMigration/helpers.ts | 0 .../AaveTokenMigration/index.ts | 1 + .../AntTokenMigration/config.ts | 0 .../AntTokenMigration/helpers.spec.ts | 0 .../AntTokenMigration/helpers.ts | 0 .../TokenMigration/AntTokenMigration/index.ts | 1 + .../GolemTokenMigration/config.ts | 0 .../GolemTokenMigration/helpers.spec.ts | 0 .../GolemTokenMigration/helpers.ts | 0 .../GolemTokenMigration/index.ts | 1 + .../RepTokenMigration/RepTokenMigration.tsx | 9 ----- .../TokenMigration/RepTokenMigration/index.ts | 4 +- .../TokenMigration/TokenMigrationStepper.tsx | 8 +--- .../__tests__/TokenMigrationForm.test.tsx | 4 +- .../__tests__/TokenMigrationMultiTx.test.tsx | 4 +- .../__tests__/TokenMigrationReceipt.test.tsx | 4 +- .../__tests__/TokenMigrationStepper.test.tsx | 3 +- src/features/TokenMigration/config.ts | 10 +++-- src/features/TokenMigration/helpers.spec.ts | 6 +-- src/features/index.ts | 1 - src/helpers/erc20.spec.ts | 6 +-- src/routing/routes.tsx | 38 ------------------- src/types/tokenMigration.ts | 3 +- 35 files changed, 37 insertions(+), 141 deletions(-) delete mode 100644 src/features/AaveTokenMigration/AaveTokenMigration.tsx delete mode 100644 src/features/AaveTokenMigration/index.ts delete mode 100644 src/features/AntTokenMigration/AntTokenMigration.tsx delete mode 100644 src/features/AntTokenMigration/index.ts delete mode 100644 src/features/GolemTokenMigration/GolemTokenMigration.tsx delete mode 100644 src/features/GolemTokenMigration/index.ts rename src/features/{ => TokenMigration}/AaveTokenMigration/config.ts (100%) rename src/features/{ => TokenMigration}/AaveTokenMigration/helpers.spec.ts (100%) rename src/features/{ => TokenMigration}/AaveTokenMigration/helpers.ts (100%) create mode 100644 src/features/TokenMigration/AaveTokenMigration/index.ts rename src/features/{ => TokenMigration}/AntTokenMigration/config.ts (100%) rename src/features/{ => TokenMigration}/AntTokenMigration/helpers.spec.ts (100%) rename src/features/{ => TokenMigration}/AntTokenMigration/helpers.ts (100%) create mode 100644 src/features/TokenMigration/AntTokenMigration/index.ts rename src/features/{ => TokenMigration}/GolemTokenMigration/config.ts (100%) rename src/features/{ => TokenMigration}/GolemTokenMigration/helpers.spec.ts (100%) rename src/features/{ => TokenMigration}/GolemTokenMigration/helpers.ts (100%) create mode 100644 src/features/TokenMigration/GolemTokenMigration/index.ts delete mode 100644 src/features/TokenMigration/RepTokenMigration/RepTokenMigration.tsx diff --git a/jest_config/__fixtures__/tokenMigrationMultiTx.ts b/jest_config/__fixtures__/tokenMigrationMultiTx.ts index c17b37b6a6e..95ea88aefc2 100644 --- a/jest_config/__fixtures__/tokenMigrationMultiTx.ts +++ b/jest_config/__fixtures__/tokenMigrationMultiTx.ts @@ -1,6 +1,9 @@ import { REPV1UUID } from '@config'; -import { repTokenMigrationConfig } from '@features/RepTokenMigration/config'; -import { createApproveTx, createRepMigrationTx } from '@features/RepTokenMigration/helpers'; +import { MIGRATION_CONFIGS } from '@features/TokenMigration/config'; +import { + createApproveTx, + createRepMigrationTx +} from '@features/TokenMigration/RepTokenMigration/helpers'; import { fApproveERC20TxResponse, fREPTokenMigrationTxResponse } from '@fixtures'; import { ITokenMigrationFormFull, ITxStatus, ITxType, TxParcel } from '@types'; import { generateUUID, inputGasLimitToHex, inputNonceToHex } from '@utils'; @@ -11,7 +14,7 @@ import { fNetwork } from './network'; export const fTokenMigrationTxs = (): TxParcel[] => { const tokenMigrationPayload: ITokenMigrationFormFull = { - tokenConfig: repTokenMigrationConfig, + tokenConfig: MIGRATION_CONFIGS.REP, asset: fAssets.find(({ uuid }) => uuid === REPV1UUID)!, network: fNetwork, address: fAccount.address, diff --git a/src/components/TransactionFlow/helpers.spec.ts b/src/components/TransactionFlow/helpers.spec.ts index 1cc61584d2e..182ef1c2ff7 100644 --- a/src/components/TransactionFlow/helpers.spec.ts +++ b/src/components/TransactionFlow/helpers.spec.ts @@ -1,8 +1,5 @@ -import { - TokenMigrationMultiTx, - TokenMigrationReceipt -} from '@components/TokenMigration/components'; -import { repTokenMigrationConfig } from '@features/RepTokenMigration/config'; +import { TokenMigrationMultiTx, TokenMigrationReceipt } from '@features/TokenMigration/components'; +import { MIGRATION_CONFIGS } from '@features/TokenMigration/config'; import { fAccounts, fDerivedApprovalTx, @@ -104,7 +101,7 @@ describe('createSignConfirmAndReceiptSteps', () => { amount: '5', backStepTitle: translateRaw('REP_TOKEN_MIGRATION'), account: fAccounts[0], - flowConfig: repTokenMigrationConfig, + flowConfig: MIGRATION_CONFIGS.REP, receiptTitle: translateRaw('REP_TOKEN_MIGRATION_RECEIPT'), isSubmitting: false, multiTxTitle: translateRaw('CONFIRM_TRANSACTION'), diff --git a/src/components/TransactionFlow/helpers.ts b/src/components/TransactionFlow/helpers.ts index 37ae6e59dab..5bdb83fe094 100644 --- a/src/components/TransactionFlow/helpers.ts +++ b/src/components/TransactionFlow/helpers.ts @@ -5,9 +5,9 @@ import pick from 'ramda/src/pick'; import { Brand, ValuesType } from 'utility-types'; import { WALLET_STEPS } from '@components'; -import { TokenMigrationReceiptProps } from '@components/TokenMigration/components/TokenMigrationReceipt'; import { CONTRACT_INTERACTION_TYPES } from '@config'; import { IMembershipPurchaseReceiptProps } from '@features/PurchaseMembership/components/MembershipPurchaseReceipt'; +import { TokenMigrationReceiptProps } from '@features/TokenMigration/components/TokenMigrationReceipt'; import { fetchUniversalGasPriceEstimate } from '@services/ApiService/Gas'; import { getAccountBalance, getStoreAccount } from '@services/Store'; import { diff --git a/src/features/AaveTokenMigration/AaveTokenMigration.tsx b/src/features/AaveTokenMigration/AaveTokenMigration.tsx deleted file mode 100644 index 7afa1934ec5..00000000000 --- a/src/features/AaveTokenMigration/AaveTokenMigration.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import { TokenMigrationStepper } from '@components'; - -import { migrationConfig } from './config'; - -export const AaveTokenMigration = () => { - return ; -}; diff --git a/src/features/AaveTokenMigration/index.ts b/src/features/AaveTokenMigration/index.ts deleted file mode 100644 index 7f8d390e1c5..00000000000 --- a/src/features/AaveTokenMigration/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { AaveTokenMigration } from './AaveTokenMigration'; - -export default AaveTokenMigration; diff --git a/src/features/AntTokenMigration/AntTokenMigration.tsx b/src/features/AntTokenMigration/AntTokenMigration.tsx deleted file mode 100644 index 60566b77238..00000000000 --- a/src/features/AntTokenMigration/AntTokenMigration.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { TokenMigrationStepper } from '@components'; - -import { tokenMigrationConfig } from './config'; - -const AntTokenMigration = () => { - return ; -}; - -export default AntTokenMigration; diff --git a/src/features/AntTokenMigration/index.ts b/src/features/AntTokenMigration/index.ts deleted file mode 100644 index 7de60c2d9f8..00000000000 --- a/src/features/AntTokenMigration/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import AntTokenMigration from './AntTokenMigration'; - -export default AntTokenMigration; diff --git a/src/features/GolemTokenMigration/GolemTokenMigration.tsx b/src/features/GolemTokenMigration/GolemTokenMigration.tsx deleted file mode 100644 index 3378d2d3651..00000000000 --- a/src/features/GolemTokenMigration/GolemTokenMigration.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { TokenMigrationStepper } from '@components'; - -import { golemTokenMigrationConfig } from './config'; - -const GolemTokenMigration = () => { - return ; -}; - -export default GolemTokenMigration; diff --git a/src/features/GolemTokenMigration/index.ts b/src/features/GolemTokenMigration/index.ts deleted file mode 100644 index 5ebf02a2634..00000000000 --- a/src/features/GolemTokenMigration/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import GolemTokenMigration from './GolemTokenMigration'; - -export default GolemTokenMigration; diff --git a/src/features/Layout/Navigation/constants.ts b/src/features/Layout/Navigation/constants.ts index ac35487ebca..ef6550881a6 100644 --- a/src/features/Layout/Navigation/constants.ts +++ b/src/features/Layout/Navigation/constants.ts @@ -100,27 +100,6 @@ export const toolsTray = (APP_ROUTES: IAppRoutes) => { title: translateRaw('NAVIGATION_MIGRATE_REP'), icon: 'nav-migrate-rep' }, - { - type: 'internal', - to: APP_ROUTES.GOLEM_TOKEN_MIGRATION.path, - enabled: APP_ROUTES.GOLEM_TOKEN_MIGRATION.enabled, - title: translateRaw('NAVIGATION_MIGRATE_GNT'), - icon: 'nav-migrate-gnt' - }, - { - type: 'internal', - to: APP_ROUTES.ANT_TOKEN_MIGRATION.path, - enabled: APP_ROUTES.ANT_TOKEN_MIGRATION.enabled, - title: translateRaw('NAVIGATION_MIGRATE_ANT'), - icon: 'nav-migrate-ant' - }, - { - type: 'internal', - to: APP_ROUTES.AAVE_TOKEN_MIGRATION.path, - enabled: APP_ROUTES.AAVE_TOKEN_MIGRATION.enabled, - title: translateRaw('NAVIGATION_MIGRATE_LEND'), - icon: 'nav-migrate-lend' - }, { type: 'internal', to: APP_ROUTES.FAUCET.path, diff --git a/src/features/AaveTokenMigration/config.ts b/src/features/TokenMigration/AaveTokenMigration/config.ts similarity index 100% rename from src/features/AaveTokenMigration/config.ts rename to src/features/TokenMigration/AaveTokenMigration/config.ts diff --git a/src/features/AaveTokenMigration/helpers.spec.ts b/src/features/TokenMigration/AaveTokenMigration/helpers.spec.ts similarity index 100% rename from src/features/AaveTokenMigration/helpers.spec.ts rename to src/features/TokenMigration/AaveTokenMigration/helpers.spec.ts diff --git a/src/features/AaveTokenMigration/helpers.ts b/src/features/TokenMigration/AaveTokenMigration/helpers.ts similarity index 100% rename from src/features/AaveTokenMigration/helpers.ts rename to src/features/TokenMigration/AaveTokenMigration/helpers.ts diff --git a/src/features/TokenMigration/AaveTokenMigration/index.ts b/src/features/TokenMigration/AaveTokenMigration/index.ts new file mode 100644 index 00000000000..f03c2281a91 --- /dev/null +++ b/src/features/TokenMigration/AaveTokenMigration/index.ts @@ -0,0 +1 @@ +export * from './config'; diff --git a/src/features/AntTokenMigration/config.ts b/src/features/TokenMigration/AntTokenMigration/config.ts similarity index 100% rename from src/features/AntTokenMigration/config.ts rename to src/features/TokenMigration/AntTokenMigration/config.ts diff --git a/src/features/AntTokenMigration/helpers.spec.ts b/src/features/TokenMigration/AntTokenMigration/helpers.spec.ts similarity index 100% rename from src/features/AntTokenMigration/helpers.spec.ts rename to src/features/TokenMigration/AntTokenMigration/helpers.spec.ts diff --git a/src/features/AntTokenMigration/helpers.ts b/src/features/TokenMigration/AntTokenMigration/helpers.ts similarity index 100% rename from src/features/AntTokenMigration/helpers.ts rename to src/features/TokenMigration/AntTokenMigration/helpers.ts diff --git a/src/features/TokenMigration/AntTokenMigration/index.ts b/src/features/TokenMigration/AntTokenMigration/index.ts new file mode 100644 index 00000000000..f03c2281a91 --- /dev/null +++ b/src/features/TokenMigration/AntTokenMigration/index.ts @@ -0,0 +1 @@ +export * from './config'; diff --git a/src/features/GolemTokenMigration/config.ts b/src/features/TokenMigration/GolemTokenMigration/config.ts similarity index 100% rename from src/features/GolemTokenMigration/config.ts rename to src/features/TokenMigration/GolemTokenMigration/config.ts diff --git a/src/features/GolemTokenMigration/helpers.spec.ts b/src/features/TokenMigration/GolemTokenMigration/helpers.spec.ts similarity index 100% rename from src/features/GolemTokenMigration/helpers.spec.ts rename to src/features/TokenMigration/GolemTokenMigration/helpers.spec.ts diff --git a/src/features/GolemTokenMigration/helpers.ts b/src/features/TokenMigration/GolemTokenMigration/helpers.ts similarity index 100% rename from src/features/GolemTokenMigration/helpers.ts rename to src/features/TokenMigration/GolemTokenMigration/helpers.ts diff --git a/src/features/TokenMigration/GolemTokenMigration/index.ts b/src/features/TokenMigration/GolemTokenMigration/index.ts new file mode 100644 index 00000000000..f03c2281a91 --- /dev/null +++ b/src/features/TokenMigration/GolemTokenMigration/index.ts @@ -0,0 +1 @@ +export * from './config'; diff --git a/src/features/TokenMigration/RepTokenMigration/RepTokenMigration.tsx b/src/features/TokenMigration/RepTokenMigration/RepTokenMigration.tsx deleted file mode 100644 index 28e20b0940c..00000000000 --- a/src/features/TokenMigration/RepTokenMigration/RepTokenMigration.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import { TokenMigrationStepper } from '@components'; - -import { repTokenMigrationConfig } from './config'; - -const RepTokenMigration = () => { - return ; -}; - -export default RepTokenMigration; diff --git a/src/features/TokenMigration/RepTokenMigration/index.ts b/src/features/TokenMigration/RepTokenMigration/index.ts index 27008db3d22..f03c2281a91 100644 --- a/src/features/TokenMigration/RepTokenMigration/index.ts +++ b/src/features/TokenMigration/RepTokenMigration/index.ts @@ -1,3 +1 @@ -import RepTokenMigration from './RepTokenMigration'; - -export default RepTokenMigration; +export * from './config'; diff --git a/src/features/TokenMigration/TokenMigrationStepper.tsx b/src/features/TokenMigration/TokenMigrationStepper.tsx index 01d73d14415..e716b95e740 100644 --- a/src/features/TokenMigration/TokenMigrationStepper.tsx +++ b/src/features/TokenMigration/TokenMigrationStepper.tsx @@ -5,13 +5,7 @@ import { default as GeneralStepper, IStepperPath } from '@components/GeneralStep import { ROUTE_PATHS } from '@config'; import { useTxMulti } from '@hooks'; import { translateRaw } from '@translations'; -import { - ITokenMigrationConfig, - ITokenMigrationFormFull, - ITxStatus, - MigrationType, - TokenMigrationState -} from '@types'; +import { ITokenMigrationFormFull, ITxStatus, MigrationType, TokenMigrationState } from '@types'; import ConfirmTokenMigration from './components/TokenMigrationConfirm'; import TokenMigrationForm from './components/TokenMigrationForm'; diff --git a/src/features/TokenMigration/__tests__/TokenMigrationForm.test.tsx b/src/features/TokenMigration/__tests__/TokenMigrationForm.test.tsx index 10280c1f164..fbadbe30da6 100644 --- a/src/features/TokenMigration/__tests__/TokenMigrationForm.test.tsx +++ b/src/features/TokenMigration/__tests__/TokenMigrationForm.test.tsx @@ -1,10 +1,10 @@ import { APP_STATE, mockAppState, simpleRender } from 'test-utils'; -import { repTokenMigrationConfig } from '@features/RepTokenMigration/config'; import { fAccount, fAccounts, fAssets, fNetwork } from '@fixtures'; import { translateRaw } from '@translations'; import TokenMigrationForm, { TokenMigrationProps } from '../components/TokenMigrationForm'; +import { MIGRATION_CONFIGS } from '../config'; jest.mock('@vendor', () => { return { @@ -17,7 +17,7 @@ jest.mock('@vendor', () => { const defaultProps: TokenMigrationProps = { isSubmitting: false, - tokenMigrationConfig: repTokenMigrationConfig, + tokenMigrationConfig: MIGRATION_CONFIGS.REP, asset: fAssets[0], network: fNetwork, address: '', diff --git a/src/features/TokenMigration/__tests__/TokenMigrationMultiTx.test.tsx b/src/features/TokenMigration/__tests__/TokenMigrationMultiTx.test.tsx index 1ca159a675f..93652b1a22c 100644 --- a/src/features/TokenMigration/__tests__/TokenMigrationMultiTx.test.tsx +++ b/src/features/TokenMigration/__tests__/TokenMigrationMultiTx.test.tsx @@ -1,13 +1,13 @@ import { simpleRender } from 'test-utils'; -import { repTokenMigrationConfig } from '@features/RepTokenMigration/config'; import { fAccount, fTokenMigrationTxs } from '@fixtures'; import { ITokenMigrationConfig, ITxMultiConfirmProps } from '@types'; import ConfirmTokenMigration from '../components/TokenMigrationMultiTx'; +import { MIGRATION_CONFIGS } from '../config'; const defaultProps: ITxMultiConfirmProps = { - flowConfig: repTokenMigrationConfig, + flowConfig: MIGRATION_CONFIGS.REP, currentTxIdx: 0, account: fAccount, transactions: fTokenMigrationTxs(), diff --git a/src/features/TokenMigration/__tests__/TokenMigrationReceipt.test.tsx b/src/features/TokenMigration/__tests__/TokenMigrationReceipt.test.tsx index 87917e73c06..6f9c168e2a1 100644 --- a/src/features/TokenMigration/__tests__/TokenMigrationReceipt.test.tsx +++ b/src/features/TokenMigration/__tests__/TokenMigrationReceipt.test.tsx @@ -1,15 +1,15 @@ import { mockAppState, simpleRender } from 'test-utils'; -import { repTokenMigrationConfig } from '@features/RepTokenMigration/config'; import { fAccounts, fTokenMigrationTxs } from '@fixtures'; import { translateRaw } from '@translations'; import TokenMigrationReceipt, { TokenMigrationReceiptProps } from '../components/TokenMigrationReceipt'; +import { MIGRATION_CONFIGS } from '../config'; const defaultProps: TokenMigrationReceiptProps = { - flowConfig: repTokenMigrationConfig, + flowConfig: MIGRATION_CONFIGS.REP, account: fAccounts[0], amount: '4', transactions: fTokenMigrationTxs(), diff --git a/src/features/TokenMigration/__tests__/TokenMigrationStepper.test.tsx b/src/features/TokenMigration/__tests__/TokenMigrationStepper.test.tsx index dcc4ea2fa39..c14f5d6f0ce 100644 --- a/src/features/TokenMigration/__tests__/TokenMigrationStepper.test.tsx +++ b/src/features/TokenMigration/__tests__/TokenMigrationStepper.test.tsx @@ -1,6 +1,5 @@ import { APP_STATE, fireEvent, mockAppState, simpleRender, waitFor } from 'test-utils'; -import { repTokenMigrationConfig } from '@features/RepTokenMigration/config'; import { fAccounts, fAssets, fSettings } from '@fixtures'; import { translateRaw } from '@translations'; import { truncate } from '@utils'; @@ -23,7 +22,7 @@ jest.mock('@vendor', () => { /* Test components */ describe('TokenMigrationStepper', () => { const renderComponent = () => - simpleRender(, { + simpleRender(, { initialState: mockAppState({ assets: fAssets, settings: fSettings, diff --git a/src/features/TokenMigration/config.ts b/src/features/TokenMigration/config.ts index 109ca7944f5..f106a00f2df 100644 --- a/src/features/TokenMigration/config.ts +++ b/src/features/TokenMigration/config.ts @@ -1,9 +1,13 @@ import { MigrationType } from '@types'; -import { repTokenMigrationConfig } from './RepTokenMigration/config'; +import { migrationConfig } from './AaveTokenMigration'; +import { tokenMigrationConfig } from './AntTokenMigration'; +import { golemTokenMigrationConfig } from './GolemTokenMigration'; +import { repTokenMigrationConfig } from './RepTokenMigration'; export const MIGRATION_CONFIGS = { [MigrationType.REP]: repTokenMigrationConfig, - [MigrationType.ANT]: null, - [MigrationType.GOLEM]: null + [MigrationType.ANT]: tokenMigrationConfig, + [MigrationType.GOLEM]: golemTokenMigrationConfig, + [MigrationType.AAVE]: migrationConfig }; diff --git a/src/features/TokenMigration/helpers.spec.ts b/src/features/TokenMigration/helpers.spec.ts index 0956bd03c44..b19901397da 100644 --- a/src/features/TokenMigration/helpers.spec.ts +++ b/src/features/TokenMigration/helpers.spec.ts @@ -1,4 +1,3 @@ -import { repTokenMigrationConfig } from '@features/RepTokenMigration/config'; import { fAccounts, fApproveErc20TxConfig, @@ -9,6 +8,7 @@ import { import { ITxNonce } from '@types'; import { inputGasLimitToHex } from '@utils'; +import { MIGRATION_CONFIGS } from './config'; import { makeTokenMigrationTxConfig } from './helpers'; describe('makeTokenMigrationTxConfig', () => { @@ -22,7 +22,7 @@ describe('makeTokenMigrationTxConfig', () => { approvalTx, fAccounts[0], '5' - )(repTokenMigrationConfig); + )(MIGRATION_CONFIGS.REP); expect(txConfig).toStrictEqual(fApproveErc20TxConfig); }); it('creates txConfig from rep token migration tx', () => { @@ -35,7 +35,7 @@ describe('makeTokenMigrationTxConfig', () => { repMigrationTx, fAccounts[0], '5' - )(repTokenMigrationConfig); + )(MIGRATION_CONFIGS.REP); expect(txConfig).toStrictEqual(fTokenMigrationTxConfig); }); }); diff --git a/src/features/index.ts b/src/features/index.ts index 5dd0dc19043..946077ee9b9 100644 --- a/src/features/index.ts +++ b/src/features/index.ts @@ -4,4 +4,3 @@ export { useNotifications } from './NotificationsPanel'; export { useToasts } from './Toasts'; export { ErrorProvider, ErrorContext } from './ErrorHandling'; export { Dashboard } from './Dashboard'; -export { default as GolemTokenMigration } from './GolemTokenMigration'; diff --git a/src/helpers/erc20.spec.ts b/src/helpers/erc20.spec.ts index 97850a18d81..20716323720 100644 --- a/src/helpers/erc20.spec.ts +++ b/src/helpers/erc20.spec.ts @@ -1,4 +1,4 @@ -import { repTokenMigrationConfig } from '@features/RepTokenMigration/config'; +import { MIGRATION_CONFIGS } from '@features/TokenMigration/config'; import { fAccount, fDerivedApprovalTx, fNetworks, fRopDAI } from '@fixtures'; import { TAddress } from '@types'; import { toTokenBase } from '@utils'; @@ -8,10 +8,10 @@ import { formatApproveTx } from './erc20'; describe('formatApproveTx', () => { it('formats an approval tx without the gas limit or nonce params', () => { const amountToApprove = '5'; - const spender = repTokenMigrationConfig.toContractAddress; + const spender = MIGRATION_CONFIGS.REP.toContractAddress; const baseAmountToApprove = toTokenBase(amountToApprove, fRopDAI.decimal!); const approveTx = formatApproveTx({ - contractAddress: repTokenMigrationConfig.fromContractAddress as TAddress, + contractAddress: MIGRATION_CONFIGS.REP.fromContractAddress as TAddress, baseTokenAmount: baseAmountToApprove, spenderAddress: spender as TAddress, form: { diff --git a/src/routing/routes.tsx b/src/routing/routes.tsx index 847ae2df4d1..fd06e6133ad 100644 --- a/src/routing/routes.tsx +++ b/src/routing/routes.tsx @@ -78,19 +78,8 @@ const TxStatus = lazy(() => import(/* webpackChunkName: "TxStatus" */ '@features/TxStatus/TxStatus') ); -const AaveTokenMigration = lazy(() => - import(/* webpackChunkName: "TokenMigration" */ '@features/AaveTokenMigration') -); - -const AntTokenMigration = lazy(() => - import(/* webpackChunkName: "TokenMigration" */ '@features/AntTokenMigration') -); const Faucet = lazy(() => import(/* webpackChunkName: "Faucet" */ '@features/Faucet')); -const GolemTokenMigration = lazy(() => - import(/* webpackChunkName: "TokenMigration" */ '@features/GolemTokenMigration') -); - const Migrations = lazy(() => import(/* webpackChunkName: "TokenMigration" */ '@features/TokenMigration') ); @@ -285,33 +274,6 @@ export const getStaticAppRoutes = (featureFlags: FeatureFlags): IAppRoute[] => [ enabled: true, component: Migrations }, - { - name: ROUTE_PATHS.AAVE_TOKEN_MIGRATION.name, - title: ROUTE_PATHS.AAVE_TOKEN_MIGRATION.title, - path: ROUTE_PATHS.AAVE_TOKEN_MIGRATION.path, - exact: true, - requireAccounts: true, - enabled: isTruthy(featureFlags.AAVE_TOKEN_MIGRATION), - component: AaveTokenMigration - }, - { - name: ROUTE_PATHS.ANT_TOKEN_MIGRATION.name, - title: ROUTE_PATHS.ANT_TOKEN_MIGRATION.title, - path: ROUTE_PATHS.ANT_TOKEN_MIGRATION.path, - exact: true, - requireAccounts: true, - enabled: isTruthy(featureFlags.ANT_TOKEN_MIGRATION), - component: AntTokenMigration - }, - { - name: ROUTE_PATHS.GOLEM_TOKEN_MIGRATION.name, - title: ROUTE_PATHS.GOLEM_TOKEN_MIGRATION.title, - path: ROUTE_PATHS.GOLEM_TOKEN_MIGRATION.path, - exact: true, - requireAccounts: true, - enabled: isTruthy(featureFlags.GOLEM_TOKEN_MIGRATION), - component: GolemTokenMigration - }, { name: ROUTE_PATHS.FAUCET.name, title: ROUTE_PATHS.FAUCET.title, diff --git a/src/types/tokenMigration.ts b/src/types/tokenMigration.ts index 6bd0a9af442..960775a87f0 100644 --- a/src/types/tokenMigration.ts +++ b/src/types/tokenMigration.ts @@ -3,7 +3,8 @@ import { ISimpleTxFormFull, ITxObject, ITxType, StoreAccount, TAddress, TUuid } export enum MigrationType { REP = 'REP', GOLEM = 'GOLEM', - ANT = 'ANT' + ANT = 'ANT', + AAVE = 'AAVE' } export interface TokenMigrationState { From cceed6b07097db852f94d95d34c5afec993cec2d Mon Sep 17 00:00:00 2001 From: Frederik Bolding Date: Tue, 30 Nov 2021 15:46:25 +0100 Subject: [PATCH 03/12] Add migration selector --- src/components/TextSelector.tsx | 52 +++++++++++++++++++ src/components/index.ts | 1 + src/features/Layout/Navigation/constants.ts | 21 -------- .../TokenMigration/TokenMigrationStepper.tsx | 6 ++- .../__tests__/TokenMigrationForm.test.tsx | 5 +- .../components/TokenMigrationForm.tsx | 41 ++++++++++++--- src/translations/lang/en.json | 3 +- 7 files changed, 98 insertions(+), 31 deletions(-) create mode 100644 src/components/TextSelector.tsx diff --git a/src/components/TextSelector.tsx b/src/components/TextSelector.tsx new file mode 100644 index 00000000000..12907e353d5 --- /dev/null +++ b/src/components/TextSelector.tsx @@ -0,0 +1,52 @@ +import React from 'react'; + +import Box from './Box'; +import { Body } from './NewTypography'; +import Selector from './Selector'; + +export interface OptionType { + label: string; + value: T; +} + +const Option = ({ + value, + selectOption +}: { + value: OptionType; + selectOption?(option: OptionType): void; +}) => { + const handleClick = () => selectOption && selectOption(value); + + return ( + + {value.label} + + ); +}; + +export const TextSelector = ({ + options, + value, + onChange +}: { + options: OptionType[]; + value: OptionType; + onChange(value: OptionType): void; +}) => { + const handleChange = (value: OptionType) => onChange(value); + + return ( + > + name="text-selector" + value={value} + options={options} + onChange={handleChange} + searchable={false} + optionComponent={({ data, selectOption }) => ( +