added forget modal functionality to addresses (#288)
* added forget modal functionality to addresses * fixed mistakes and added centering css * Bump dependencies * FIXME around RxJs (with types) upgrade * fix: Fixes #290. Toggles Address Add/Edit menu correctly (#292) * fix: Fixes #290. Toggles Address Add/Edit menu correctly * fix: Rename to hasNoAddresses * fixed modal title
This commit is contained in:
parent
3eed706835
commit
2c24ed9d78
@ -16,6 +16,7 @@ import withObservableBase from '@polkadot/ui-react-rx/with/observableBase';
|
||||
|
||||
import Forgetting from './Forgetting';
|
||||
import AddressSummary from '@polkadot/ui-app/AddressSummary';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
type Props = I18nProps & {
|
||||
|
||||
@ -15,6 +15,7 @@ import keyring from '@polkadot/ui-keyring/index';
|
||||
import addressObservable from '@polkadot/ui-keyring/observable/addresses';
|
||||
import withObservableBase from '@polkadot/ui-react-rx/with/observableBase';
|
||||
|
||||
import Forgetting from './Forgetting';
|
||||
import translate from './translate';
|
||||
|
||||
type Props = I18nProps & {
|
||||
@ -24,7 +25,8 @@ type Props = I18nProps & {
|
||||
type State = {
|
||||
current: KeyringAddress | null,
|
||||
editedName: string,
|
||||
isEdited: boolean
|
||||
isEdited: boolean,
|
||||
isForgetOpen: boolean
|
||||
};
|
||||
|
||||
class Editor extends React.PureComponent<Props, State> {
|
||||
@ -37,8 +39,15 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
render () {
|
||||
const { isForgetOpen, current } = this.state;
|
||||
return (
|
||||
<div className='addresses--Editor'>
|
||||
<Forgetting
|
||||
isOpen={isForgetOpen}
|
||||
onClose={this.toggleForget}
|
||||
doForget={this.onForget}
|
||||
currentAddress={current}
|
||||
/>
|
||||
{this.renderData()}
|
||||
{this.renderButtons()}
|
||||
</div>
|
||||
@ -57,7 +66,7 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
<Button.Group>
|
||||
<Button
|
||||
isNegative
|
||||
onClick={this.onForget}
|
||||
onClick={this.toggleForget}
|
||||
text={t('editor.forget', {
|
||||
defaultValue: 'Forget'
|
||||
})}
|
||||
@ -140,7 +149,8 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
return {
|
||||
current,
|
||||
editedName: name,
|
||||
isEdited: false
|
||||
isEdited: false,
|
||||
isForgetOpen: false
|
||||
};
|
||||
}
|
||||
|
||||
@ -160,11 +170,13 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
} else {
|
||||
editedName = '';
|
||||
}
|
||||
let isForgetOpen = false;
|
||||
|
||||
return {
|
||||
current,
|
||||
editedName,
|
||||
isEdited
|
||||
isEdited,
|
||||
isForgetOpen
|
||||
};
|
||||
}
|
||||
);
|
||||
@ -207,6 +219,14 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
} as State);
|
||||
}
|
||||
|
||||
toggleForget = (): void => {
|
||||
this.setState(
|
||||
({ isForgetOpen }: State) => ({
|
||||
isForgetOpen: !isForgetOpen
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
onForget = (): void => {
|
||||
const { current } = this.state;
|
||||
|
||||
|
||||
97
packages/app-addresses/src/Forgetting.tsx
Normal file
97
packages/app-addresses/src/Forgetting.tsx
Normal file
@ -0,0 +1,97 @@
|
||||
// Copyright 2017-2018 @polkadot/app-accounts authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import { KeyringAddress } from '@polkadot/ui-keyring/types';
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import Button from '@polkadot/ui-app/Button';
|
||||
import Modal from '@polkadot/ui-app/Modal';
|
||||
import AddressSummary from '@polkadot/ui-app/AddressSummary';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
type Props = I18nProps & {
|
||||
isOpen: boolean,
|
||||
onClose: () => void,
|
||||
doForget: () => void,
|
||||
currentAddress: KeyringAddress | null
|
||||
};
|
||||
|
||||
class Forgetting extends React.PureComponent<Props> {
|
||||
constructor (props: Props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render () {
|
||||
const { isOpen, style } = this.props;
|
||||
|
||||
if (!isOpen) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
size='tiny'
|
||||
dimmer='inverted'
|
||||
open
|
||||
style={style}
|
||||
>
|
||||
{this.renderContent()}
|
||||
{this.renderButtons()}
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
renderButtons () {
|
||||
const { onClose, doForget, t } = this.props;
|
||||
|
||||
return (
|
||||
<Modal.Actions>
|
||||
<Button.Group>
|
||||
<Button
|
||||
isNegative
|
||||
onClick={onClose}
|
||||
text={t('forget.close', {
|
||||
defaultValue: 'Cancel'
|
||||
})}
|
||||
/>
|
||||
<Button.Or />
|
||||
<Button
|
||||
isPrimary
|
||||
onClick={doForget}
|
||||
text={t('forget.forget', {
|
||||
defaultValue: 'Forget'
|
||||
})}
|
||||
/>
|
||||
</Button.Group>
|
||||
</Modal.Actions>
|
||||
);
|
||||
}
|
||||
|
||||
renderContent () {
|
||||
const { t, currentAddress } = this.props;
|
||||
|
||||
const address = currentAddress
|
||||
? currentAddress.address()
|
||||
: undefined;
|
||||
|
||||
return [
|
||||
<Modal.Header key='header'>
|
||||
{t('forget.header', {
|
||||
defaultValue: 'Confirm address removal'
|
||||
})}
|
||||
</Modal.Header>,
|
||||
<Modal.Content className='forgetting-Address' key='content'>
|
||||
<AddressSummary
|
||||
className='ui--AddressSummary-base'
|
||||
value={address || ''}
|
||||
/>
|
||||
</Modal.Content>
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(Forgetting);
|
||||
@ -1,3 +1,7 @@
|
||||
/* Copyright 2017-2018 @polkadot/app-addresses authors & contributors
|
||||
/* This software may be modified and distributed under the terms
|
||||
/* of the ISC license. See the LICENSE file for details. */
|
||||
|
||||
.forgetting-Address {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user