diff --git a/packages/extension-ui/src/Popup/Accounts/Account.tsx b/packages/extension-ui/src/Popup/Accounts/Account.tsx index 48cc8c91..23148a07 100644 --- a/packages/extension-ui/src/Popup/Accounts/Account.tsx +++ b/packages/extension-ui/src/Popup/Accounts/Account.tsx @@ -2,65 +2,62 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { OnActionFromCtx } from '../../components/types'; + import React, { useState } from 'react'; import { Link } from 'react-router-dom'; -import { ActionBar, Address } from '../../components'; -import { ActionContext } from '../../components/contexts'; +import { ActionBar, Address, withAction } from '../../components'; import { editAccount } from '../../messaging'; import { Name } from '../../partials'; type Props = { address: string, - className?: string + className?: string, + onAction: OnActionFromCtx }; -export default function Account ({ address, className }: Props) { +function Account ({ address, className, onAction }: Props) { const [isEditing, setEditing] = useState(false); const [editedname, setName] = useState(null as string | null); const toggleEdit = (): void => { setEditing(!isEditing); }; + const saveChanges = (): void => { + if (editedname && editedname !== name) { + editAccount(address, editedname) + .then(() => onAction()) + .catch(console.error); + } + + toggleEdit(); + }; return ( - - {(onAction) => { - const saveChanges = (): void => { - if (editedname && editedname !== name) { - editAccount(address, editedname) - .then(() => onAction()) - .catch(console.error); - } - - toggleEdit(); - }; - - return ( -
- ) - : undefined - } - > - - Edit - Forget - -
- ); - }} -
+
+ ) + : undefined + } + > + + Edit + Forget + +
); } + +export default withAction(Account); diff --git a/packages/extension-ui/src/Popup/Accounts/index.tsx b/packages/extension-ui/src/Popup/Accounts/index.tsx index 9787e0dc..52c32982 100644 --- a/packages/extension-ui/src/Popup/Accounts/index.tsx +++ b/packages/extension-ui/src/Popup/Accounts/index.tsx @@ -2,40 +2,41 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { AccountsFromCtx } from '../../components/types'; + import React from 'react'; -import { Button, Header, Tip } from '../../components'; -import { AccountContext } from '../../components/contexts'; +import { Button, Header, Tip, withAccounts } from '../../components'; import Account from './Account'; -type Props = {}; +type Props = { + accounts: AccountsFromCtx +}; -export default function Accounts (props: Props) { +function Accounts ({ accounts }: Props) { return ( - - {(accounts) => ( -
-
- { - (accounts.length === 0) - ? You currently don't have any accounts. Either create a new account or if you have an existing account you wish to use, import it with the seed phrase - : accounts.map(({ address }) => ( - - )) - } -
- )} -
+
+
+ { + (accounts.length === 0) + ? You currently don't have any accounts. Either create a new account or if you have an existing account you wish to use, import it with the seed phrase + : accounts.map(({ address }) => ( + + )) + } +
); } + +export default withAccounts(Accounts); diff --git a/packages/extension-ui/src/Popup/Create.tsx b/packages/extension-ui/src/Popup/Create.tsx index b63935d1..67b2ca13 100644 --- a/packages/extension-ui/src/Popup/Create.tsx +++ b/packages/extension-ui/src/Popup/Create.tsx @@ -2,16 +2,19 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { OnActionFromCtx } from '../components/types'; + import React, { useState, useEffect } from 'react'; -import { Address, Button, Header, Loading, TextArea } from '../components'; -import { ActionContext } from '../components/contexts'; +import { Address, Button, Header, Loading, TextArea, withAction } from '../components'; import { createAccount, createSeed } from '../messaging'; import { Back, Name, Password } from '../partials'; -type Props = {}; +type Props = { + onAction: OnActionFromCtx +}; -export default function Create (props: Props) { +function Create ({ onAction }: Props) { const [account, setAccount] = useState(null as null | { address: string, seed: string }); const [name, setName] = useState(null as string | null); const [password, setPassword] = useState(null as string | null); @@ -22,52 +25,48 @@ export default function Create (props: Props) { .catch(console.error); }, []); - return ( - - {(onAction) => { - // FIXME Duplicated between here and Import.tsx - const onCreate = (): void => { - // this should always be the case - if (name && password && account) { - createAccount(name, password, account.seed) - .then(() => onAction('/')) - .catch(console.error); - } - }; + // FIXME Duplicated between here and Import.tsx + const onCreate = (): void => { + // this should always be the case + if (name && password && account) { + createAccount(name, password, account.seed) + .then(() => onAction('/')) + .catch(console.error); + } + }; - return ( -
-
- - {account && ( - <> -