Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportingAccount: add loading indicator #2456

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions stores/UTXOsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default class UTXOsStore {
@observable public accountToImport: any | null;
@observable public start_height?: number;
@observable public addresses_to_generate: number = 50;
@observable public addresses_to_generate_progress: number = 1;
// rescan
@observable public attemptingRescan = false;
@observable public rescanErrorMsg: string;
Expand Down Expand Up @@ -206,6 +207,7 @@ export default class UTXOsStore {
}

if (data.addresses_to_generate) {
this.addresses_to_generate_progress = 1;
this.addresses_to_generate = data.addresses_to_generate || 50;
}

Expand All @@ -217,13 +219,11 @@ export default class UTXOsStore {

return BackendUtils.importAccount(data)
.then(async (response: any) => {
this.importingAccount = false;
this.error = false;
if (!data.dry_run) {
this.success = true;
if (this.start_height) {
// generate N addresses from account
for (let i = 0; i < this.addresses_to_generate; i++) {
this.addresses_to_generate_progress = i + 1;
await BackendUtils.getNewAddress({
account: this.accountToImport.account.name,
type: walletrpc.AddressType[
Expand Down Expand Up @@ -264,8 +264,14 @@ export default class UTXOsStore {
console.log('rescan err', err);
});
}

this.importingAccount = false;
this.error = false;
this.success = true;
return;
} else {
this.importingAccount = false;
this.error = false;
this.accountToImport = response;
return this.accountToImport;
}
Expand Down
68 changes: 61 additions & 7 deletions views/Accounts/ImportingAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import * as React from 'react';
import { ScrollView, StyleSheet, Text, View } from 'react-native';
import { inject, observer } from 'mobx-react';
import { StackNavigationProp } from '@react-navigation/stack';
import { LinearProgress } from 'react-native-elements';

import Button from './../../components/Button';
import Button from '../../components/Button';
import Header from '../../components/Header';
import {
SuccessMessage,
ErrorMessage
} from './../../components/SuccessErrorMessage';
import KeyValue from './../../components/KeyValue';
} from '../../components/SuccessErrorMessage';
import KeyValue from '../../components/KeyValue';
import LoadingIndicator from '../../components/LoadingIndicator';
import Screen from '../../components/Screen';

import Base64Utils from '../../utils/Base64Utils';
import { localeString } from './../../utils/LocaleUtils';
import { themeColor } from './../../utils/ThemeUtils';
import { localeString } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';

import UTXOsStore from '../../stores/UTXOsStore';

Expand All @@ -34,7 +36,15 @@ export default class ImportingAccount extends React.Component<
> {
render() {
const { navigation, UTXOsStore } = this.props;
const { accountToImport, errorMsg, success } = UTXOsStore;
const {
accountToImport,
errorMsg,
success,
importingAccount,
addresses_to_generate,
addresses_to_generate_progress,
start_height
} = UTXOsStore;
const { account, dry_run_external_addrs, dry_run_internal_addrs } =
accountToImport;
const {
Expand All @@ -54,6 +64,17 @@ export default class ImportingAccount extends React.Component<
text: localeString('views.ImportAccount.title'),
style: { color: themeColor('text') }
}}
rightComponent={
importingAccount && (
<View
style={{
alignItems: 'center'
}}
>
<LoadingIndicator size={35} />
</View>
)
}
navigation={navigation}
/>
<ScrollView style={styles.content}>
Expand All @@ -65,6 +86,38 @@ export default class ImportingAccount extends React.Component<
)}
/>
)}

{importingAccount && !success && !errorMsg && start_height && (
<View
style={{
marginTop: 15,
marginBottom: 15,
flex: 1,
flexDirection: 'row',
display: 'flex',
justifyContent: 'space-between',
minWidth: '100%'
}}
>
<LinearProgress
value={
Math.floor(
(addresses_to_generate_progress /
addresses_to_generate) *
100
) / 100
}
variant="determinate"
color={themeColor('highlight')}
trackColor={themeColor('secondaryBackground')}
style={{
flex: 1,
flexDirection: 'row'
}}
/>
</View>
)}

<KeyValue
keyValue={localeString('general.accountName')}
value={name}
Expand Down Expand Up @@ -146,7 +199,7 @@ export default class ImportingAccount extends React.Component<
{dry_run_internal_addrs.join(', ')}
</Text>
</ScrollView>
<View style={{ bottom: 10 }}>
<View style={{ marginBottom: 10 }}>
<View style={styles.button}>
<Button
title={localeString(
Expand All @@ -161,6 +214,7 @@ export default class ImportingAccount extends React.Component<
dry_run: false
}).then(() => navigation.popTo('Wallet'))
}
disabled={importingAccount}
/>
</View>
</View>
Expand Down
Loading