This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Refactor navigation (#743)
* Refactor a bit of code * Install HealthContext from nomidot * Remove fixme * Simplify a bit the code * Refactor route names * Refactor accounts-app * Create nicer gates and contexts * Make contexts work * Use packages from npm * Fix addresses * Fix accounts and addresses * Remove comment * Updatepackages
- Loading branch information
1 parent
a1996ee
commit 2a40745
Showing
46 changed files
with
564 additions
and
954 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2018-2020 @paritytech/substrate-light-ui authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { KeyringContext } from '@substrate/context'; | ||
import React, { useContext } from 'react'; | ||
import { Redirect, Route, RouteComponentProps, Switch } from 'react-router-dom'; | ||
|
||
import { AddAccount } from './AddAccount'; | ||
import { AccountsOverview } from './Overview'; | ||
|
||
type Props = RouteComponentProps; | ||
|
||
export function Accounts(props: Props): React.ReactElement { | ||
const { location } = props; | ||
const { accounts } = useContext(KeyringContext); | ||
|
||
// Redirect to Add Account page if we have no accounts | ||
if (!Object.keys(accounts).length && !location.pathname.startsWith('/accounts/add')) { | ||
return <Redirect to='/accounts/add' />; | ||
} | ||
|
||
return ( | ||
<Switch> | ||
<Route exact path='/accounts' component={AccountsOverview} /> | ||
<Route path='/accounts/add' component={AddAccount} /> | ||
</Switch> | ||
); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2018-2020 @paritytech/substrate-light-ui authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { KeyringContext } from '@substrate/context'; | ||
import { StackedHorizontal, StyledLinkButton } from '@substrate/ui-components'; | ||
import React, { useContext } from 'react'; | ||
import { Link, RouteComponentProps } from 'react-router-dom'; | ||
|
||
import { AccountsOverviewCard } from './OverviewCard'; | ||
|
||
type Props = RouteComponentProps; | ||
|
||
export function AccountsOverview(props: Props): React.ReactElement { | ||
const { history } = props; | ||
const { accounts } = useContext(KeyringContext); | ||
|
||
return ( | ||
<StackedHorizontal> | ||
{Object.values(accounts).map(account => { | ||
return ( | ||
<AccountsOverviewCard | ||
address={account.json.address} | ||
name={account.json.meta.name} | ||
history={history} | ||
key={account.json.address} | ||
/> | ||
); | ||
})} | ||
<Link to='/accounts/add'> | ||
<StyledLinkButton>Add Account</StyledLinkButton> | ||
</Link> | ||
</StackedHorizontal> | ||
); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2018-2020 @paritytech/substrate-light-ui authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { Margin, Stacked, SubHeader } from '@substrate/ui-components'; | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import { SaveAddress } from './SaveAddress'; | ||
|
||
export function Edit(): React.ReactElement { | ||
return ( | ||
<> | ||
<Link to='/addresses'>← Back</Link> | ||
<Stacked> | ||
<SubHeader>Edit Address</SubHeader> | ||
<Margin top /> | ||
<SaveAddress /> | ||
</Stacked> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2018-2020 @paritytech/substrate-light-ui authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
|
||
import { SingleAddress } from '@polkadot/ui-keyring/observable/types'; | ||
import { KeyringContext } from '@substrate/context'; | ||
import { | ||
AddressSummary, | ||
CopyButton, | ||
Margin, | ||
Stacked, | ||
StackedHorizontal, | ||
StyledLinkButton, | ||
SubHeader, | ||
WithSpace, | ||
WrapperDiv, | ||
} from '@substrate/ui-components'; | ||
import React, { useContext } from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
function renderAllAddressesFromKeyring(addresses: SingleAddress[]): React.ReactElement { | ||
return addresses.length ? ( | ||
<> | ||
{addresses.map((address: SingleAddress) => ( | ||
<React.Fragment key={address.json.address}> | ||
<Margin top /> | ||
<StackedHorizontal> | ||
<Link to={`/addresses/${address.json.address}`}> | ||
<AddressSummary | ||
address={address.json.address} | ||
name={address.json.meta.name} | ||
orientation='horizontal' | ||
size='small' | ||
/> | ||
</Link> | ||
<Margin left /> | ||
<CopyButton value={address.json.address} /> | ||
</StackedHorizontal> | ||
</React.Fragment> | ||
))} | ||
</> | ||
) : ( | ||
<p>It looks like you haven't saved any addresses yet.</p> | ||
); | ||
} | ||
|
||
export function Overview(): React.ReactElement { | ||
const { addresses } = useContext(KeyringContext); | ||
return ( | ||
<WrapperDiv> | ||
<Stacked> | ||
<SubHeader>Select an address to edit its metadata.</SubHeader> | ||
<WithSpace>{renderAllAddressesFromKeyring(Object.values(addresses))}</WithSpace> | ||
<Link to='/addresses/add'> | ||
<StyledLinkButton>Add Address</StyledLinkButton> | ||
</Link> | ||
</Stacked> | ||
</WrapperDiv> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.