1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

refactoring Address to Account

This commit is contained in:
Szymon Lesisz 2018-05-16 18:30:46 +02:00
parent b90ba80ec4
commit a5b6e20525
15 changed files with 54 additions and 48 deletions

View File

@ -32,7 +32,7 @@ export const init = (): ThunkAction => {
if (!coin) return;
const state: State = {
index: parseInt(urlParams.address),
index: parseInt(urlParams.account),
deviceState: selected.state || '0',
deviceId: selected.features ? selected.features.device_id : '0',
deviceInstance: selected.instance,

View File

@ -115,7 +115,7 @@ export const start = (device: TrezorDevice, network: string, ignoreCompleted?: b
// start from beginning
dispatch( begin(device, network) );
} else {
dispatch( discoverAddress(device, discoveryProcess) );
dispatch( discoverAccount(device, discoveryProcess) );
}
}
}
@ -189,7 +189,7 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => {
}
}
const discoverAddress = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => {
const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => {
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const derivedKey = discoveryProcess.hdKey.derive(`m/${discoveryProcess.accountIndex}`);
@ -296,7 +296,7 @@ const discoverAddress = (device: TrezorDevice, discoveryProcess: Discovery): Asy
const addressIsEmpty = nonce < 1 && !balance.greaterThan(0);
if (!addressIsEmpty) {
dispatch( discoverAddress(device, discoveryProcess) );
dispatch( discoverAccount(device, discoveryProcess) );
} else {
// release acquired sesssion
await TrezorConnect.getFeatures({

View File

@ -234,7 +234,7 @@ export const onSelectDevice = (device: TrezorDevice | Device): ThunkAction => {
const deviceId: string = device.features.device_id;
const urlParams: RouterLocationState = getState().router.location.state;
// let url: string = `/device/${ device.features.device_id }/network/ethereum/address/0`;
// let url: string = `/device/${ device.features.device_id }/network/ethereum/account/0`;
let url: string = `/device/${ deviceId }`;
let instance: ?number;
// check if device is not TrezorDevice type
@ -250,7 +250,7 @@ export const onSelectDevice = (device: TrezorDevice | Device): ThunkAction => {
}
}
// check if current location is not set to this device
//dispatch( push(`/device/${ device.features.device_id }/network/etc/address/0`) );
//dispatch( push(`/device/${ device.features.device_id }/network/etc/account/0`) );
if (urlParams.deviceInstance !== instance || urlParams.device !== deviceId) {
dispatch( push(url) );
@ -498,7 +498,7 @@ export const selectDuplicatedDevice = (): AsyncAction => {
}
export function addAddress(): ThunkAction {
export function addAccount(): ThunkAction {
return (dispatch: Dispatch, getState: GetState): void => {
const selected = findSelectedDevice(getState().connect);
if (!selected) return;

View File

@ -71,7 +71,7 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
}
if (discovery && !discovery.completed && !deviceStatusNotification) {
deviceStatusNotification = <Notification className="info" title="Loading accounts" />;
deviceStatusNotification = <Notification className="info" title="Loading accounts..." />;
}
this.setState({
@ -93,7 +93,7 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
const accountState = props.abstractAccount;
if (!accountState) {
return (<section><Notification className="info" title="Loading device" /></section>);
return (<section><Notification className="info" title="Loading device..." /></section>);
}
const {
@ -106,9 +106,12 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
return (<section>Device with state {accountState.deviceState} not found</section>);
}
// account not found. checking why...
if (!account) {
if (!discovery || discovery.waitingForDevice) {
if (device.connected) {
// case 1: device is connected but discovery not started yet (probably waiting for auth)
if (device.available) {
return (
<section>
@ -116,6 +119,7 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
</section>
);
} else {
// case 2: device is unavailable (created with different passphrase settings) account cannot be accessed
return (
<section>
<Notification
@ -127,6 +131,7 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
);
}
} else {
// case 3: device is disconnected
return (
<section>
<Notification
@ -138,18 +143,21 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
);
}
} else if (discovery.waitingForBackend) {
// case 4: backend is not working
return (
<section>
<Notification className="warning" title="Backend not working" />
</section>
);
} else if (discovery.completed) {
// case 5: account not found and discovery is completed
return (
<section>
<Notification className="warning" title="Account does not exist" />
</section>
);
} else {
// case 6: discovery is not completed yet
return (
<section>
<Notification className="info" title="Account is loading..." />

View File

@ -79,8 +79,7 @@ class Indicator extends Component<Props, State> {
const AccountTabs = (props: any) => {
const urlParams = props.match.params;
//const urlParams = props.match ? props.match.params : { address: '0' };
const basePath = `/device/${urlParams.device}/network/${urlParams.network}/address/${urlParams.address}`;
const basePath = `/device/${urlParams.device}/network/${urlParams.network}/account/${urlParams.account}`;
return (
<div className="account-tabs">

View File

@ -18,8 +18,7 @@ type State = {
const AccountTabs = (props: any): any => {
const urlParams = props.match.params;
//const urlParams = props.match ? props.match.params : { address: '0' };
const basePath = `/device/${urlParams.device}/network/${urlParams.network}/address/${urlParams.address}`;
const basePath = `/device/${urlParams.device}/network/${urlParams.network}/account/${urlParams.account}`;
return (
<div className="account-tabs">

View File

@ -29,36 +29,36 @@ const AccountSelection = (props: Props): ?React$Element<string> => {
const fiatRate = props.fiat.find(f => f.network === selectedCoin.network);
const deviceAddresses: Array<any> = findDeviceAccounts(accounts, selected, location.state.network);
let selectedAccounts = deviceAddresses.map((address, i) => {
// const url: string = `${baseUrl}/network/${location.state.network}/address/${i}`;
const url: string = location.pathname.replace(/address+\/([0-9]*)/, `address/${i}`);
const deviceAccounts: Array<any> = findDeviceAccounts(accounts, selected, location.state.network);
let selectedAccounts = deviceAccounts.map((account, i) => {
// const url: string = `${baseUrl}/network/${location.state.network}/account/${i}`;
const url: string = location.pathname.replace(/account+\/([0-9]*)/, `account/${i}`);
let balance: string = 'Loading...';
if (address.balance !== '') {
if (account.balance !== '') {
if (fiatRate) {
const accountBalance = new BigNumber(address.balance);
const accountBalance = new BigNumber(account.balance);
const fiat = accountBalance.times(fiatRate.value).toFixed(2);
balance = `${ address.balance } ${ selectedCoin.symbol } / $${ fiat }`;
balance = `${ account.balance } ${ selectedCoin.symbol } / $${ fiat }`;
} else {
balance = `${ address.balance } ${ selectedCoin.symbol }`;
balance = `${ account.balance } ${ selectedCoin.symbol }`;
}
}
return (
<NavLink key={i} activeClassName="selected" className="account" to={ url }>
{ `Address #${(address.index + 1 )}` }
<span>{ address.loaded ? balance : "Loading..." }</span>
{ `Account #${(account.index + 1 )}` }
<span>{ account.loaded ? balance : "Loading..." }</span>
</NavLink>
)
});
if (selectedAccounts.length < 1) {
if (selected.connected) {
const url: string = location.pathname.replace(/address+\/([0-9]*)/, `address/0`);
const url: string = location.pathname.replace(/account+\/([0-9]*)/, `account/0`);
selectedAccounts = (
<NavLink activeClassName="selected" className="account" to={ url }>
Address #1
Account #1
<span>Loading...</span>
</NavLink>
)
@ -72,17 +72,17 @@ const AccountSelection = (props: Props): ?React$Element<string> => {
if (discovery.completed) {
// TODO: add only if last one is not empty
//if (selectedAccounts.length > 0 && selectedAccounts[selectedAccounts.length - 1])
const lastAccount = deviceAddresses[deviceAddresses.length - 1];
const lastAccount = deviceAccounts[deviceAccounts.length - 1];
if (lastAccount && (new BigNumber(lastAccount.balance).greaterThan(0) || lastAccount.nonce > 0)) {
discoveryStatus = (
<div className="add-address" onClick={ props.addAddress }>
Add address
<div className="add-account" onClick={ props.addAccount }>
Add account
</div>
);
} else {
const tooltip = (
<div className="aside-tooltip-wrapper">
To add a new address, last address must have some transactions.
To add a new account, last account must have some transactions.
</div>
)
discoveryStatus = (
@ -90,17 +90,17 @@ const AccountSelection = (props: Props): ?React$Element<string> => {
arrowContent={<div className="rc-tooltip-arrow-inner"></div>}
overlay={ tooltip }
placement="top">
<div className="add-address disabled">
Add address
<div className="add-account disabled">
Add account
</div>
</Tooltip>
);
}
} else if (!selected.connected) {
} else if (!selected.connected || !selected.available) {
discoveryStatus = (
<div className="discovery-status">
Addresses could not be loaded
Accounts could not be loaded
<span>{ `Connect ${ selected.instanceLabel } device` }</span>
</div>
);

View File

@ -21,7 +21,7 @@ const CoinSelection = (props: Props): React$Element<string> => {
}
const walletCoins = config.coins.map(item => {
const url = `${ baseUrl }/network/${ item.network }/address/0`;
const url = `${ baseUrl }/network/${ item.network }/account/0`;
const className = `coin ${ item.network }`
return (
<NavLink key={ item.network } to={ url } className={ className }>

View File

@ -30,7 +30,7 @@ type StateProps = {
type DispatchProps = {
toggleDeviceDropdown: typeof toggleDeviceDropdown,
addAddress: typeof TrezorConnectActions.addAddress,
addAccount: typeof TrezorConnectActions.addAccount,
acquireDevice: typeof TrezorConnectActions.acquire,
forgetDevice: typeof TrezorConnectActions.forget,
duplicateDevice: typeof TrezorConnectActions.duplicateDevice,
@ -56,7 +56,7 @@ const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps>
return {
//onAccountSelect: bindActionCreators(AccountActions.onAccountSelect, dispatch),
toggleDeviceDropdown: bindActionCreators(toggleDeviceDropdown, dispatch),
addAddress: bindActionCreators(TrezorConnectActions.addAddress, dispatch),
addAccount: bindActionCreators(TrezorConnectActions.addAccount, dispatch),
acquireDevice: bindActionCreators(TrezorConnectActions.acquire, dispatch),
forgetDevice: bindActionCreators(TrezorConnectActions.forget, dispatch),
duplicateDevice: bindActionCreators(TrezorConnectActions.duplicateDevice, dispatch),

View File

@ -25,7 +25,7 @@ const Content = (props: Props) => {
return (
<article>
<nav>
<Route path="/device/:device/network/:network/address/:address" component={ AccountTabs } />
<Route path="/device/:device/network/:network/account/:account" component={ AccountTabs } />
<Route path="/device/:device/device-settings" component={ DeviceSettingsTabs } />
</nav>
<Notifications />

View File

@ -54,7 +54,7 @@ const _render = (props: Props, state: AccountState): React$Element<string> => {
{ deviceStatusNotification }
<h2 className={ `summary-header ${abstractAccount.network}` }>
Address #{ parseInt(abstractAccount.index) + 1 }
Account #{ parseInt(abstractAccount.index) + 1 }
<a href={ explorerLink } className="gray" target="_blank" rel="noreferrer noopener">See full transaction history</a>
</h2>

View File

@ -76,7 +76,7 @@ const complete = (state: State, action: DiscoveryCompleteAction): State => {
return newState;
}
const addressCreate = (state: State, action: AccountCreateAction): State => {
const accountCreate = (state: State, action: AccountCreateAction): State => {
const index: number = findIndex(state, action.network, action.device.state || '0');
const newState: State = [ ...state ];
newState[index].accountIndex++;
@ -159,7 +159,7 @@ export default function discovery(state: State = initialState, action: Action):
case DISCOVERY.START :
return start(state, action);
case ACCOUNT.CREATE :
return addressCreate(state, action);
return accountCreate(state, action);
case DISCOVERY.STOP :
return stop(state, action);
case DISCOVERY.COMPLETE :

View File

@ -35,11 +35,11 @@ export default (
<Route exact path="/device/:device/acquire" component={ AcquireContainer } />
<Route exact path="/device/:device/bootloader" component={ BootloaderContainer } />
<Route exact path="/device/:device/settings" component={ DeviceSettingsContainer } />
<Route exact path="/device/:device/network/:network/address/:address" component={ SummaryContainer } />
<Route path="/device/:device/network/:network/address/:address/send" component={ SendFormContainer } />
<Route path="/device/:device/network/:network/address/:address/send/override" component={ SendFormContainer } />
<Route path="/device/:device/network/:network/address/:address/receive" component={ ReceiveContainer } />
<Route path="/device/:device/network/:network/address/:address/signverify" component={ SignVerifyContainer } />
<Route exact path="/device/:device/network/:network/account/:account" component={ SummaryContainer } />
<Route path="/device/:device/network/:network/account/:account/send" component={ SendFormContainer } />
<Route path="/device/:device/network/:network/account/:account/send/override" component={ SendFormContainer } />
<Route path="/device/:device/network/:network/account/:account/receive" component={ ReceiveContainer } />
<Route path="/device/:device/network/:network/account/:account/signverify" component={ SignVerifyContainer } />
</WalletContainer>
</Route>
</Switch>

View File

@ -65,10 +65,10 @@ const validation = (api: MiddlewareAPI, params: RouterLocationState): boolean =>
const { config } = api.getState().localStorage;
const coin = config.coins.find(coin => coin.network === params.network);
if (!coin) return false;
if (!params.address) return false;
if (!params.account) return false;
}
if (params.address) {
if (params.account) {
}

View File

@ -514,7 +514,7 @@ aside {
.add-address {
.add-account {
position: relative;
padding: 8px 0 8px 20px;
cursor: pointer;