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
refactor: Refactor navigation #743
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d4a8a00
Refactor a bit of code
amaury1093 fd45db3
Install HealthContext from nomidot
amaury1093 9fd7c4f
Remove fixme
amaury1093 4469375
Simplify a bit the code
amaury1093 df7c72a
Refactor route names
amaury1093 88b0592
Refactor accounts-app
amaury1093 7d51156
Create nicer gates and contexts
amaury1093 b66f913
Make contexts work
amaury1093 4223fc6
Use packages from npm
amaury1093 8ea5bc9
Merge master
amaury1093 f057fd0
Fix addresses
amaury1093 ebb5db6
Fix accounts and addresses
amaury1093 3cd886f
Remove comment
amaury1093 c1cb484
Updatepackages
amaury1093 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so I'm pretty sure this KeyringContext is pretty much useless, or it should be according to the code, since ui-keyring calls
cryptoWaitReady
anyway. But if it fixes something, then let's keep it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to remove it and see (iirc it was not related to cryptoWaitReady but to keyring.loadall)