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

Improvement: update corresponding balances #601

Merged
merged 6 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions app/components/UI/TransactionEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ class TransactionEditor extends Component {
transaction: { to },
networkType
} = this.props;
if (!to) {
return undefined;
}
const address = toChecksumAddress(to);
if (networkType === 'mainnet') {
const contractMapToken = contractMap[address];
Expand Down
9 changes: 7 additions & 2 deletions app/components/Views/Approval/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,20 @@ class Approval extends Component {
TransactionController.hub.once(`${transaction.id}:finished`, transactionMeta => {
// Add to the AddressBook if it's an unkonwn address
const checksummedAddress = toChecksumAddress(transactionMeta.transaction.to);
const existingContact = addressBook.find(address => toChecksumAddress(address) === checksummedAddress);
const existingContact = addressBook.find(
({ address }) => toChecksumAddress(address) === checksummedAddress
);
if (!existingContact) {
AddressBookController.set(checksummedAddress, '');
}

if (transactionMeta.status === 'submitted') {
this.setState({ transactionHandled: true });
this.props.navigation.pop();
TransactionsNotificationManager.watchSubmittedTransaction(transactionMeta);
TransactionsNotificationManager.watchSubmittedTransaction({
...transactionMeta,
assetType: transaction.assetType
});
} else {
throw transactionMeta.error;
}
Expand Down
12 changes: 9 additions & 3 deletions app/components/Views/Send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ class Send extends Component {
* Resets gas and gasPrice of transaction, passing state to 'edit'
*/
async reset() {
const { transaction } = this.props;
const { transaction, navigation } = this.props;
const { gas, gasPrice } = await Engine.context.TransactionController.estimateGas(transaction);
this.props.setTransactionObject({
gas: hexToBN(gas),
gasPrice: hexToBN(gasPrice)
});
navigation && navigation.setParams({ mode: 'edit' });
return this.mounted && this.setState({ mode: 'edit', transactionKey: Date.now() });
}

Expand Down Expand Up @@ -369,7 +370,9 @@ class Send extends Component {

// Add to the AddressBook if it's an unkonwn address
const checksummedAddress = toChecksumAddress(transactionMeta.transaction.to);
const existingContact = addressBook.find(address => toChecksumAddress(address) === checksummedAddress);
const existingContact = addressBook.find(
({ address }) => toChecksumAddress(address) === checksummedAddress
);
if (!existingContact) {
AddressBookController.set(checksummedAddress, '');
}
Expand All @@ -384,7 +387,10 @@ class Send extends Component {
this.setState({ transactionConfirmed: false, transactionSubmitted: true });
this.props.navigation.pop();
InteractionManager.runAfterInteractions(() => {
TransactionsNotificationManager.watchSubmittedTransaction(transactionMeta);
TransactionsNotificationManager.watchSubmittedTransaction({
...transactionMeta,
assetType: transaction.assetType
});
});
} catch (error) {
Alert.alert('Transaction error', error && error.message, [{ text: 'OK' }]);
Expand Down
21 changes: 14 additions & 7 deletions app/core/TransactionsNotificationManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ class TransactionsNotificationManager {
*/
watchSubmittedTransaction(transaction) {
const { TransactionController } = Engine.context;

// First we show the pending tx notification
this._showNotification({
type: 'pending',
Expand Down Expand Up @@ -200,13 +199,21 @@ class TransactionsNotificationManager {
this._removeListeners(transactionMeta.id);

const { TokenBalancesController, AssetsDetectionController, AccountTrackerController } = Engine.context;
// Detect assets and tokens and account balances
// account balances for ETH txs
// Detect assets and tokens for ERC20 txs
// Detect assets for ERC721 txs
// right after a transaction was confirmed
Promise.all([
AccountTrackerController.poll(),
TokenBalancesController.poll(),
AssetsDetectionController.poll()
]);
const pollPromises = [AccountTrackerController.poll()];
switch (transaction.assetType) {
case 'ERC20': {
pollPromises.push(...[TokenBalancesController.poll(), AssetsDetectionController.poll()]);
break;
}
case 'ERC721':
pollPromises.push(AssetsDetectionController.poll());
break;
}
Promise.all(pollPromises);

Platform.OS === 'ios' &&
setTimeout(() => {
Expand Down