From 17df51168208af6aef03da3e885ebe7be691820a Mon Sep 17 00:00:00 2001 From: Michael - Blurpesec Date: Thu, 13 Feb 2020 09:36:25 -0800 Subject: [PATCH 0001/1001] Feature Status Killswitch (#3033) * added a feature status panel that we can edit to hide features * updated to use APP_ROUTES * naming and coments to explain --- common/v2/config/index.ts | 2 +- common/v2/config/isActiveFeature.ts | 47 +++++++ common/v2/features/Layout/Header/Header.tsx | 130 ++++++++++-------- common/v2/features/Layout/Header/constants.ts | 34 +++-- common/v2/routing/routes.tsx | 43 +++++- common/v2/types/routes.ts | 1 + 6 files changed, 182 insertions(+), 75 deletions(-) create mode 100644 common/v2/config/isActiveFeature.ts diff --git a/common/v2/config/index.ts b/common/v2/config/index.ts index 3688698a25d..08bbaa63330 100644 --- a/common/v2/config/index.ts +++ b/common/v2/config/index.ts @@ -40,6 +40,6 @@ export { TOKEN_INFO_URL } from './constants'; export { Fiats } from './fiats'; - +export { IS_ACTIVE_FEATURE } from './isActiveFeature'; export { ROUTE_PATHS } from './routePaths'; export type IWalletConfig = IWalletConfig; diff --git a/common/v2/config/isActiveFeature.ts b/common/v2/config/isActiveFeature.ts new file mode 100644 index 00000000000..ff0bba06c8e --- /dev/null +++ b/common/v2/config/isActiveFeature.ts @@ -0,0 +1,47 @@ +import { IS_DEV } from 'v2/utils'; + +export enum FEATURE_LIST { + DASHBOARD = 'DASHBOARD', + BUY = 'BUY', + SEND_ASSETS = 'SEND_ASSETS', + BROADCAST_TX = 'BROADCAST_TX', + ADD_ACCOUNT = 'ADD_ACCOUNT', + CONTRACT_INTERACT = 'CONTRACT_INTERACT', + CONTRACT_DEPLOY = 'CONTRACT_DEPLOY', + SIGN_MESSAGE = 'SIGN_MESSAGE', + VERIFY_MESSAGE = 'VERIFY_MESSAGE', + TX_HISTORY = 'TX_HISTORY', + REQUEST_ASSETS = 'REQUEST_ASSETS', + CREATE_WALLET = 'CREATE_WALLET', + SCREEN_LOCK = 'SCREEN_LOCK', + SETTINGS = 'SETTINGS', + SWAP = 'SWAP', + DOWNLOAD_DESKTOP_APP = 'DOWNLOAD_DESKTOP_APP', + PRIVATE_TAGS = 'PRIVATE_TAGS', + DEFIZAP = 'DEFIZAP' +} + +export type IIS_ACTIVE_FEATURE = { + readonly [k in FEATURE_LIST]: boolean; +}; + +export const IS_ACTIVE_FEATURE: IIS_ACTIVE_FEATURE = { + DASHBOARD: true, + BUY: true, + SEND_ASSETS: true, + BROADCAST_TX: true, + ADD_ACCOUNT: true, + CONTRACT_INTERACT: true, + CONTRACT_DEPLOY: true, + SIGN_MESSAGE: true, + VERIFY_MESSAGE: true, + TX_HISTORY: true, + REQUEST_ASSETS: true, + CREATE_WALLET: true, + SCREEN_LOCK: true, + SETTINGS: true, + SWAP: true, + DOWNLOAD_DESKTOP_APP: true, + PRIVATE_TAGS: false, + DEFIZAP: IS_DEV +}; diff --git a/common/v2/features/Layout/Header/Header.tsx b/common/v2/features/Layout/Header/Header.tsx index ecc794e6f27..29ce148e91a 100644 --- a/common/v2/features/Layout/Header/Header.tsx +++ b/common/v2/features/Layout/Header/Header.tsx @@ -354,43 +354,47 @@ export function Header({ drawerVisible, toggleDrawerVisible, setDrawerScreen, hi ((style: any) => ( - {links.map(({ title, to, subItems, icon }) => { - return ( -
  • { - e.stopPropagation(); - - if (to) { - history.push(to); - toggleMenu(); - } else { - toggleMenuDropdown(title); - } - }} - > - - {icon && } {title} - {!icon && } - - {subItems && visibleMenuDropdowns[title] && ( -
      - {subItems.map(({ to: innerTo, title: innerTitle }: LinkElement) => ( -
    • { - toggleMenu(); - history.push(innerTo); - }} - > - {innerTitle} -
    • - ))} -
    - )} -
  • - ); - })} + {links + .filter(linkObject => linkObject.enabled) + .map(({ title, to, subItems, icon }) => { + return ( +
  • { + e.stopPropagation(); + + if (to) { + history.push(to); + toggleMenu(); + } else { + toggleMenuDropdown(title); + } + }} + > + + {icon && } {title} + {!icon && } + + {subItems && visibleMenuDropdowns[title] && ( +
      + {subItems + .filter(subItem => subItem.enabled) + .map(({ to: innerTo, title: innerTitle }: LinkElement) => ( +
    • { + toggleMenu(); + history.push(innerTo); + }} + > + {innerTitle} +
    • + ))} +
    + )} +
  • + ); + })}
    {languages[languageSelection]} @@ -438,30 +442,34 @@ export function Header({ drawerVisible, toggleDrawerVisible, setDrawerScreen, hi - {links.map(({ title, to, subItems, icon }) => { - const liProps = to - ? { onClick: () => history.push(to) } - : { - onMouseEnter: () => toggleDropdown(title), - onMouseLeave: () => toggleDropdown(title) - }; - - return ( -
  • - {icon && } {title}{' '} - {!icon && subItems && } - {subItems && visibleDropdowns[title] && ( -
      - {subItems.map(({ to: innerTo, title: innerTitle }: LinkElement) => ( -
    • history.push(innerTo)}> - {innerTitle} -
    • - ))} -
    - )} -
  • - ); - })} + {links + .filter(link => link.enabled) + .map(({ title, to, subItems, icon }) => { + const liProps = to + ? { onClick: () => history.push(to) } + : { + onMouseEnter: () => toggleDropdown(title), + onMouseLeave: () => toggleDropdown(title) + }; + + return ( +
  • + {icon && } {title}{' '} + {!icon && subItems && } + {subItems && visibleDropdowns[title] && ( +
      + {subItems + .filter(subItem => subItem.enabled) + .map(({ to: innerTo, title: innerTitle }: LinkElement) => ( +
    • history.push(innerTo)}> + {innerTitle} +
    • + ))} +
    + )} +
  • + ); + })}
    diff --git a/common/v2/features/Layout/Header/constants.ts b/common/v2/features/Layout/Header/constants.ts index 104a8ec3d03..124a0ce8f82 100644 --- a/common/v2/features/Layout/Header/constants.ts +++ b/common/v2/features/Layout/Header/constants.ts @@ -1,52 +1,63 @@ -import { ROUTE_PATHS } from 'v2/config'; import { translateRaw } from 'v2/translations'; import dashboardIcon from 'common/assets/images/icn-dashboard.svg'; +import { APP_ROUTES_OBJECT } from 'v2/routing/routes'; export const links = [ { title: 'Dashboard', - to: ROUTE_PATHS.DASHBOARD.path, + to: APP_ROUTES_OBJECT.DASHBOARD.path, + enabled: APP_ROUTES_OBJECT.DASHBOARD.enabled, icon: { src: dashboardIcon, width: '16px', height: '12px' } }, { title: 'Manage Assets', + enabled: true, subItems: [ { - to: ROUTE_PATHS.SEND.path, + to: APP_ROUTES_OBJECT.SEND.path, + enabled: APP_ROUTES_OBJECT.SEND.enabled, title: translateRaw('SEND') }, { - to: ROUTE_PATHS.REQUEST_ASSETS.path, + to: APP_ROUTES_OBJECT.REQUEST_ASSETS.path, + enabled: APP_ROUTES_OBJECT.REQUEST_ASSETS.enabled, title: translateRaw('REQUEST') }, { - to: ROUTE_PATHS.SWAP.path, + to: APP_ROUTES_OBJECT.SWAP.path, + enabled: APP_ROUTES_OBJECT.SWAP.enabled, title: translateRaw('SWAP') } ] }, { title: 'Tools', + enabled: true, subItems: [ { - to: ROUTE_PATHS.SIGN_MESSAGE.path, + to: APP_ROUTES_OBJECT.SIGN_MESSAGE.path, + enabled: APP_ROUTES_OBJECT.SIGN_MESSAGE.enabled, title: 'Sign Message' }, { - to: ROUTE_PATHS.VERIFY_MESSAGE.path, + to: APP_ROUTES_OBJECT.VERIFY_MESSAGE.path, + enabled: APP_ROUTES_OBJECT.VERIFY_MESSAGE.enabled, title: 'Verify Message' }, { - to: ROUTE_PATHS.BROADCAST_TX.path, + to: APP_ROUTES_OBJECT.BROADCAST_TX.path, + enabled: APP_ROUTES_OBJECT.BROADCAST_TX.enabled, title: 'Broadcast Transaction' }, { - to: ROUTE_PATHS.INTERACT_WITH_CONTRACTS.path, + to: APP_ROUTES_OBJECT.INTERACT_WITH_CONTRACTS.path, + enabled: APP_ROUTES_OBJECT.INTERACT_WITH_CONTRACTS.enabled, title: 'Interact with Contracts' }, { - to: ROUTE_PATHS.DEPLOY_CONTRACTS.path, + to: APP_ROUTES_OBJECT.DEPLOY_CONTRACTS.path, + enabled: APP_ROUTES_OBJECT.DEPLOY_CONTRACTS.enabled, title: 'Deploy Contracts' }, { @@ -57,6 +68,7 @@ export const links = [ }, { title: 'Settings', - to: ROUTE_PATHS.SETTINGS.path + to: APP_ROUTES_OBJECT.SETTINGS.path, + enabled: APP_ROUTES_OBJECT.SETTINGS.enabled } ]; diff --git a/common/v2/routing/routes.tsx b/common/v2/routing/routes.tsx index dd9f159edf5..6bd8bcd43ea 100644 --- a/common/v2/routing/routes.tsx +++ b/common/v2/routing/routes.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Redirect } from 'react-router-dom'; import { IAppRoute } from 'v2/types'; -import { ROUTE_PATHS } from 'v2/config'; +import { ROUTE_PATHS, IS_ACTIVE_FEATURE } from 'v2/config'; import { AddAccountFlow, CreateWallet, @@ -28,13 +28,18 @@ import { } from 'v2/features'; import { requiresDesktopApp } from './helpers'; +export interface IAppRoutes { + [K: string]: IAppRoute; +} + const DownloadAppRedirect = () => ; -export const APP_ROUTES: IAppRoute[] = [ +export const STATIC_APP_ROUTES: IAppRoute[] = [ { name: ROUTE_PATHS.HOME.name, title: ROUTE_PATHS.HOME.title, path: ROUTE_PATHS.HOME.path, + enabled: true, exact: true, seperateLayout: true, component: Home @@ -43,6 +48,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.DASHBOARD.name, title: ROUTE_PATHS.DASHBOARD.title, path: ROUTE_PATHS.DASHBOARD.path, + enabled: IS_ACTIVE_FEATURE.DASHBOARD, exact: true, requireAccounts: true, component: Dashboard @@ -51,6 +57,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.ADD_ACCOUNT.name, title: ROUTE_PATHS.ADD_ACCOUNT.title, path: `${ROUTE_PATHS.ADD_ACCOUNT.path}/:walletId?`, + enabled: IS_ACTIVE_FEATURE.ADD_ACCOUNT, exact: true, component: AddAccountFlow }, @@ -58,6 +65,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.CREATE_WALLET.name, title: ROUTE_PATHS.CREATE_WALLET.title, path: ROUTE_PATHS.CREATE_WALLET.path, + enabled: IS_ACTIVE_FEATURE.CREATE_WALLET, exact: true, component: requiresDesktopApp(CreateWallet)(DownloadAppRedirect) }, @@ -65,6 +73,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.CREATE_WALLET_MNEMONIC.name, title: ROUTE_PATHS.CREATE_WALLET_MNEMONIC.title, path: ROUTE_PATHS.CREATE_WALLET_MNEMONIC.path, + enabled: IS_ACTIVE_FEATURE.CREATE_WALLET, exact: true, component: requiresDesktopApp(Mnemonic)(DownloadAppRedirect) }, @@ -72,6 +81,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.CREATE_WALLET_KEYSTORE.name, title: ROUTE_PATHS.CREATE_WALLET_KEYSTORE.title, path: ROUTE_PATHS.CREATE_WALLET_KEYSTORE.path, + enabled: IS_ACTIVE_FEATURE.CREATE_WALLET, exact: true, component: requiresDesktopApp(Keystore)(DownloadAppRedirect) }, @@ -79,6 +89,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.DOWNLOAD_DESKTOP_APP.name, title: ROUTE_PATHS.DOWNLOAD_DESKTOP_APP.title, path: ROUTE_PATHS.DOWNLOAD_DESKTOP_APP.path, + enabled: IS_ACTIVE_FEATURE.DOWNLOAD_DESKTOP_APP, exact: true, component: DownloadApp }, @@ -86,6 +97,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.NO_ACCOUNTS.name, title: ROUTE_PATHS.NO_ACCOUNTS.title, path: ROUTE_PATHS.NO_ACCOUNTS.path, + enabled: true, exact: true, component: NoAccounts }, @@ -93,6 +105,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.REQUEST_ASSETS.name, title: ROUTE_PATHS.REQUEST_ASSETS.title, path: ROUTE_PATHS.REQUEST_ASSETS.path, + enabled: IS_ACTIVE_FEATURE.REQUEST_ASSETS, exact: true, requireAccounts: true, component: ReceiveAssets @@ -101,6 +114,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.SCREEN_LOCK_NEW.name, title: ROUTE_PATHS.SCREEN_LOCK_NEW.title, path: ROUTE_PATHS.SCREEN_LOCK_NEW.path, + enabled: IS_ACTIVE_FEATURE.DASHBOARD, exact: true, component: ScreenLockNew }, @@ -108,6 +122,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.SCREEN_LOCK_LOCKED.name, title: ROUTE_PATHS.SCREEN_LOCK_LOCKED.title, path: ROUTE_PATHS.SCREEN_LOCK_LOCKED.path, + enabled: IS_ACTIVE_FEATURE.SCREEN_LOCK, exact: true, component: ScreenLockLocked }, @@ -115,6 +130,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.SCREEN_LOCK_FORGOT.name, title: ROUTE_PATHS.SCREEN_LOCK_FORGOT.title, path: ROUTE_PATHS.SCREEN_LOCK_FORGOT.path, + enabled: IS_ACTIVE_FEATURE.SCREEN_LOCK, exact: true, component: ScreenLockForgotPassword }, @@ -122,6 +138,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.SEND.name, title: ROUTE_PATHS.SEND.title, path: ROUTE_PATHS.SEND.path, + enabled: IS_ACTIVE_FEATURE.SEND_ASSETS, exact: true, requireAccounts: true, component: SendAssets @@ -130,6 +147,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.SETTINGS.name, title: ROUTE_PATHS.SETTINGS.title, path: ROUTE_PATHS.SETTINGS.path, + enabled: IS_ACTIVE_FEATURE.SETTINGS, exact: true, component: Settings }, @@ -137,6 +155,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.SETTINGS_IMPORT.name, title: ROUTE_PATHS.SETTINGS_IMPORT.title, path: ROUTE_PATHS.SETTINGS_IMPORT.path, + enabled: IS_ACTIVE_FEATURE.SETTINGS, exact: true, component: Import }, @@ -144,6 +163,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.SETTINGS_EXPORT.name, title: ROUTE_PATHS.SETTINGS_EXPORT.title, path: ROUTE_PATHS.SETTINGS_EXPORT.path, + enabled: IS_ACTIVE_FEATURE.SETTINGS, exact: true, component: Export }, @@ -151,6 +171,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.SWAP.name, title: ROUTE_PATHS.SWAP.title, path: ROUTE_PATHS.SWAP.path, + enabled: IS_ACTIVE_FEATURE.SWAP, exact: true, component: SwapAssetsFlow }, @@ -158,6 +179,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.SIGN_MESSAGE.name, title: ROUTE_PATHS.SIGN_MESSAGE.title, path: ROUTE_PATHS.SIGN_MESSAGE.path, + enabled: IS_ACTIVE_FEATURE.SIGN_MESSAGE, exact: true, component: SignAndVerifyMessage }, @@ -165,6 +187,7 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.VERIFY_MESSAGE.name, title: ROUTE_PATHS.VERIFY_MESSAGE.title, path: ROUTE_PATHS.VERIFY_MESSAGE.path, + enabled: IS_ACTIVE_FEATURE.VERIFY_MESSAGE, exact: true, component: SignAndVerifyMessage }, @@ -172,18 +195,34 @@ export const APP_ROUTES: IAppRoute[] = [ name: ROUTE_PATHS.BROADCAST_TX.name, title: ROUTE_PATHS.BROADCAST_TX.title, path: ROUTE_PATHS.BROADCAST_TX.path, + enabled: IS_ACTIVE_FEATURE.BROADCAST_TX, component: BroadcastTransactionFlow }, { name: ROUTE_PATHS.INTERACT_WITH_CONTRACTS.name, title: ROUTE_PATHS.INTERACT_WITH_CONTRACTS.title, path: ROUTE_PATHS.INTERACT_WITH_CONTRACTS.path, + enabled: IS_ACTIVE_FEATURE.CONTRACT_INTERACT, component: InteractWithContractsFlow }, { name: ROUTE_PATHS.DEPLOY_CONTRACTS.name, title: ROUTE_PATHS.DEPLOY_CONTRACTS.title, path: ROUTE_PATHS.DEPLOY_CONTRACTS.path, + enabled: IS_ACTIVE_FEATURE.CONTRACT_DEPLOY, component: DeployContractsFlow } ]; + +// Enabled Routes +export const APP_ROUTES = STATIC_APP_ROUTES.filter(APP_ROUTE => APP_ROUTE.enabled); + +export const createAppRoutesObject = (paths: IAppRoute[]) => { + return paths.reduce((navLinks, path) => { + navLinks[path.name] = path; + return navLinks; + }, {} as IAppRoutes); +}; + +// APP_ROUTE_OBJECT is for ALL routes, even disabled ones. +export const APP_ROUTES_OBJECT = createAppRoutesObject(STATIC_APP_ROUTES); diff --git a/common/v2/types/routes.ts b/common/v2/types/routes.ts index fe335c29aaf..0b51ec19bef 100644 --- a/common/v2/types/routes.ts +++ b/common/v2/types/routes.ts @@ -6,6 +6,7 @@ export interface IRoutePath { export interface IAppRoute extends IRoutePath { component: React.ReactNode; + enabled: boolean; exact?: boolean; seperateLayout?: boolean; requireAccounts?: boolean; From e15ddf698ec993a898c7abdb3c26ae992f076f9e Mon Sep 17 00:00:00 2001 From: H <409H@users.noreply.github.com> Date: Fri, 14 Feb 2020 20:53:42 +0000 Subject: [PATCH 0002/1001] Add obb to claim domain (#3035) --- static/.well-known/security.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/static/.well-known/security.txt b/static/.well-known/security.txt index a4140372069..aec20f7e92e 100644 --- a/static/.well-known/security.txt +++ b/static/.well-known/security.txt @@ -6,3 +6,4 @@ Preferred-Languages: en Canonical: https://mycrypto.com/.well-known/security.txt Policy: https://hackerone.com/mycrypto?view_policy=true Hiring: https://about.mycrypto.com/jobs/ +OpenBugBounty: https://openbugbounty.org/bugbounty/MyCrypto/ From d369b3078928e4ff5148af47db3cb208f19e9e41 Mon Sep 17 00:00:00 2001 From: Emmanuel Vilsbol Date: Fri, 14 Feb 2020 20:13:37 -0300 Subject: [PATCH 0003/1001] Dedupe declaration of Wallet signing components (#3041) --- .../SignTransactionWallets/index.ts | 35 +++++++++++++----- .../DeployContracts/DeployContractsFlow.tsx | 3 +- common/v2/features/DeployContracts/helpers.ts | 36 ++----------------- .../InteractWithContractsFlow.tsx | 3 +- .../features/InteractWithContracts/helpers.ts | 36 ++----------------- .../SendAssets/components/SignTransaction.tsx | 31 ++-------------- .../v2/features/SwapAssets/SwapAssetsFlow.tsx | 3 +- .../SwapAssets/components/SetAllowance.tsx | 4 +-- common/v2/features/SwapAssets/helpers.ts | 29 ++------------- 9 files changed, 39 insertions(+), 141 deletions(-) diff --git a/common/v2/components/SignTransactionWallets/index.ts b/common/v2/components/SignTransactionWallets/index.ts index d1969bc3a35..fd96a705ce7 100644 --- a/common/v2/components/SignTransactionWallets/index.ts +++ b/common/v2/components/SignTransactionWallets/index.ts @@ -1,9 +1,26 @@ -export { default as SignTransactionKeystore } from './Keystore'; -export { default as SignTransactionLedger } from './Ledger'; -export { default as SignTransactionWeb3 } from './Web3'; -export { default as SignTransactionMnemonic } from './Mnemonic'; -export { default as SignTransactionParity } from './Parity'; -export { default as SignTransactionPrivateKey } from './PrivateKey'; -export { default as SignTransactionSafeT } from './SafeTmini'; -export { default as SignTransactionTrezor } from './Trezor'; -export { default as HardwareSignTransaction } from './Hardware'; +import { WalletId, SigningComponents } from 'v2/types'; + +import { default as SignTransactionKeystore } from './Keystore'; +import { default as SignTransactionLedger } from './Ledger'; +import { default as SignTransactionWeb3 } from './Web3'; +import { default as SignTransactionMnemonic } from './Mnemonic'; +import { default as SignTransactionParity } from './Parity'; +import { default as SignTransactionPrivateKey } from './PrivateKey'; +import { default as SignTransactionSafeT } from './SafeTmini'; +import { default as SignTransactionTrezor } from './Trezor'; + +export const WALLET_STEPS: SigningComponents = { + [WalletId.PRIVATE_KEY]: SignTransactionPrivateKey, + [WalletId.WEB3]: SignTransactionWeb3, + [WalletId.METAMASK]: SignTransactionWeb3, + [WalletId.TRUST]: SignTransactionWeb3, + [WalletId.FRAME]: SignTransactionWeb3, + [WalletId.COINBASE]: SignTransactionWeb3, + [WalletId.LEDGER_NANO_S]: SignTransactionLedger, + [WalletId.TREZOR]: SignTransactionTrezor, + [WalletId.SAFE_T_MINI]: SignTransactionSafeT, + [WalletId.KEYSTORE_FILE]: SignTransactionKeystore, + [WalletId.PARITY_SIGNER]: SignTransactionParity, + [WalletId.MNEMONIC_PHRASE]: SignTransactionMnemonic, + [WalletId.VIEW_ONLY]: null +}; diff --git a/common/v2/features/DeployContracts/DeployContractsFlow.tsx b/common/v2/features/DeployContracts/DeployContractsFlow.tsx index caf595abb0f..2c2019c49b8 100644 --- a/common/v2/features/DeployContracts/DeployContractsFlow.tsx +++ b/common/v2/features/DeployContracts/DeployContractsFlow.tsx @@ -3,7 +3,7 @@ import { withRouter, RouteComponentProps } from 'react-router-dom'; import styled from 'styled-components'; import { translateRaw } from 'v2/translations'; -import { ExtendedContentPanel, Tabs } from 'v2/components'; +import { ExtendedContentPanel, Tabs, WALLET_STEPS } from 'v2/components'; import { ROUTE_PATHS } from 'v2/config'; import { useStateReducer } from 'v2/utils'; import { ITxReceipt, ISignedTx, Tab } from 'v2/types'; @@ -12,7 +12,6 @@ import { BREAK_POINTS } from 'v2/theme'; import { deployContractsInitialState, DeployContractsFactory } from './stateFactory'; import { Deploy, DeployConfirm, DeployReceipt } from './components'; import { DeployContractsState } from './types'; -import { WALLET_STEPS } from './helpers'; const { SCREEN_XS } = BREAK_POINTS; diff --git a/common/v2/features/DeployContracts/helpers.ts b/common/v2/features/DeployContracts/helpers.ts index 703b734cebf..ced36fe9d0d 100644 --- a/common/v2/features/DeployContracts/helpers.ts +++ b/common/v2/features/DeployContracts/helpers.ts @@ -1,39 +1,7 @@ -import { - WalletId, - SigningComponents, - StoreAccount, - NetworkId, - ITxConfig, - ITxObject -} from 'v2/types'; -import { - SignTransactionPrivateKey, - SignTransactionWeb3, - SignTransactionLedger, - SignTransactionTrezor, - SignTransactionSafeT, - SignTransactionKeystore, - SignTransactionParity, - SignTransactionMnemonic -} from 'v2/components'; +import { StoreAccount, NetworkId, ITxConfig, ITxObject } from 'v2/types'; +import { WALLET_STEPS } from 'v2/components'; import { getAssetByUUID, hexToString, hexWeiToString } from 'v2/services'; -export const WALLET_STEPS: SigningComponents = { - [WalletId.PRIVATE_KEY]: SignTransactionPrivateKey, - [WalletId.WEB3]: SignTransactionWeb3, - [WalletId.METAMASK]: SignTransactionWeb3, - [WalletId.TRUST]: SignTransactionWeb3, - [WalletId.FRAME]: SignTransactionWeb3, - [WalletId.COINBASE]: SignTransactionWeb3, - [WalletId.LEDGER_NANO_S]: SignTransactionLedger, - [WalletId.TREZOR]: SignTransactionTrezor, - [WalletId.SAFE_T_MINI]: SignTransactionSafeT, - [WalletId.KEYSTORE_FILE]: SignTransactionKeystore, - [WalletId.PARITY_SIGNER]: SignTransactionParity, - [WalletId.MNEMONIC_PHRASE]: SignTransactionMnemonic, - [WalletId.VIEW_ONLY]: null -}; - export const getAccountsInNetwork = (accounts: StoreAccount[], networkId: NetworkId) => accounts.filter(acc => acc.networkId === networkId && WALLET_STEPS[acc.wallet]); diff --git a/common/v2/features/InteractWithContracts/InteractWithContractsFlow.tsx b/common/v2/features/InteractWithContracts/InteractWithContractsFlow.tsx index eff7f2b455a..cadf99c9618 100644 --- a/common/v2/features/InteractWithContracts/InteractWithContractsFlow.tsx +++ b/common/v2/features/InteractWithContracts/InteractWithContractsFlow.tsx @@ -3,7 +3,7 @@ import { withRouter, RouteComponentProps } from 'react-router-dom'; import styled from 'styled-components'; import { translateRaw } from 'v2/translations'; -import { ExtendedContentPanel, Tabs } from 'v2/components'; +import { ExtendedContentPanel, Tabs, WALLET_STEPS } from 'v2/components'; import { ROUTE_PATHS, DEFAULT_NETWORK } from 'v2/config'; import { useStateReducer } from 'v2/utils'; import { ITxReceipt, ISignedTx, Tab } from 'v2/types'; @@ -13,7 +13,6 @@ import { BREAK_POINTS } from 'v2/theme'; import { interactWithContractsInitialState, InteractWithContractsFactory } from './stateFactory'; import { Interact, InteractionReceipt } from './components'; import { ABIItem, InteractWithContractState } from './types'; -import { WALLET_STEPS } from './helpers'; import InteractionConfirm from './components/InteractionConfirm'; const { SCREEN_XS } = BREAK_POINTS; diff --git a/common/v2/features/InteractWithContracts/helpers.ts b/common/v2/features/InteractWithContracts/helpers.ts index 46cdc81ff81..43ea39dd54c 100644 --- a/common/v2/features/InteractWithContracts/helpers.ts +++ b/common/v2/features/InteractWithContracts/helpers.ts @@ -1,24 +1,8 @@ import { sortBy, cloneDeep } from 'lodash'; import { bufferToHex } from 'ethereumjs-util'; -import { - WalletId, - SigningComponents, - StoreAccount, - NetworkId, - ITxConfig, - ITxObject -} from 'v2/types'; -import { - SignTransactionPrivateKey, - SignTransactionWeb3, - SignTransactionLedger, - SignTransactionTrezor, - SignTransactionSafeT, - SignTransactionKeystore, - SignTransactionParity, - SignTransactionMnemonic -} from 'v2/components'; +import { StoreAccount, NetworkId, ITxConfig, ITxObject } from 'v2/types'; +import { WALLET_STEPS } from 'v2/components'; import { getAssetByUUID, hexToString, hexWeiToString, inputValueToHex } from 'v2/services'; import { AbiFunction } from 'v2/services/EthService/contracts/ABIFunction'; @@ -95,22 +79,6 @@ export const getFunctionsFromABI = (pAbi: ABIItem[]) => item => item.name.toLowerCase() ).map(x => Object.assign(x, { label: x.name })); -export const WALLET_STEPS: SigningComponents = { - [WalletId.PRIVATE_KEY]: SignTransactionPrivateKey, - [WalletId.WEB3]: SignTransactionWeb3, - [WalletId.METAMASK]: SignTransactionWeb3, - [WalletId.TRUST]: SignTransactionWeb3, - [WalletId.FRAME]: SignTransactionWeb3, - [WalletId.COINBASE]: SignTransactionWeb3, - [WalletId.LEDGER_NANO_S]: SignTransactionLedger, - [WalletId.TREZOR]: SignTransactionTrezor, - [WalletId.SAFE_T_MINI]: SignTransactionSafeT, - [WalletId.KEYSTORE_FILE]: SignTransactionKeystore, - [WalletId.PARITY_SIGNER]: SignTransactionParity, - [WalletId.MNEMONIC_PHRASE]: SignTransactionMnemonic, - [WalletId.VIEW_ONLY]: null -}; - export const getAccountsInNetwork = (accounts: StoreAccount[], networkId: NetworkId) => accounts.filter(acc => acc.networkId === networkId && WALLET_STEPS[acc.wallet]); diff --git a/common/v2/features/SendAssets/components/SignTransaction.tsx b/common/v2/features/SendAssets/components/SignTransaction.tsx index 3105707354e..e8f4a60d71e 100644 --- a/common/v2/features/SendAssets/components/SignTransaction.tsx +++ b/common/v2/features/SendAssets/components/SignTransaction.tsx @@ -5,34 +5,9 @@ import { ITxReceipt, IStepComponentProps, ISignComponentProps, - ISignedTx, - SigningComponents as SigningComponentsType + ISignedTx } from 'v2/types'; -import { - SignTransactionPrivateKey, - SignTransactionWeb3, - SignTransactionLedger, - SignTransactionTrezor, - SignTransactionSafeT, - SignTransactionKeystore, - SignTransactionMnemonic -} from 'v2/components'; - -const SigningComponents: SigningComponentsType = { - [WalletId.PRIVATE_KEY]: SignTransactionPrivateKey, - [WalletId.WEB3]: SignTransactionWeb3, - [WalletId.METAMASK]: SignTransactionWeb3, - [WalletId.TRUST]: SignTransactionWeb3, - [WalletId.FRAME]: SignTransactionWeb3, - [WalletId.COINBASE]: SignTransactionWeb3, - [WalletId.LEDGER_NANO_S]: SignTransactionLedger, - [WalletId.TREZOR]: SignTransactionTrezor, - [WalletId.SAFE_T_MINI]: SignTransactionSafeT, - [WalletId.KEYSTORE_FILE]: SignTransactionKeystore, - [WalletId.PARITY_SIGNER]: null, - [WalletId.MNEMONIC_PHRASE]: SignTransactionMnemonic, - [WalletId.VIEW_ONLY]: null -}; +import { WALLET_STEPS } from 'v2/components'; export default function SignTransaction({ txConfig, onComplete }: IStepComponentProps) { // @TODO remove before deployement. @@ -54,7 +29,7 @@ export default function SignTransaction({ txConfig, onComplete }: IStepComponent } = txConfig; const getWalletComponent = (walletType: WalletId) => { - return SigningComponents[walletType]; + return WALLET_STEPS[walletType]; }; const WalletComponent: React.ComponentType = getWalletComponent(walletName)!; diff --git a/common/v2/features/SwapAssets/SwapAssetsFlow.tsx b/common/v2/features/SwapAssets/SwapAssetsFlow.tsx index a33bd3febab..5da5a62593a 100644 --- a/common/v2/features/SwapAssets/SwapAssetsFlow.tsx +++ b/common/v2/features/SwapAssets/SwapAssetsFlow.tsx @@ -3,7 +3,7 @@ import { withRouter, RouteComponentProps } from 'react-router-dom'; import { translateRaw } from 'v2/translations'; -import { ExtendedContentPanel } from 'v2/components'; +import { ExtendedContentPanel, WALLET_STEPS } from 'v2/components'; import { ROUTE_PATHS } from 'v2/config'; import { ITxReceipt, ISignedTx } from 'v2/types'; import { useStateReducer } from 'v2/utils'; @@ -16,7 +16,6 @@ import { SwapTransactionReceipt, SetAllowance } from './components'; -import { WALLET_STEPS } from './helpers'; import { SwapFlowFactory, swapFlowInitialState } from './stateFactory'; import { SwapState } from './types'; diff --git a/common/v2/features/SwapAssets/components/SetAllowance.tsx b/common/v2/features/SwapAssets/components/SetAllowance.tsx index 7e514a7f57f..68ed9250ec2 100644 --- a/common/v2/features/SwapAssets/components/SetAllowance.tsx +++ b/common/v2/features/SwapAssets/components/SetAllowance.tsx @@ -4,9 +4,7 @@ import styled from 'styled-components'; import translate from 'v2/translations'; import { StoreAccount } from 'v2/types'; -import { Spinner, Typography } from 'v2/components'; - -import { WALLET_STEPS } from '../helpers'; +import { Spinner, Typography, WALLET_STEPS } from 'v2/components'; const AllowanceWrapper = styled.div` display: flex; diff --git a/common/v2/features/SwapAssets/helpers.ts b/common/v2/features/SwapAssets/helpers.ts index e9e7381c740..70f4111a0a2 100644 --- a/common/v2/features/SwapAssets/helpers.ts +++ b/common/v2/features/SwapAssets/helpers.ts @@ -2,7 +2,7 @@ import { ethers } from 'ethers'; import BN from 'bn.js'; import { addHexPrefix } from 'ethereumjs-util'; -import { Asset, StoreAccount, WalletId, ITxConfig, SigningComponents } from 'v2/types'; +import { Asset, StoreAccount, ITxConfig } from 'v2/types'; import { DEXAG_PROXY_CONTRACT } from 'v2/config'; import { fetchGasPriceEstimates, getGasEstimate } from 'v2/services/ApiService'; import { @@ -13,36 +13,11 @@ import { hexToString } from 'v2/services/EthService'; import { getAssetByUUID, getAssetByTicker } from 'v2/services'; -import { - SignTransactionPrivateKey, - SignTransactionWeb3, - SignTransactionLedger, - SignTransactionTrezor, - SignTransactionSafeT, - SignTransactionKeystore, - SignTransactionParity, - SignTransactionMnemonic -} from 'v2/components'; +import { WALLET_STEPS } from 'v2/components'; import { weiToFloat } from 'v2/utils'; import { ISwapAsset } from './types'; -export const WALLET_STEPS: SigningComponents = { - [WalletId.PRIVATE_KEY]: SignTransactionPrivateKey, - [WalletId.WEB3]: SignTransactionWeb3, - [WalletId.METAMASK]: SignTransactionWeb3, - [WalletId.TRUST]: SignTransactionWeb3, - [WalletId.FRAME]: SignTransactionWeb3, - [WalletId.COINBASE]: SignTransactionWeb3, - [WalletId.LEDGER_NANO_S]: SignTransactionLedger, - [WalletId.TREZOR]: SignTransactionTrezor, - [WalletId.SAFE_T_MINI]: SignTransactionSafeT, - [WalletId.KEYSTORE_FILE]: SignTransactionKeystore, - [WalletId.PARITY_SIGNER]: SignTransactionParity, - [WalletId.MNEMONIC_PHRASE]: SignTransactionMnemonic, - [WalletId.VIEW_ONLY]: null -}; - export const makeAllowanceTransaction = async ( trade: any, account: StoreAccount From 602510425d5d29de75c4b3df80af2804b28a5930 Mon Sep 17 00:00:00 2001 From: Emmanuel Vilsbol Date: Fri, 14 Feb 2020 21:35:18 -0300 Subject: [PATCH 0004/1001] Remove reference to Cipher in i18n files (#3043) --- common/v2/translations/lang/ar.json | 1 - common/v2/translations/lang/de.json | 1 - common/v2/translations/lang/el.json | 1 - common/v2/translations/lang/es.json | 1 - common/v2/translations/lang/fi.json | 1 - common/v2/translations/lang/fr.json | 1 - common/v2/translations/lang/ht.json | 1 - common/v2/translations/lang/hu.json | 1 - common/v2/translations/lang/id.json | 1 - common/v2/translations/lang/it.json | 1 - common/v2/translations/lang/ja.json | 1 - common/v2/translations/lang/ko.json | 1 - common/v2/translations/lang/nl.json | 1 - common/v2/translations/lang/no.json | 1 - common/v2/translations/lang/pl.json | 1 - common/v2/translations/lang/pt.json | 1 - common/v2/translations/lang/ru.json | 1 - common/v2/translations/lang/sk.json | 1 - common/v2/translations/lang/sl.json | 1 - common/v2/translations/lang/sv.json | 1 - common/v2/translations/lang/tr.json | 1 - common/v2/translations/lang/vi.json | 1 - common/v2/translations/lang/zhcn.json | 1 - common/v2/translations/lang/zhtw.json | 1 - 24 files changed, 24 deletions(-) diff --git a/common/v2/translations/lang/ar.json b/common/v2/translations/lang/ar.json index d08614a8afc..f45d9794ac8 100644 --- a/common/v2/translations/lang/ar.json +++ b/common/v2/translations/lang/ar.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "وقع الرسالة ", "X_SENDER": "Your Address ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore File ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Phrase ", diff --git a/common/v2/translations/lang/de.json b/common/v2/translations/lang/de.json index fa0910ff390..1b16c95b955 100644 --- a/common/v2/translations/lang/de.json +++ b/common/v2/translations/lang/de.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Sign Message ", "X_SENDER": "Deine Adresse ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore File ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Phrase ", diff --git a/common/v2/translations/lang/el.json b/common/v2/translations/lang/el.json index 2b2ece96b09..5583eaf30c9 100644 --- a/common/v2/translations/lang/el.json +++ b/common/v2/translations/lang/el.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Υπογραφή μηνύματος ", "X_ADDRESS": "Η διεύθυνσή σας ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Αρχείο Keystore ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Μνημονικό ", diff --git a/common/v2/translations/lang/es.json b/common/v2/translations/lang/es.json index 8d3240244d5..1ff7b46651a 100644 --- a/common/v2/translations/lang/es.json +++ b/common/v2/translations/lang/es.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Firmar mensaje ", "X_ADDRESS": "Tu dirección ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Archivo Keystore ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Phrase ", diff --git a/common/v2/translations/lang/fi.json b/common/v2/translations/lang/fi.json index 22eabde4334..622b5e4a2d2 100644 --- a/common/v2/translations/lang/fi.json +++ b/common/v2/translations/lang/fi.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Sign Message ", "X_ADDRESS": "Sinun osoitteesi ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Avainsäilö Tiedosto ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Phrase ", diff --git a/common/v2/translations/lang/fr.json b/common/v2/translations/lang/fr.json index 9dc6baf83f1..8dd2cc91fa0 100644 --- a/common/v2/translations/lang/fr.json +++ b/common/v2/translations/lang/fr.json @@ -4,7 +4,6 @@ "ADDRESS": "Adresse", "NAV_SIGNMSG": "Signer un Message ", "X_ADDRESS": "Votre adresse ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Fichier Keystore ", "X_METAMASK": "MetaMask / Web3 ", "X_MIST": "Mist", diff --git a/common/v2/translations/lang/ht.json b/common/v2/translations/lang/ht.json index 9a288bed5db..2cebc31f062 100644 --- a/common/v2/translations/lang/ht.json +++ b/common/v2/translations/lang/ht.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Sign Message ", "X_ADDRESS": "Your Address ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore File ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Phrase ", diff --git a/common/v2/translations/lang/hu.json b/common/v2/translations/lang/hu.json index 4d1275dc034..75244a52c38 100644 --- a/common/v2/translations/lang/hu.json +++ b/common/v2/translations/lang/hu.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Sign Message ", "X_ADDRESS": "A Te címed ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore Fájl ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonikus frázis ", diff --git a/common/v2/translations/lang/id.json b/common/v2/translations/lang/id.json index 81695df1dec..05668727e7f 100644 --- a/common/v2/translations/lang/id.json +++ b/common/v2/translations/lang/id.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Penandaan Pesan ", "X_ADDRESS": "Alamat Anda ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "File Keystore ", "X_LEDGER": "Ledger ", "X_METAMASK": "MetaMask / Web3 ", diff --git a/common/v2/translations/lang/it.json b/common/v2/translations/lang/it.json index 0982d96c6d1..0cd5646c34a 100644 --- a/common/v2/translations/lang/it.json +++ b/common/v2/translations/lang/it.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Firma messaggio ", "X_ADDRESS": "Il tuo indirizzo ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "File Keystore ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Frase mnemonica ", diff --git a/common/v2/translations/lang/ja.json b/common/v2/translations/lang/ja.json index 03d17144252..01f30a753d9 100644 --- a/common/v2/translations/lang/ja.json +++ b/common/v2/translations/lang/ja.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "メッセージ署名 ", "X_ADDRESS": "自分のアドレス ", - "X_CIPHER": "暗号化ブラウザ", "X_KEYSTORE2": "Keystore ファイル ", "X_METAMASK": "MetaMask / Web3 ", "X_MIST": "Mist", diff --git a/common/v2/translations/lang/ko.json b/common/v2/translations/lang/ko.json index ab27cd13ee8..4a6906eaede 100644 --- a/common/v2/translations/lang/ko.json +++ b/common/v2/translations/lang/ko.json @@ -4,7 +4,6 @@ "ADDRESS": "주소", "NAV_SIGNMSG": "메시지 서명 ", "X_ADDRESS": "내 주소 ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "키스토어 파일 ", "X_METAMASK": "MetaMask ", "X_MIST": "Mist", diff --git a/common/v2/translations/lang/nl.json b/common/v2/translations/lang/nl.json index 5f42d15f2d8..e6b5b187e13 100644 --- a/common/v2/translations/lang/nl.json +++ b/common/v2/translations/lang/nl.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Onderteken Bericht ", "X_ADDRESS": "Je Adres ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore Bestand ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Zin ", diff --git a/common/v2/translations/lang/no.json b/common/v2/translations/lang/no.json index b12e0a89d68..ae15b8792ab 100644 --- a/common/v2/translations/lang/no.json +++ b/common/v2/translations/lang/no.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Signér Melding ", "X_ADDRESS": "Din adresse ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore-fil ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonisk Frase ", diff --git a/common/v2/translations/lang/pl.json b/common/v2/translations/lang/pl.json index 691e926f134..7fe8e5f7ebd 100644 --- a/common/v2/translations/lang/pl.json +++ b/common/v2/translations/lang/pl.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Podpisz Wiadomość ", "X_ADDRESS": "Twój Adres ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Plik Keystore ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonik ", diff --git a/common/v2/translations/lang/pt.json b/common/v2/translations/lang/pt.json index 6da5672d4d2..92cf6768ca9 100644 --- a/common/v2/translations/lang/pt.json +++ b/common/v2/translations/lang/pt.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Sign Message ", "X_ADDRESS": "Seu Endereço ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Arquivo de armazenamento de chaves ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Frase Mnemonic ", diff --git a/common/v2/translations/lang/ru.json b/common/v2/translations/lang/ru.json index 34c8495a18f..70f6fd0d15b 100644 --- a/common/v2/translations/lang/ru.json +++ b/common/v2/translations/lang/ru.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Подписать сообщение ", "X_ADDRESS": "Ваш адрес ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Файл Keystore ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Кодовая фраза ", diff --git a/common/v2/translations/lang/sk.json b/common/v2/translations/lang/sk.json index c92edf0f0bd..899565443a5 100644 --- a/common/v2/translations/lang/sk.json +++ b/common/v2/translations/lang/sk.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Sign Message ", "X_ADDRESS": "Vaša Adresa ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore Súbor ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Phrase (MetaMask / Jaxx ) ", diff --git a/common/v2/translations/lang/sl.json b/common/v2/translations/lang/sl.json index 02e99999b92..d494c3d8eea 100644 --- a/common/v2/translations/lang/sl.json +++ b/common/v2/translations/lang/sl.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Sign Message ", "X_ADDRESS": "Vaš Naslov ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Datoteka za Shrambo ključa Keystore ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Phrase ", diff --git a/common/v2/translations/lang/sv.json b/common/v2/translations/lang/sv.json index 844c99a3663..d7661b2cb16 100644 --- a/common/v2/translations/lang/sv.json +++ b/common/v2/translations/lang/sv.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Sign Message ", "X_ADDRESS": "Din Adress ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore Fil ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Phrase ", diff --git a/common/v2/translations/lang/tr.json b/common/v2/translations/lang/tr.json index c960aa9dc58..90565565517 100644 --- a/common/v2/translations/lang/tr.json +++ b/common/v2/translations/lang/tr.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Mesajı Doğrula ", "X_ADDRESS": "Adresin ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore dosya ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Phrase ", diff --git a/common/v2/translations/lang/vi.json b/common/v2/translations/lang/vi.json index 6cd7b62f45b..1c942123f55 100644 --- a/common/v2/translations/lang/vi.json +++ b/common/v2/translations/lang/vi.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Sign Message ", "X_ADDRESS": "Địa Chỉ Của Bạn ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Định Dạng Keystore ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Cụm từ dễ nhớ ", diff --git a/common/v2/translations/lang/zhcn.json b/common/v2/translations/lang/zhcn.json index a76ee2bd0d6..89d299f2f72 100644 --- a/common/v2/translations/lang/zhcn.json +++ b/common/v2/translations/lang/zhcn.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "Sign Message ", "X_ADDRESS": "你的地址 ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore File ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "Mnemonic Phrase ", diff --git a/common/v2/translations/lang/zhtw.json b/common/v2/translations/lang/zhtw.json index cd24f491226..61afb3dd79e 100644 --- a/common/v2/translations/lang/zhtw.json +++ b/common/v2/translations/lang/zhtw.json @@ -3,7 +3,6 @@ "data": { "NAV_SIGNMSG": "對訊息做簽名 ", "X_ADDRESS": "你的地址 ", - "X_CIPHER": "Cipher Browser", "X_KEYSTORE2": "Keystore 檔 ", "X_METAMASK": "MetaMask / Web3 ", "X_MNEMONIC": "助憶口令 ", From 7845c48a7456906c16700a930dabdffdcf015549 Mon Sep 17 00:00:00 2001 From: Emmanuel Vilsbol Date: Mon, 17 Feb 2020 19:25:20 -0300 Subject: [PATCH 0005/1001] Use TAddress for Account address (#3044) * Use TAdrress for Account address * Cast is no longer required --- common/v2/database/seed/accounts.ts | 12 ++++++------ .../v2/features/CreateWallet/Keystore/Keystore.tsx | 4 ++-- .../v2/features/CreateWallet/Mnemonic/Mnemonic.tsx | 13 +++++++++++-- common/v2/features/DevTools/DevTools.tsx | 11 +++++++++-- common/v2/features/SendAssets/stateFactory.tsx | 2 +- common/v2/services/Store/BalanceService.tsx | 7 +++++-- common/v2/services/Store/StoreProvider.tsx | 3 ++- common/v2/types/account.tsx | 3 ++- 8 files changed, 38 insertions(+), 17 deletions(-) diff --git a/common/v2/database/seed/accounts.ts b/common/v2/database/seed/accounts.ts index 401f0948611..e1fe3dacf3c 100644 --- a/common/v2/database/seed/accounts.ts +++ b/common/v2/database/seed/accounts.ts @@ -1,5 +1,5 @@ import { Overwrite } from 'utility-types'; -import { AssetBalanceObject, TTicker, Account, WalletId, TUuid } from 'v2/types'; +import { TAddress, AssetBalanceObject, TTicker, Account, WalletId, TUuid } from 'v2/types'; export interface SeedAssetBalance extends AssetBalanceObject { ticker: TTicker; @@ -14,7 +14,7 @@ export type DevAccount = Overwrite< export const devAccounts: DevAccount[] = [ { - address: '0xc7bfc8a6bd4e52bfe901764143abef76caf2f912', + address: '0xc7bfc8a6bd4e52bfe901764143abef76caf2f912' as TAddress, networkId: 'Ethereum', assets: [ { @@ -37,7 +37,7 @@ export const devAccounts: DevAccount[] = [ favorite: true }, { - address: '0xc7bfc8a6bd4e52bfe901764143abef76caf2f912', + address: '0xc7bfc8a6bd4e52bfe901764143abef76caf2f912' as TAddress, networkId: 'Goerli', assets: [ { @@ -54,7 +54,7 @@ export const devAccounts: DevAccount[] = [ favorite: true }, { - address: '0x82d69476357a03415e92b5780c89e5e9e972ce75', + address: '0x82d69476357a03415e92b5780c89e5e9e972ce75' as TAddress, networkId: 'Ropsten', assets: [ { @@ -89,7 +89,7 @@ export const devAccounts: DevAccount[] = [ favorite: true }, { - address: '0x8fe684ae26557DfFF70ceE9a4Ff5ee7251a31AD5', + address: '0x8fe684ae26557DfFF70ceE9a4Ff5ee7251a31AD5' as TAddress, networkId: 'Rinkeby', assets: [ { @@ -124,7 +124,7 @@ export const devAccounts: DevAccount[] = [ favorite: true }, { - address: '0xd57478a81CF7DcA65996Ef0550367467cbD6309f', + address: '0xd57478a81CF7DcA65996Ef0550367467cbD6309f' as TAddress, networkId: 'Kovan', assets: [ { diff --git a/common/v2/features/CreateWallet/Keystore/Keystore.tsx b/common/v2/features/CreateWallet/Keystore/Keystore.tsx index c5abb29872d..2195cc977c1 100644 --- a/common/v2/features/CreateWallet/Keystore/Keystore.tsx +++ b/common/v2/features/CreateWallet/Keystore/Keystore.tsx @@ -16,7 +16,7 @@ import { import { stripHexPrefix } from 'v2/services/EthService'; import { WalletFactory } from 'v2/services/WalletService'; import { NotificationTemplates } from 'v2/features/NotificationsPanel'; -import { Account, Asset, ISettings, Network, NetworkId, WalletId } from 'v2/types'; +import { TAddress, Account, Asset, ISettings, Network, NetworkId, WalletId } from 'v2/types'; import { ROUTE_PATHS, N_FACTOR } from 'v2/config'; import { KeystoreStages, keystoreStageToComponentHash, keystoreFlow } from './constants'; @@ -119,7 +119,7 @@ class CreateKeystore extends Component const newAssetID = generateUUID(); const newUUID = generateUUID(); const account: Account = { - address: toChecksumAddress(addHexPrefix(address)), + address: toChecksumAddress(addHexPrefix(address)) as TAddress, networkId: network, wallet: accountType, dPath: path, diff --git a/common/v2/features/DevTools/DevTools.tsx b/common/v2/features/DevTools/DevTools.tsx index 3f68ae32494..d3ed3f60dea 100644 --- a/common/v2/features/DevTools/DevTools.tsx +++ b/common/v2/features/DevTools/DevTools.tsx @@ -13,7 +13,14 @@ import { DataContext } from 'v2/services/Store'; import { useDevTools } from 'v2/services'; -import { Account, AddressBook, WalletId, AssetBalanceObject, ExtendedAddressBook } from 'v2/types'; +import { + TAddress, + Account, + AddressBook, + WalletId, + AssetBalanceObject, + ExtendedAddressBook +} from 'v2/types'; import ToolsNotifications from './ToolsNotifications'; import ToolsAccountList from './ToolsAccountList'; @@ -120,7 +127,7 @@ const DevTools = () => { const { accounts, createAccountWithID, deleteAccount } = useContext(AccountContext); const dummyAccount = { label: 'Foo', - address: '0x80200997f095da94E404F7E0d581AAb1fFba9f7d', + address: '0x80200997f095da94E404F7E0d581AAb1fFba9f7d' as TAddress, networkId: DEFAULT_NETWORK, assets: [ { diff --git a/common/v2/features/SendAssets/stateFactory.tsx b/common/v2/features/SendAssets/stateFactory.tsx index 3693c8cf4f0..d3d09761bc9 100644 --- a/common/v2/features/SendAssets/stateFactory.tsx +++ b/common/v2/features/SendAssets/stateFactory.tsx @@ -181,7 +181,7 @@ const TxConfigFactory: TUseStateReducerFactory = ({ state, setState }) => ? { ...state.txConfig, hash: payload, - to: state.txConfig.senderAccount.address, + to: state.txConfig.senderAccount.address as string, from: state.txConfig.receiverAddress } : fromTxReceiptObj(payload); diff --git a/common/v2/services/Store/BalanceService.tsx b/common/v2/services/Store/BalanceService.tsx index c8a546b5eb6..eb2a4d26081 100644 --- a/common/v2/services/Store/BalanceService.tsx +++ b/common/v2/services/Store/BalanceService.tsx @@ -99,7 +99,7 @@ const getAccountAssetsBalancesWithJsonRPC = async ( return Promise.all([ provider.getRawBalance(account.address).then(balance => ({ [address]: balance })), - getTokenBalances(provider, address as TAddress, tokens) + getTokenBalances(provider, address, tokens) ]) .then(addBalancesToAccount(account)) .catch(_ => account); @@ -137,7 +137,10 @@ export const getAllTokensBalancesOfAccount = async (account: StoreAccount, asset export const getAccountsTokenBalance = async (accounts: StoreAccount[], tokenContract: string) => { const scanner = getScanner(accounts[0].network.nodes[0]); try { - return scanner.getTokenBalances(accounts.map(account => account.address), tokenContract); + return scanner.getTokenBalances( + accounts.map(account => account.address), + tokenContract + ); } catch (err) { throw new Error(err); } diff --git a/common/v2/services/Store/StoreProvider.tsx b/common/v2/services/Store/StoreProvider.tsx index ba2cd37c73f..93417f27ef2 100644 --- a/common/v2/services/Store/StoreProvider.tsx +++ b/common/v2/services/Store/StoreProvider.tsx @@ -1,6 +1,7 @@ import React, { useState, useContext, useMemo, createContext, useEffect } from 'react'; import * as R from 'ramda'; import { + TAddress, Account, StoreAccount, StoreAsset, @@ -228,7 +229,7 @@ export const StoreProvider: React.FC = ({ children }) => { }, addAccount: ( networkId: NetworkId, - address: string, + address: TAddress, accountType: WalletId | undefined, dPath: string ) => { diff --git a/common/v2/types/account.tsx b/common/v2/types/account.tsx index 4e1c9304375..c096a47c2ab 100644 --- a/common/v2/types/account.tsx +++ b/common/v2/types/account.tsx @@ -6,10 +6,11 @@ import { NetworkId } from './networkId'; import { WalletId } from './walletId'; import { ITxReceipt } from './transaction'; import { TUuid } from './uuid'; +import { TAddress } from './address'; export interface Account { label?: string; - address: string; + address: TAddress; networkId: NetworkId; assets: AssetBalanceObject[]; wallet: WalletId; From 27bd6345628be8cc7c092e72e4bfd32628ff4d5c Mon Sep 17 00:00:00 2001 From: Emmanuel Vilsbol Date: Mon, 17 Feb 2020 20:00:38 -0300 Subject: [PATCH 0006/1001] ev/combine account types (#3045) * Rename ExtendedAccount to IAccount * Prefer IRawAccount over ExtendedAccount --- common/v2/components/AccountList.tsx | 6 +++--- .../SignTransactionWallets/Hardware.tsx | 4 ++-- .../displays/TransactionDetailsDisplay.tsx | 4 ++-- common/v2/database/seed/accounts.ts | 4 ++-- common/v2/database/v1.0.0/devSeed.ts | 4 ++-- common/v2/database/v1.0.0/migration.ts | 6 +++--- common/v2/database/v1.0.0/removeSeed.ts | 6 +++--- .../CreateWallet/Keystore/Keystore.tsx | 6 +++--- .../CreateWallet/Mnemonic/Mnemonic.tsx | 6 +++--- .../WalletBreakdown/AccountDropdown.tsx | 8 ++++---- .../components/WalletBreakdown/types.ts | 4 ++-- common/v2/features/DevTools/DevTools.tsx | 18 ++++++++++++------ .../v2/features/DevTools/ToolsAccountList.tsx | 8 ++++---- .../NotificationsPanel/NotificationsPanel.tsx | 4 ++-- .../features/ReceiveAssets/ReceiveAssets.tsx | 4 ++-- .../SendAssets/components/SendAssetsForm.tsx | 8 ++++---- common/v2/services/EthService/nonce.ts | 4 ++-- .../services/Store/Account/AccountProvider.tsx | 18 +++++++++--------- common/v2/services/Store/Account/helpers.ts | 6 +++--- .../Store/AddressBook/AddressBookProvider.tsx | 8 ++++---- .../v2/services/Store/AddressBook/helpers.ts | 7 +++---- .../services/Store/DataManager/reducer.spec.ts | 12 ++++++------ common/v2/services/Store/StoreProvider.tsx | 12 ++++++------ common/v2/services/Store/helpers.tsx | 4 ++-- common/v2/types/account.tsx | 9 ++++----- common/v2/types/index.ts | 2 +- common/v2/types/store.ts | 6 +++--- common/v2/types/transactionFlow.ts | 10 +++++----- 28 files changed, 101 insertions(+), 97 deletions(-) diff --git a/common/v2/components/AccountList.tsx b/common/v2/components/AccountList.tsx index e7429d38818..4bac2bc15ba 100644 --- a/common/v2/components/AccountList.tsx +++ b/common/v2/components/AccountList.tsx @@ -14,7 +14,7 @@ import { } from 'v2/components'; import { truncate } from 'v2/utils'; import { BREAK_POINTS, COLORS, SPACING, breakpointToNumber } from 'v2/theme'; -import { ExtendedAccount, StoreAccount, ExtendedAddressBook } from 'v2/types'; +import { IAccount, StoreAccount, ExtendedAddressBook } from 'v2/types'; import { AccountContext, getLabelByAccount, @@ -206,8 +206,8 @@ export default function AccountList(props: AccountListProps) { function buildAccountTable( accounts: StoreAccount[], - deleteAccount: (a: ExtendedAccount) => void, - updateAccount: (u: TUuid, a: ExtendedAccount) => void, + deleteAccount: (a: IAccount) => void, + updateAccount: (u: TUuid, a: IAccount) => void, deletable?: boolean, favoritable?: boolean, copyable?: boolean, diff --git a/common/v2/components/SignTransactionWallets/Hardware.tsx b/common/v2/components/SignTransactionWallets/Hardware.tsx index 21f85ffa5f7..bbca01c37d2 100644 --- a/common/v2/components/SignTransactionWallets/Hardware.tsx +++ b/common/v2/components/SignTransactionWallets/Hardware.tsx @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; -import { ExtendedAccount as IExtendedAccount, ITxReceipt, ITxObject, ISignedTx } from 'v2/types'; +import { IAccount as IIAccount, ITxReceipt, ITxObject, ISignedTx } from 'v2/types'; import { WALLETS_CONFIG } from 'v2/config'; import { makeTransaction } from 'v2/services/EthService'; import { WalletFactory, HardwareWallet } from 'v2/services/WalletService'; @@ -29,7 +29,7 @@ export const splitDPath = (fullDPath: string): IDestructuredDPath => { export interface IProps { walletIcon: any; signerDescription: string; - senderAccount: IExtendedAccount; + senderAccount: IIAccount; rawTransaction: ITxObject; onSuccess(receipt: ITxReceipt | ISignedTx): void; } diff --git a/common/v2/components/TransactionFlow/displays/TransactionDetailsDisplay.tsx b/common/v2/components/TransactionFlow/displays/TransactionDetailsDisplay.tsx index 52398dc907d..e70501a22b1 100644 --- a/common/v2/components/TransactionFlow/displays/TransactionDetailsDisplay.tsx +++ b/common/v2/components/TransactionFlow/displays/TransactionDetailsDisplay.tsx @@ -2,7 +2,7 @@ import React, { useState, useContext } from 'react'; import { Network } from '@mycrypto/ui'; import { bigNumberify } from 'ethers/utils'; -import { Asset, StoreAccount, ExtendedAccount, Network as INetwork, ITxObject } from 'v2/types'; +import { Asset, StoreAccount, IAccount, Network as INetwork, ITxObject } from 'v2/types'; import { baseToConvertedUnit, totalTxFeeToString } from 'v2/services/EthService'; import { getAccountBalance, StoreContext } from 'v2/services/Store'; import { CopyableCodeBlock, Button } from 'v2/components'; @@ -23,7 +23,7 @@ interface Props { data: string; gasLimit: string; gasPrice: string; - senderAccount: ExtendedAccount; + senderAccount: IAccount; rawTransaction?: ITxObject; signedTransaction?: string; } diff --git a/common/v2/database/seed/accounts.ts b/common/v2/database/seed/accounts.ts index e1fe3dacf3c..63d61048252 100644 --- a/common/v2/database/seed/accounts.ts +++ b/common/v2/database/seed/accounts.ts @@ -1,12 +1,12 @@ import { Overwrite } from 'utility-types'; -import { TAddress, AssetBalanceObject, TTicker, Account, WalletId, TUuid } from 'v2/types'; +import { TAddress, AssetBalanceObject, TTicker, IRawAccount, WalletId, TUuid } from 'v2/types'; export interface SeedAssetBalance extends AssetBalanceObject { ticker: TTicker; } export type DevAccount = Overwrite< - Account, + IRawAccount, { assets: SeedAssetBalance[]; } diff --git a/common/v2/database/v1.0.0/devSeed.ts b/common/v2/database/v1.0.0/devSeed.ts index ee900b6c3b6..1105d635474 100644 --- a/common/v2/database/v1.0.0/devSeed.ts +++ b/common/v2/database/v1.0.0/devSeed.ts @@ -5,7 +5,7 @@ import { devAccounts, DevAccount, SeedAssetBalance, devAssets, devContacts } fro import { Asset, AssetBalanceObject, - ExtendedAccount, + IAccount, AddressBook, LocalStorage, NetworkId, @@ -53,7 +53,7 @@ const addDevAccounts = add(LSKeys.ACCOUNTS)((accounts: DevAccount[], store: Loca }; }; - const updateAssetUuid = ({ assets, ...rest }: ExtendedAccount): ExtendedAccount => ({ + const updateAssetUuid = ({ assets, ...rest }: IAccount): IAccount => ({ ...rest, assets: assets.map(formatAccountAssetBalance(rest.networkId)) }); diff --git a/common/v2/database/v1.0.0/migration.ts b/common/v2/database/v1.0.0/migration.ts index cfe43f061d5..2d5507d530c 100644 --- a/common/v2/database/v1.0.0/migration.ts +++ b/common/v2/database/v1.0.0/migration.ts @@ -3,7 +3,7 @@ import { LocalStorage, Asset, TUuid, - ExtendedAccount, + IAccount, TTicker, NetworkId, AssetBalanceObject @@ -25,7 +25,7 @@ export function migrate(prev: LocalStorage, curr: LocalStorage) { R.values(assets) ); - const updateAccountAssetsUUID = ({ networkId, assets = [], ...rest }: ExtendedAccount) => { + const updateAccountAssetsUUID = ({ networkId, assets = [], ...rest }: IAccount) => { const getTicker = (uuid: TUuid) => { //@ts-ignore const asset = prev.assets[uuid] || {}; @@ -53,7 +53,7 @@ export function migrate(prev: LocalStorage, curr: LocalStorage) { const accounts = Object.assign( {}, curr.accounts, - R.map(updateAccountAssetsUUID, (prev.accounts as R.Functor) || {}) + R.map(updateAccountAssetsUUID, (prev.accounts as R.Functor) || {}) ); // Add labels to address book diff --git a/common/v2/database/v1.0.0/removeSeed.ts b/common/v2/database/v1.0.0/removeSeed.ts index 09cb83219e0..b44db7cb7fe 100644 --- a/common/v2/database/v1.0.0/removeSeed.ts +++ b/common/v2/database/v1.0.0/removeSeed.ts @@ -3,7 +3,7 @@ import * as R from 'ramda'; import { devAccounts, DevAccount, devContacts } from '../seed'; import { AddressBook, - ExtendedAccount, + IAccount, ExtendedAddressBook, LocalStorage, TUuid, @@ -14,14 +14,14 @@ import { import { toArray, toObject, add } from './helpers'; const removeDevAccounts = add(LSKeys.ACCOUNTS)((accounts: DevAccount[], store: LocalStorage) => { - const cmp = (x: ExtendedAccount, y: DevAccount) => x.address === y.address; + const cmp = (x: IAccount, y: DevAccount) => x.address === y.address; const toKeep = R.differenceWith(cmp, toArray(store.accounts), accounts); return R.reduce(toObject('uuid'), {}, toKeep); }); const removeDevAccountsFromSettings = add(LSKeys.SETTINGS)( (accounts: DevAccount[], store: LocalStorage) => { - const cmp = (x: ExtendedAccount, y: DevAccount) => x.address === y.address; + const cmp = (x: IAccount, y: DevAccount) => x.address === y.address; const devAccountUuids = R.differenceWith(cmp, toArray(store.accounts), accounts).map( a => a.uuid ); diff --git a/common/v2/features/CreateWallet/Keystore/Keystore.tsx b/common/v2/features/CreateWallet/Keystore/Keystore.tsx index 2195cc977c1..9018d5e1981 100644 --- a/common/v2/features/CreateWallet/Keystore/Keystore.tsx +++ b/common/v2/features/CreateWallet/Keystore/Keystore.tsx @@ -16,7 +16,7 @@ import { import { stripHexPrefix } from 'v2/services/EthService'; import { WalletFactory } from 'v2/services/WalletService'; import { NotificationTemplates } from 'v2/features/NotificationsPanel'; -import { TAddress, Account, Asset, ISettings, Network, NetworkId, WalletId } from 'v2/types'; +import { TAddress, IRawAccount, Asset, ISettings, Network, NetworkId, WalletId } from 'v2/types'; import { ROUTE_PATHS, N_FACTOR } from 'v2/config'; import { KeystoreStages, keystoreStageToComponentHash, keystoreFlow } from './constants'; @@ -34,7 +34,7 @@ interface State { interface Props extends RouteComponentProps<{}> { settings: ISettings; - createAccountWithID(accountData: Account, uuid: string): void; + createAccountWithID(accountData: IRawAccount, uuid: string): void; updateSettingsAccounts(accounts: string[]): void; createAssetWithID(value: Asset, id: string): void; displayNotification(templateName: string, templateData?: object): void; @@ -118,7 +118,7 @@ class CreateKeystore extends Component { settings: ISettings; - createAccountWithID(accountData: Account, uuid: string): void; + createAccountWithID(accountData: IRawAccount, uuid: string): void; updateSettingsAccounts(accounts: string[]): void; createAssetWithID(value: Asset, id: string): void; displayNotification(templateName: string, templateData?: object): void; @@ -159,7 +159,7 @@ class CreateMnemonic extends Component const newAsset: Asset = getNewDefaultAssetTemplateByNetwork(this.props.assets)(accountNetwork); const newAssetID = generateUUID(); const newUUID = generateUUID(); - const account: Account = { + const account: IRawAccount = { address: toChecksumAddress(addHexPrefix(address)) as TAddress, networkId: network, wallet: accountType, diff --git a/common/v2/features/Dashboard/components/WalletBreakdown/AccountDropdown.tsx b/common/v2/features/Dashboard/components/WalletBreakdown/AccountDropdown.tsx index b4e6d81f306..a54d238edcc 100644 --- a/common/v2/features/Dashboard/components/WalletBreakdown/AccountDropdown.tsx +++ b/common/v2/features/Dashboard/components/WalletBreakdown/AccountDropdown.tsx @@ -7,12 +7,12 @@ import { Checkbox } from 'v2/components'; import { useOnClickOutside, truncate } from 'v2/utils'; import { getLabelByAccount, AddressBookContext } from 'v2/services/Store'; import { COLORS } from 'v2/theme'; -import { ExtendedAccount, ExtendedAddressBook, TUuid } from 'v2/types'; +import { IAccount, ExtendedAddressBook, TUuid } from 'v2/types'; const { BLUE_BRIGHT } = COLORS; interface AccountDropdownProps { - accounts: ExtendedAccount[]; + accounts: IAccount[]; selected: TUuid[]; onSubmit(selected: TUuid[]): void; } @@ -81,12 +81,12 @@ const IconWrapper = styled(Icon)` `; const renderAccounts = ( - accounts: ExtendedAccount[], + accounts: IAccount[], selected: string[], addressBook: ExtendedAddressBook[], handleChange: (uuid: string) => void ) => - accounts.map((account: ExtendedAccount) => { + accounts.map((account: IAccount) => { const addressCard = getLabelByAccount(account, addressBook); const addressLabel = addressCard ? addressCard.label : 'Unknown Account'; return ( diff --git a/common/v2/features/Dashboard/components/WalletBreakdown/types.ts b/common/v2/features/Dashboard/components/WalletBreakdown/types.ts index 7fb99ba8d5e..e81409cccd9 100644 --- a/common/v2/features/Dashboard/components/WalletBreakdown/types.ts +++ b/common/v2/features/Dashboard/components/WalletBreakdown/types.ts @@ -1,4 +1,4 @@ -import { ExtendedAccount, Fiat } from 'v2/types'; +import { IAccount, Fiat } from 'v2/types'; export interface Balance { name: string; @@ -12,7 +12,7 @@ export interface WalletBreakdownProps { balances: Balance[]; totalFiatValue: number; fiat: Fiat; - accounts: ExtendedAccount[]; + accounts: IAccount[]; selected: string[]; toggleShowChart(): void; } diff --git a/common/v2/features/DevTools/DevTools.tsx b/common/v2/features/DevTools/DevTools.tsx index d3ed3f60dea..83893b31b49 100644 --- a/common/v2/features/DevTools/DevTools.tsx +++ b/common/v2/features/DevTools/DevTools.tsx @@ -8,14 +8,15 @@ import { DEFAULT_NETWORK } from 'v2/config'; import { generateUUID } from 'v2/utils'; import { AccountContext, - getLabelByAccount, + getLabelByAddressAndNetwork, AddressBookContext, - DataContext + DataContext, + NetworkContext } from 'v2/services/Store'; import { useDevTools } from 'v2/services'; import { TAddress, - Account, + IRawAccount, AddressBook, WalletId, AssetBalanceObject, @@ -35,8 +36,13 @@ const renderAccountForm = (addressBook: ExtendedAddressBook[]) => ({ handleChange, handleBlur, isSubmitting -}: FormikProps) => { - const detectedLabel: AddressBook | undefined = getLabelByAccount(values, addressBook); +}: FormikProps) => { + const { getNetworkByName } = useContext(NetworkContext); + const detectedLabel: AddressBook | undefined = getLabelByAddressAndNetwork( + values.address, + addressBook, + getNetworkByName(values.networkId) + ); const label = detectedLabel ? detectedLabel.label : 'Unknown Account'; return (
    @@ -162,7 +168,7 @@ const DevTools = () => {
    Enter a new Account
    { + onSubmit={(values: IRawAccount, { setSubmitting }) => { createAccountWithID(values, generateUUID()); setSubmitting(false); }} diff --git a/common/v2/features/DevTools/ToolsAccountList.tsx b/common/v2/features/DevTools/ToolsAccountList.tsx index f932aea4f63..7663678bd4b 100644 --- a/common/v2/features/DevTools/ToolsAccountList.tsx +++ b/common/v2/features/DevTools/ToolsAccountList.tsx @@ -2,7 +2,7 @@ import React, { useContext } from 'react'; import { List, Button } from '@mycrypto/ui'; import styled from 'styled-components'; -import { AddressBook, ExtendedAccount } from 'v2/types'; +import { AddressBook, IAccount } from 'v2/types'; import { truncate } from 'v2/utils'; import { getLabelByAccount, AddressBookContext } from 'v2/services/Store'; import { Account } from 'v2/components'; @@ -18,14 +18,14 @@ const DeleteButton = styled(Button)` `; export interface AccountListProps { - accounts: ExtendedAccount[]; - deleteAccount(account: ExtendedAccount): void; + accounts: IAccount[]; + deleteAccount(account: IAccount): void; } const ToolsAccountList: React.FC = props => { const { addressBook } = useContext(AddressBookContext); const { accounts, deleteAccount } = props; - const list = accounts.map((account: ExtendedAccount, index: number) => { + const list = accounts.map((account: IAccount, index: number) => { const detectedLabel: AddressBook | undefined = getLabelByAccount(account, addressBook); const label = detectedLabel ? detectedLabel.label : 'Unknown Account'; return ( diff --git a/common/v2/features/NotificationsPanel/NotificationsPanel.tsx b/common/v2/features/NotificationsPanel/NotificationsPanel.tsx index e89996de123..e5f70c2e429 100644 --- a/common/v2/features/NotificationsPanel/NotificationsPanel.tsx +++ b/common/v2/features/NotificationsPanel/NotificationsPanel.tsx @@ -3,7 +3,7 @@ import { Panel, Button } from '@mycrypto/ui'; import styled from 'styled-components'; import { SPACING } from 'v2/theme'; -import { ExtendedAccount } from 'v2/types'; +import { IAccount } from 'v2/types'; import { NotificationsContext } from './NotificationsProvider'; import { notificationsConfigs, NotificationTemplates } from './constants'; @@ -27,7 +27,7 @@ const CloseButton = styled(Button)` `; interface Props { - accounts: ExtendedAccount[]; + accounts: IAccount[]; } const NotificationsPanel = ({ accounts }: Props) => { diff --git a/common/v2/features/ReceiveAssets/ReceiveAssets.tsx b/common/v2/features/ReceiveAssets/ReceiveAssets.tsx index df151247095..609a371165d 100644 --- a/common/v2/features/ReceiveAssets/ReceiveAssets.tsx +++ b/common/v2/features/ReceiveAssets/ReceiveAssets.tsx @@ -12,7 +12,7 @@ import { import { ContentPanel, QRCode, AccountDropdown, AssetDropdown } from 'v2/components'; import { AssetContext, getNetworkById, StoreContext } from 'v2/services/Store'; import { isValidAmount } from 'v2/utils'; -import { ExtendedAccount as IExtendedAccount, StoreAccount } from 'v2/types'; +import { IAccount as IIAccount, StoreAccount } from 'v2/types'; import { ROUTE_PATHS } from 'v2/config'; import translate, { translateRaw } from 'v2/translations'; import questionToolTip from 'common/assets/images/icn-question.svg'; @@ -169,7 +169,7 @@ export function ReceiveAssets({ history }: RouteComponentProps<{}>) { name={field.name} value={field.value} accounts={accounts} - onSelect={(option: IExtendedAccount) => { + onSelect={(option: IIAccount) => { form.setFieldValue(field.name, option); if (option.networkId) { setNetworkId(option.networkId); diff --git a/common/v2/features/SendAssets/components/SendAssetsForm.tsx b/common/v2/features/SendAssets/components/SendAssetsForm.tsx index b4356248206..546c05fe063 100644 --- a/common/v2/features/SendAssets/components/SendAssetsForm.tsx +++ b/common/v2/features/SendAssets/components/SendAssetsForm.tsx @@ -31,7 +31,7 @@ import { import { Asset, Network, - ExtendedAccount, + IAccount, StoreAsset, WalletId, IFormikFields, @@ -92,7 +92,7 @@ const initialFormikValues: IFormikFields = { display: '' }, amount: '', - account: {} as ExtendedAccount, // should be renamed senderAccount + account: {} as IAccount, // should be renamed senderAccount network: {} as Network, // Not a field move to state asset: {} as StoreAsset, txDataField: '0x', @@ -354,7 +354,7 @@ export default function SendAssetsForm({ txConfig, onComplete }: IStepComponentP } }; - const handleNonceEstimate = async (account: ExtendedAccount) => { + const handleNonceEstimate = async (account: IAccount) => { if (!values || !values.network || !account) { return; } @@ -424,7 +424,7 @@ export default function SendAssetsForm({ txConfig, onComplete }: IStepComponentP name={field.name} value={field.value} accounts={accountsWithAsset} - onSelect={(option: ExtendedAccount) => { + onSelect={(option: IAccount) => { form.setFieldValue('account', option); //if this gets deleted, it no longer shows as selected on interface, would like to set only object keys that are needed instead of full object handleNonceEstimate(option); handleGasEstimate(); diff --git a/common/v2/services/EthService/nonce.ts b/common/v2/services/EthService/nonce.ts index d69acad0e43..6b0e2632b83 100644 --- a/common/v2/services/EthService/nonce.ts +++ b/common/v2/services/EthService/nonce.ts @@ -1,7 +1,7 @@ -import { ExtendedAccount, Network } from 'v2/types'; +import { IAccount, Network } from 'v2/types'; import { ProviderHandler } from './network'; -export function getNonce(network: Network, account: ExtendedAccount) { +export function getNonce(network: Network, account: IAccount) { const provider = new ProviderHandler(network); return provider.getTransactionCount(account.address); } diff --git a/common/v2/services/Store/Account/AccountProvider.tsx b/common/v2/services/Store/Account/AccountProvider.tsx index 967ce38b847..5b579cc7227 100644 --- a/common/v2/services/Store/Account/AccountProvider.tsx +++ b/common/v2/services/Store/Account/AccountProvider.tsx @@ -4,8 +4,8 @@ import BigNumber from 'bignumber.js'; import * as R from 'ramda'; import { - Account, - ExtendedAccount, + IRawAccount, + IAccount, ITxReceipt, StoreAccount, Asset, @@ -19,14 +19,14 @@ import { getAccountByAddressAndNetworkName } from './helpers'; import { getAllTokensBalancesOfAccount } from '../BalanceService'; export interface IAccountContext { - accounts: ExtendedAccount[]; - createAccountWithID(accountData: Account, uuid: TUuid): void; - deleteAccount(account: ExtendedAccount): void; - updateAccount(uuid: TUuid, accountData: ExtendedAccount): void; - addNewTransactionToAccount(account: ExtendedAccount, transaction: ITxReceipt): void; - getAccountByAddressAndNetworkName(address: string, network: string): ExtendedAccount | undefined; + accounts: IAccount[]; + createAccountWithID(accountData: IRawAccount, uuid: TUuid): void; + deleteAccount(account: IAccount): void; + updateAccount(uuid: TUuid, accountData: IAccount): void; + addNewTransactionToAccount(account: IAccount, transaction: ITxReceipt): void; + getAccountByAddressAndNetworkName(address: string, network: string): IAccount | undefined; updateAccountAssets(account: StoreAccount, assets: Asset[]): Promise; - updateAccountsBalances(toUpate: ExtendedAccount[]): void; + updateAccountsBalances(toUpate: IAccount[]): void; } export const AccountContext = createContext({} as IAccountContext); diff --git a/common/v2/services/Store/Account/helpers.ts b/common/v2/services/Store/Account/helpers.ts index 180dd993ed5..20524f1745a 100644 --- a/common/v2/services/Store/Account/helpers.ts +++ b/common/v2/services/Store/Account/helpers.ts @@ -1,4 +1,4 @@ -import { Asset, ExtendedAccount, StoreAccount } from 'v2/types'; +import { Asset, IAccount, StoreAccount } from 'v2/types'; export const getDashboardAccounts = ( accounts: StoreAccount[], @@ -9,10 +9,10 @@ export const getDashboardAccounts = ( .filter(({ uuid }) => currentAccounts.indexOf(uuid) >= 0); }; -export const getAccountByAddressAndNetworkName = (accounts: ExtendedAccount[]) => ( +export const getAccountByAddressAndNetworkName = (accounts: IAccount[]) => ( address: string, networkId: string -): ExtendedAccount | undefined => { +): IAccount | undefined => { return accounts.find( account => account.address.toLowerCase() === address.toLowerCase() && account.networkId === networkId diff --git a/common/v2/services/Store/AddressBook/AddressBookProvider.tsx b/common/v2/services/Store/AddressBook/AddressBookProvider.tsx index ba367f91140..a5f801816cb 100644 --- a/common/v2/services/Store/AddressBook/AddressBookProvider.tsx +++ b/common/v2/services/Store/AddressBook/AddressBookProvider.tsx @@ -3,7 +3,7 @@ import React, { useContext, createContext } from 'react'; import { AddressBook, ExtendedAddressBook, - ExtendedAccount, + IAccount, Network, StoreAccount, LSKeys, @@ -19,8 +19,8 @@ interface IAddressBookContext { deleteAddressBooks(uuid: TUuid): void; getContactByAddress(address: string): ExtendedAddressBook | undefined; getContactByAddressAndNetwork(address: string, network: Network): ExtendedAddressBook | undefined; - getContactByAccount(account: ExtendedAccount): ExtendedAddressBook | undefined; - getAccountLabel(account: StoreAccount | ExtendedAccount): string | undefined; + getContactByAccount(account: IAccount): ExtendedAddressBook | undefined; + getAccountLabel(account: StoreAccount | IAccount): string | undefined; } export const AddressBookContext = createContext({} as IAddressBookContext); @@ -57,7 +57,7 @@ export const AddressBookProvider: React.FC = ({ children }) => { ); }, getAccountLabel: account => { - const addressContact = state.getContactByAccount(account as ExtendedAccount); + const addressContact = state.getContactByAccount(account as IAccount); return addressContact ? addressContact.label : undefined; } }; diff --git a/common/v2/services/Store/AddressBook/helpers.ts b/common/v2/services/Store/AddressBook/helpers.ts index 5565eb128c8..d8e8eda8f81 100644 --- a/common/v2/services/Store/AddressBook/helpers.ts +++ b/common/v2/services/Store/AddressBook/helpers.ts @@ -1,12 +1,11 @@ - -import { Account, AddressBook, Network, WalletId, ExtendedAddressBook } from 'v2/types'; +import { IAccount, AddressBook, Network, WalletId, ExtendedAddressBook } from 'v2/types'; import { WALLETS_CONFIG } from 'v2/config'; export const getLabelByAccount = ( - account: Account, + account: IAccount, addressLabels: ExtendedAddressBook[] ): ExtendedAddressBook | undefined => { -if (!account || !addressLabels) return; + if (!account || !addressLabels) return; return addressLabels.find( label => account.address.toLowerCase() === label.address.toLowerCase() && diff --git a/common/v2/services/Store/DataManager/reducer.spec.ts b/common/v2/services/Store/DataManager/reducer.spec.ts index 0cd0a6baba1..fa4da22906f 100644 --- a/common/v2/services/Store/DataManager/reducer.spec.ts +++ b/common/v2/services/Store/DataManager/reducer.spec.ts @@ -1,4 +1,4 @@ -import { LSKeys, ExtendedAccount } from 'v2/types'; +import { LSKeys, IAccount } from 'v2/types'; import { ActionT, ActionV, appDataReducer } from './reducer'; const dispatch = (action: ActionV) => (state: any) => appDataReducer(state, action); @@ -6,7 +6,7 @@ const dispatch = (action: ActionV) => (state: any) => appDataReducer(state, acti describe('AppStateReducer', () => { describe('ADD_ITEM', () => { it('can add an Item to an array', () => { - const account = { address: '0x0', uuid: 'fakeUUID' } as ExtendedAccount; + const account = { address: '0x0', uuid: 'fakeUUID' } as IAccount; const prevState = { [LSKeys.ACCOUNTS]: [] }; const payload = { model: LSKeys.ACCOUNTS, @@ -18,8 +18,8 @@ describe('AppStateReducer', () => { }); it('preserves the previous items in the array', () => { - const account1 = { address: '0x1', uuid: 'fakeUUID' } as ExtendedAccount; - const account2 = { address: '0x2', uuid: 'fakeUUID' } as ExtendedAccount; + const account1 = { address: '0x1', uuid: 'fakeUUID' } as IAccount; + const account2 = { address: '0x2', uuid: 'fakeUUID' } as IAccount; const prevState = { [LSKeys.ACCOUNTS]: [account1] }; const payload = { model: LSKeys.ACCOUNTS, @@ -32,8 +32,8 @@ describe('AppStateReducer', () => { }); // it('avoids duplicates in the array', () => { - // const account1 = { address: '0x1', uuid: 'fakeUUID' } as ExtendedAccount; - // const account2 = { address: '0x1', uuid: 'fakeUUID' } as ExtendedAccount; + // const account1 = { address: '0x1', uuid: 'fakeUUID' } as IAccount; + // const account2 = { address: '0x1', uuid: 'fakeUUID' } as IAccount; // const prevState = { [LSKeys.ACCOUNTS]: [account1] }; // const payload = { // model: LSKeys.ACCOUNTS, diff --git a/common/v2/services/Store/StoreProvider.tsx b/common/v2/services/Store/StoreProvider.tsx index 93417f27ef2..8bc1f97f64f 100644 --- a/common/v2/services/Store/StoreProvider.tsx +++ b/common/v2/services/Store/StoreProvider.tsx @@ -2,13 +2,13 @@ import React, { useState, useContext, useMemo, createContext, useEffect } from ' import * as R from 'ramda'; import { TAddress, - Account, + IRawAccount, StoreAccount, StoreAsset, Network, TTicker, ExtendedAsset, - ExtendedAccount, + IAccount, WalletId, Asset, ITxReceipt, @@ -53,15 +53,15 @@ interface State { assetTickers(targetAssets?: StoreAsset[]): TTicker[]; assetUUIDs(targetAssets?: StoreAsset[]): any[]; scanTokens(asset?: ExtendedAsset): Promise; - deleteAccountFromCache(account: ExtendedAccount): void; + deleteAccountFromCache(account: IAccount): void; addAccount( networkId: NetworkId, address: string, accountType: WalletId | undefined, dPath: string - ): Account | undefined; + ): IRawAccount | undefined; getAssetByTicker(symbol: string): Asset | undefined; - getAccount(a: Account): StoreAccount | undefined; + getAccount(a: IRawAccount): StoreAccount | undefined; } export const StoreContext = createContext({} as State); @@ -240,7 +240,7 @@ export const StoreProvider: React.FC = ({ children }) => { accountType! === WalletId.WEB3 ? WalletId[getWeb3Config().id] : accountType!; const newAsset: Asset = getNewDefaultAssetTemplateByNetwork(assets)(network); const newUUID = generateUUID(); - const account: Account = { + const account: IRawAccount = { address, networkId, wallet: walletType, diff --git a/common/v2/services/Store/helpers.tsx b/common/v2/services/Store/helpers.tsx index 26de82686ab..20219d6ecd9 100644 --- a/common/v2/services/Store/helpers.tsx +++ b/common/v2/services/Store/helpers.tsx @@ -6,7 +6,7 @@ import { AssetBalanceObject, Asset, StoreAsset, - ExtendedAccount, + IAccount, StoreAccount, ITxStatus, ITxReceipt @@ -24,7 +24,7 @@ const getAssetsByUuid = (accountAssets: AssetBalanceObject[], assets: Asset[]): .map(asset => ({ ...asset, balance: bigNumberify(asset.balance), mtime: Date.now() })); export const getStoreAccounts = ( - accounts: ExtendedAccount[], + accounts: IAccount[], assets: Asset[], networks: Network[] ): StoreAccount[] => { diff --git a/common/v2/types/account.tsx b/common/v2/types/account.tsx index c096a47c2ab..e36b417067e 100644 --- a/common/v2/types/account.tsx +++ b/common/v2/types/account.tsx @@ -8,7 +8,8 @@ import { ITxReceipt } from './transaction'; import { TUuid } from './uuid'; import { TAddress } from './address'; -export interface Account { +export interface IAccount { + uuid: TUuid; label?: string; address: TAddress; networkId: NetworkId; @@ -20,9 +21,7 @@ export interface Account { favorite: boolean; } -export interface ExtendedAccount extends Account { - uuid: TUuid; -} +export type IRawAccount = Omit; export interface AssetBalanceObject { uuid: TUuid; @@ -31,7 +30,7 @@ export interface AssetBalanceObject { } export type StoreAccount = Overwrite< - ExtendedAccount, + IAccount, { assets: StoreAsset[]; } diff --git a/common/v2/types/index.ts b/common/v2/types/index.ts index be042daf6ca..d29d4ba14eb 100644 --- a/common/v2/types/index.ts +++ b/common/v2/types/index.ts @@ -35,7 +35,7 @@ export { AssetWithDetails } from './asset'; import { StoreAccount } from './account'; -export { Account, ExtendedAccount } from './account'; +export { IRawAccount, IAccount } from './account'; export type StoreAccount = StoreAccount; export { AddressBook, ExtendedAddressBook } from './addressBook'; export { Contract, ExtendedContract } from './contract'; diff --git a/common/v2/types/store.ts b/common/v2/types/store.ts index a88fabe4262..5de46b182a9 100644 --- a/common/v2/types/store.ts +++ b/common/v2/types/store.ts @@ -7,7 +7,7 @@ import { Network, Notification, ExtendedAddressBook, - ExtendedAccount, + IAccount, ExtendedAsset, ExtendedNotification, TUuid, @@ -29,7 +29,7 @@ export interface LocalStorage { readonly version: string; readonly mtime: number; readonly [LSKeys.SETTINGS]: ISettings; - readonly [LSKeys.ACCOUNTS]: Record; + readonly [LSKeys.ACCOUNTS]: Record; readonly [LSKeys.ASSETS]: Record; readonly [LSKeys.NETWORKS]: Record; readonly [LSKeys.CONTRACTS]: Record; @@ -40,7 +40,7 @@ export interface LocalStorage { export interface DataStore { readonly version: string; - readonly [LSKeys.ACCOUNTS]: ExtendedAccount[]; + readonly [LSKeys.ACCOUNTS]: IAccount[]; readonly [LSKeys.ASSETS]: ExtendedAsset[]; readonly [LSKeys.NETWORKS]: Network[]; readonly [LSKeys.CONTRACTS]: ExtendedContract[]; diff --git a/common/v2/types/transactionFlow.ts b/common/v2/types/transactionFlow.ts index 652d5dccae8..95d555c209b 100644 --- a/common/v2/types/transactionFlow.ts +++ b/common/v2/types/transactionFlow.ts @@ -1,9 +1,9 @@ import { Asset, - ExtendedAccount as IExtendedAccount, + IAccount as IIAccount, Network as INetwork, GasEstimates, - ExtendedAccount, + IAccount, ITxReceipt, WalletId } from 'v2/types'; @@ -25,7 +25,7 @@ export interface ITxConfig { readonly rawTransaction: ITxObject /* The rawTransaction object that will be signed */; readonly amount: string; readonly receiverAddress: string; - readonly senderAccount: IExtendedAccount; + readonly senderAccount: IIAccount; readonly from: string; readonly asset: Asset; readonly baseAsset: Asset; @@ -41,7 +41,7 @@ export interface IFormikFields { asset: Asset; address: IReceiverAddress; amount: string; - account: IExtendedAccount; + account: IIAccount; txDataField: string; gasEstimates: GasEstimates; gasPriceField: string; @@ -55,7 +55,7 @@ export interface IFormikFields { export interface ISignComponentProps { network: INetwork; - senderAccount: ExtendedAccount; + senderAccount: IAccount; rawTransaction: ITxObject; children?: never; onSuccess(receipt: ITxReceipt | ISignedTx): void; From 4bd47d307329c013a9d119925c0710aeaf9ed3ac Mon Sep 17 00:00:00 2001 From: Michael - Blurpesec Date: Mon, 17 Feb 2020 17:11:21 -0800 Subject: [PATCH 0007/1001] added sorting on add-account flow (#3038) --- common/v2/components/AccountList.tsx | 140 ++++++++++++++++++++++++--- 1 file changed, 125 insertions(+), 15 deletions(-) diff --git a/common/v2/components/AccountList.tsx b/common/v2/components/AccountList.tsx index 4bac2bc15ba..a427e1a580c 100644 --- a/common/v2/components/AccountList.tsx +++ b/common/v2/components/AccountList.tsx @@ -26,6 +26,7 @@ import { DashboardPanel } from './DashboardPanel'; import { RatesContext } from 'v2/services'; import { default as Currency } from './Currency'; import { TUuid } from 'v2/types/uuid'; +import IconArrow from './IconArrow'; const Label = styled.span` display: flex; @@ -204,6 +205,76 @@ export default function AccountList(props: AccountListProps) { ); } +type ISortTypes = + | 'label' + | 'label-reverse' + | 'address' + | 'address-reverse' + | 'network' + | 'network-reverse' + | 'value' + | 'value-reverse'; +type IColumnValues = + | 'ACCOUNT_LIST_LABEL' + | 'ACCOUNT_LIST_ADDRESS' + | 'ACCOUNT_LIST_NETWORK' + | 'ACCOUNT_LIST_VALUE'; + +export interface ISortingState { + sortState: { + ACCOUNT_LIST_LABEL: 'label' | 'label-reverse'; + ACCOUNT_LIST_ADDRESS: 'address' | 'address-reverse'; + ACCOUNT_LIST_NETWORK: 'network' | 'network-reverse'; + ACCOUNT_LIST_VALUE: 'value' | 'value-reverse'; + }; + activeSort: ISortTypes; +} + +const initialSortingState: ISortingState = { + sortState: { + ACCOUNT_LIST_LABEL: 'label', + ACCOUNT_LIST_ADDRESS: 'address', + ACCOUNT_LIST_NETWORK: 'network', + ACCOUNT_LIST_VALUE: 'value' + }, + activeSort: 'value' +}; + +interface ITableFullAccountType { + account: StoreAccount; + index: number; + label: string; + total: number; + addressCard: ExtendedAddressBook; +} + +type TSortFunction = (a: ITableFullAccountType, b: ITableFullAccountType) => number; + +const getSortingFunction = (sortKey: ISortTypes): TSortFunction => { + switch (sortKey) { + case 'value': + return (a: ITableFullAccountType, b: ITableFullAccountType) => b.total - a.total; + case 'value-reverse': + return (a: ITableFullAccountType, b: ITableFullAccountType) => a.total - b.total; + case 'label': + return (a: ITableFullAccountType, b: ITableFullAccountType) => a.label.localeCompare(b.label); + case 'label-reverse': + return (a: ITableFullAccountType, b: ITableFullAccountType) => b.label.localeCompare(a.label); + case 'address': + return (a: ITableFullAccountType, b: ITableFullAccountType) => + a.account.address.localeCompare(b.account.address); + case 'address-reverse': + return (a: ITableFullAccountType, b: ITableFullAccountType) => + b.account.address.localeCompare(a.account.address); + case 'network': + return (a: ITableFullAccountType, b: ITableFullAccountType) => + a.account.networkId.localeCompare(b.account.networkId); + case 'network-reverse': + return (a: ITableFullAccountType, b: ITableFullAccountType) => + b.account.networkId.localeCompare(a.account.networkId); + } +}; + function buildAccountTable( accounts: StoreAccount[], deleteAccount: (a: IAccount) => void, @@ -214,22 +285,70 @@ function buildAccountTable( overlayRows?: number[], setDeletingIndex?: any ) { + const [sortingState, setSortingState] = useState(initialSortingState); const { totalFiat } = useContext(StoreContext); const { getAssetRate } = useContext(RatesContext); const { settings } = useContext(SettingsContext); const { addressBook, updateAddressBooks, createAddressBooks } = useContext(AddressBookContext); + + const updateSortingState = (id: IColumnValues) => { + const currentBtnState = sortingState.sortState[id]; + if (currentBtnState.indexOf('-reverse') > -1) { + const newActiveSort = currentBtnState.split('-reverse')[0] as ISortTypes; + setSortingState({ + sortState: { + ...sortingState.sortState, + [id]: newActiveSort + }, + activeSort: newActiveSort + }); + } else { + const newActiveSort = (currentBtnState + '-reverse') as ISortTypes; + setSortingState({ + sortState: { + ...sortingState.sortState, + [id]: newActiveSort + }, + activeSort: newActiveSort + }); + } + }; + + const getColumnSortDirection = (id: IColumnValues): boolean => + sortingState.sortState[id].indexOf('-reverse') > -1 ? true : false; + + const convertColumnToClickable = (id: IColumnValues) => ( +
    updateSortingState(id)}> + {translateRaw(id)} +
    + ); + const columns = [ - translateRaw('ACCOUNT_LIST_LABEL'), - translateRaw('ACCOUNT_LIST_ADDRESS'), - translateRaw('ACCOUNT_LIST_NETWORK'), - + convertColumnToClickable('ACCOUNT_LIST_LABEL'), + convertColumnToClickable('ACCOUNT_LIST_ADDRESS'), + convertColumnToClickable('ACCOUNT_LIST_NETWORK'), + updateSortingState('ACCOUNT_LIST_VALUE')} + > {translateRaw('ACCOUNT_LIST_VALUE')} + , {translateRaw('ACCOUNT_LIST_DELETE')} ]; + const getFullTableData = accounts + .map((account, index) => { + const addressCard: ExtendedAddressBook | undefined = getLabelByAccount(account, addressBook); + const total = totalFiat([account])(getAssetRate); + const label = addressCard ? addressCard.label : 'Unknown Account'; + return { account, index, label, total, addressCard }; + }) + .sort(getSortingFunction(sortingState.activeSort)); + return { head: deletable ? columns : columns.slice(0, columns.length - 1), overlay: @@ -251,10 +370,7 @@ function buildAccountTable( <> ), overlayRows, - body: accounts.map((account, index) => { - const addressCard: ExtendedAddressBook | undefined = getLabelByAccount(account, addressBook); - const total = totalFiat([account])(getAssetRate); - const label = addressCard ? addressCard.label : 'Unknown Account'; + body: getFullTableData.map(({ account, index, label, total, addressCard }) => { const bodyContent = [