Skip to content

Commit

Permalink
Update wallet balance when switching between wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdbng committed Dec 4, 2017
1 parent 7d45d7b commit 2182e5c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
14 changes: 10 additions & 4 deletions src/screens/Main/components/Transactions.js
Expand Up @@ -3,8 +3,8 @@ import React, { Component } from 'react';
import { FlatList, RefreshControl } from 'react-native';
import { connect } from 'react-redux';
import { C, SHAPE, STYLE } from '../../../config';
import { TransactionService } from '../../../services';
import { updateTransactionsAction } from '../../../store/actions';
import { TransactionService, WalletService } from '../../../services';
import { updateTransactionsAction, updateWalletAction } from '../../../store/actions';
import TransactionItem from './TransactionItem';
import styles from './Transactions.style';

Expand All @@ -25,9 +25,14 @@ class Transactions extends Component {
}

async _onRefresh(wallet = this.props.wallet) {
const { updateTransactions } = this.props;
const { updateTransactions, updateWallet } = this.props;
this.setState({ refreshing: true });
updateTransactions(await TransactionService.list(wallet.id));

await Promise.all([
WalletService.state(wallet.id).then(updateWallet),
TransactionService.list(wallet.id).then(updateTransactions),
]);

this.setState({ refreshing: false });
}

Expand Down Expand Up @@ -84,6 +89,7 @@ const mapStateToProps = ({ device, transactions = [] }, { wallet = {} }) => ({

const mapDispatchToProps = dispatch => ({
updateTransactions: transactions => dispatch(updateTransactionsAction(transactions)),
updateWallet: wallet => dispatch(updateWalletAction(wallet)),
});

export default connect(mapStateToProps, mapDispatchToProps)(Transactions);
19 changes: 10 additions & 9 deletions src/screens/Main/modules/onNotification.js
Expand Up @@ -4,20 +4,21 @@ import { updateDeviceAction, updateTransactionsAction, updateWalletAction } from
export default async({
origin, title, body, data = {},
}) => {
const { device, wallet } = data;
const { device, wallet: walletId } = data;
let response;
console.log('{PUSH}', origin, title, body, origin, { device, wallet });
console.log('{PUSH}', origin, title, body, origin, { device, walletId });

if (device) {
response = await DeviceService.state(wallet);
response = await DeviceService.state();
if (response) updateDeviceAction(response);
}

if (wallet) {
response = await WalletService.state(wallet);
if (response) updateWalletAction(response);

response = await TransactionService.list(wallet);
if (response) updateTransactionsAction(response);
if (walletId) {
const [wallet, transactions] = Promise.all([
WalletService.state(walletId),
TransactionService.list(walletId),
]);
if (wallet) updateWalletAction(wallet);
if (transactions) updateTransactionsAction(transactions);
}
};

0 comments on commit 2182e5c

Please sign in to comment.