mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-21 14:34:55 +01:00
Development (#96)
* ADD: Wallet Details screen * FIX: Fixed receive and send calls * FIX: improve splash image and colors * FIX: Modified Encrypted Storage prompt to avoid cancellation * FIX: improved tx refresh strategy * FIX: HDBread tx confirmations calculation
This commit is contained in:
parent
552d12c660
commit
65be52ed3d
23 changed files with 798 additions and 444 deletions
|
@ -15,7 +15,7 @@ async function startAndDecrypt(retry) {
|
|||
let password = false;
|
||||
if (await BlueApp.storageIsEncrypted()) {
|
||||
do {
|
||||
password = await prompt((retry && loc._.bad_password) || loc._.enter_password, loc._.storage_is_encrypted);
|
||||
password = await prompt((retry && loc._.bad_password) || loc._.enter_password, loc._.storage_is_encrypted, false);
|
||||
} while (!password);
|
||||
}
|
||||
let success = await BlueApp.loadFromDisk(password);
|
||||
|
|
|
@ -883,9 +883,9 @@ export class NewWalletPannel extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
let sliderWidth = width * 1;
|
||||
let itemWidth = width * 0.82;
|
||||
let sliderHeight = 190;
|
||||
const sliderWidth = width * 1;
|
||||
const itemWidth = width * 0.82;
|
||||
const sliderHeight = 190;
|
||||
|
||||
export class WalletsCarousel extends Component {
|
||||
constructor(props) {
|
||||
|
@ -1023,25 +1023,24 @@ export class WalletsCarousel extends Component {
|
|||
|
||||
render() {
|
||||
return (
|
||||
<View style={{ height: sliderHeight }}>
|
||||
<Carousel
|
||||
{...this.props}
|
||||
ref={c => {
|
||||
WalletsCarousel.carousel = c;
|
||||
}}
|
||||
renderItem={this._renderItem}
|
||||
sliderWidth={sliderWidth}
|
||||
itemWidth={itemWidth}
|
||||
inactiveSlideScale={1}
|
||||
inactiveSlideOpacity={0.7}
|
||||
onSnapToItem={index => {
|
||||
if (this.onSnapToItem) {
|
||||
this.onSnapToItem(index);
|
||||
}
|
||||
console.log('snapped to card #', index);
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
<Carousel
|
||||
{...this.props}
|
||||
ref={c => {
|
||||
WalletsCarousel.carousel = c;
|
||||
}}
|
||||
renderItem={this._renderItem}
|
||||
sliderWidth={sliderWidth}
|
||||
sliderHeight={sliderHeight}
|
||||
itemWidth={itemWidth}
|
||||
inactiveSlideScale={1}
|
||||
inactiveSlideOpacity={0.7}
|
||||
onSnapToItem={index => {
|
||||
if (this.onSnapToItem) {
|
||||
this.onSnapToItem(index);
|
||||
}
|
||||
console.log('snapped to card #', index);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,6 +220,9 @@ it('HD breadwallet works', async function() {
|
|||
await hdBread.fetchTransactions();
|
||||
assert.ok(hdBread._lastTxFetch > 0);
|
||||
assert.equal(hdBread.transactions.length, 177);
|
||||
for (let tx of hdBread.getTransactions()) {
|
||||
assert.ok(tx.confirmations);
|
||||
}
|
||||
|
||||
assert.equal(hdBread.next_free_address_index, 10);
|
||||
assert.equal(hdBread.next_free_change_address_index, 118);
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import { createStackNavigator } from 'react-navigation';
|
||||
|
||||
import wallets from './screen/wallets';
|
||||
import Settings from './screen/settings/settings';
|
||||
import About from './screen/settings/about';
|
||||
import Language from './screen/settings/language';
|
||||
import EncryptStorage from './screen/settings/encryptStorage';
|
||||
import WalletsList from './screen/wallets/list';
|
||||
import WalletTransactions from './screen/wallets/transactions';
|
||||
import AddWallet from './screen/wallets/add';
|
||||
import ImportWallet from './screen/wallets/import';
|
||||
import WalletDetails from './screen/wallets/details';
|
||||
|
@ -20,15 +25,48 @@ import sendCreate from './screen/send/create';
|
|||
import ManageFunds from './screen/lnd/manageFunds';
|
||||
import ScanLndInvoice from './screen/lnd/scanLndInvoice';
|
||||
|
||||
const WalletsStackNavigator = createStackNavigator({
|
||||
Wallets: {
|
||||
screen: WalletsList,
|
||||
path: 'wallets',
|
||||
},
|
||||
Settings: {
|
||||
screen: Settings,
|
||||
path: 'Settings',
|
||||
navigationOptions: {
|
||||
headerStyle: {
|
||||
backgroundColor: '#FFFFFF',
|
||||
borderBottomWidth: 0,
|
||||
},
|
||||
headerTintColor: '#0c2550',
|
||||
},
|
||||
},
|
||||
About: {
|
||||
screen: About,
|
||||
path: 'About',
|
||||
},
|
||||
Language: {
|
||||
screen: Language,
|
||||
path: 'Language',
|
||||
},
|
||||
EncryptStorage: {
|
||||
screen: EncryptStorage,
|
||||
path: 'EncryptStorage',
|
||||
},
|
||||
});
|
||||
|
||||
const Tabs = createStackNavigator(
|
||||
{
|
||||
Wallets: {
|
||||
screen: wallets,
|
||||
screen: WalletsStackNavigator,
|
||||
path: 'wallets',
|
||||
navigationOptions: {
|
||||
header: null,
|
||||
},
|
||||
},
|
||||
WalletTransactions: {
|
||||
screen: WalletTransactions,
|
||||
},
|
||||
AddWallet: {
|
||||
screen: AddWallet,
|
||||
},
|
||||
|
@ -44,7 +82,6 @@ const Tabs = createStackNavigator(
|
|||
WalletExport: {
|
||||
screen: WalletExport,
|
||||
},
|
||||
|
||||
//
|
||||
|
||||
TransactionDetails: {
|
||||
|
|
|
@ -239,6 +239,11 @@ export class AbstractHDWallet extends LegacyWallet {
|
|||
break;
|
||||
}
|
||||
|
||||
let latestBlock = false;
|
||||
if (response.body.info && response.body.info.latest_block) {
|
||||
latestBlock = response.body.info.latest_block.height;
|
||||
}
|
||||
|
||||
this._lastTxFetch = +new Date();
|
||||
|
||||
// processing TXs and adding to internal memory
|
||||
|
@ -291,6 +296,9 @@ export class AbstractHDWallet extends LegacyWallet {
|
|||
}
|
||||
|
||||
tx.value = value; // new BigNumber(value).div(100000000).toString() * 1;
|
||||
if (!tx.confirmations && latestBlock) {
|
||||
tx.confirmations = latestBlock - tx.block_height;
|
||||
}
|
||||
|
||||
this.transactions.push(tx);
|
||||
}
|
||||
|
|
|
@ -312,7 +312,14 @@ export class AppStorage {
|
|||
for (let wallet of this.wallets) {
|
||||
txs = txs.concat(wallet.getTransactions());
|
||||
}
|
||||
return txs;
|
||||
|
||||
for (let t of txs) {
|
||||
t.sort_ts = +new Date(t.received);
|
||||
}
|
||||
|
||||
return txs.sort(function(a, b) {
|
||||
return b.sort_ts > a.sort_ts;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,11 @@ export class LightningCustodianWallet extends LegacyWallet {
|
|||
this.info_raw = false;
|
||||
}
|
||||
|
||||
allowSend() {
|
||||
console.log(this.getBalance(), this.getBalance() > 0);
|
||||
return this.getBalance() > 0;
|
||||
}
|
||||
|
||||
getAddress() {
|
||||
return '';
|
||||
}
|
||||
|
|
10
events.js
10
events.js
|
@ -20,9 +20,19 @@ function EV(eventName, arg) {
|
|||
}
|
||||
|
||||
EV.enum = {
|
||||
// emitted when local wallet created or deleted, so one must redraw wallets carousel
|
||||
WALLETS_COUNT_CHANGED: 'WALLETS_COUNT_CHANGED',
|
||||
|
||||
// emitted when local wallet (usually current wallet) has changed number of transactions
|
||||
// so one must redraw main screen transactions list and WalletTransactions screen tx list
|
||||
TRANSACTIONS_COUNT_CHANGED: 'TRANSACTIONS_COUNT_CHANGED',
|
||||
|
||||
// emitted when we know for sure that on remote server tx list
|
||||
// changed (usually for current wallet)
|
||||
REMOTE_TRANSACTIONS_COUNT_CHANGED: 'REMOTE_TRANSACTIONS_COUNT_CHANGED',
|
||||
|
||||
CREATE_TRANSACTION_NEW_DESTINATION_ADDRESS: 'CREATE_TRANSACTION_NEW_DESTINATION_ADDRESS',
|
||||
|
||||
// RECEIVE_ADDRESS_CHANGED: 'RECEIVE_ADDRESS_CHANGED',
|
||||
};
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ module.exports = {
|
|||
never: 'never',
|
||||
},
|
||||
wallets: {
|
||||
options: 'options',
|
||||
list: {
|
||||
app_name: 'Blue Wallet',
|
||||
title: 'wallets',
|
||||
|
|
|
@ -10,6 +10,7 @@ module.exports = {
|
|||
never: 'nunca',
|
||||
},
|
||||
wallets: {
|
||||
options: 'opciones',
|
||||
list: {
|
||||
app_name: 'Blue Wallet',
|
||||
title: 'carteras',
|
||||
|
|
|
@ -10,6 +10,7 @@ module.exports = {
|
|||
never: 'nunca...',
|
||||
},
|
||||
wallets: {
|
||||
options: 'options',
|
||||
list: {
|
||||
tabBarLabel: 'Wallets',
|
||||
app_name: 'Blue Wallet',
|
||||
|
|
|
@ -10,6 +10,7 @@ module.exports = {
|
|||
never: 'never',
|
||||
},
|
||||
wallets: {
|
||||
options: 'options',
|
||||
list: {
|
||||
app_name: 'Blue Wallet',
|
||||
title: 'wallets',
|
||||
|
|
|
@ -10,6 +10,7 @@ module.exports = {
|
|||
never: 'никогда',
|
||||
},
|
||||
wallets: {
|
||||
options: 'options',
|
||||
list: {
|
||||
app_name: 'BlueWallet',
|
||||
title: 'кошельки',
|
||||
|
|
|
@ -10,6 +10,7 @@ module.exports = {
|
|||
never: 'ніколи',
|
||||
},
|
||||
wallets: {
|
||||
options: 'options',
|
||||
list: {
|
||||
app_name: 'BlueWallet',
|
||||
title: 'гаманці',
|
||||
|
|
47
prompt.js
47
prompt.js
|
@ -1,27 +1,34 @@
|
|||
import { AlertIOS } from 'react-native';
|
||||
|
||||
module.exports = (title, text) => {
|
||||
module.exports = (title, text, isCancelable = true) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
AlertIOS.prompt(
|
||||
title,
|
||||
text,
|
||||
[
|
||||
{
|
||||
text: 'Cancel',
|
||||
onPress: () => {
|
||||
reject(Error('Cancel Pressed'));
|
||||
const buttons = isCancelable
|
||||
? [
|
||||
{
|
||||
text: 'Cancel',
|
||||
onPress: () => {
|
||||
reject(Error('Cancel Pressed'));
|
||||
},
|
||||
style: 'cancel',
|
||||
},
|
||||
style: 'cancel',
|
||||
},
|
||||
{
|
||||
text: 'OK',
|
||||
onPress: password => {
|
||||
console.log('OK Pressed, password: ' + password);
|
||||
resolve(password);
|
||||
{
|
||||
text: 'OK',
|
||||
onPress: password => {
|
||||
console.log('OK Pressed, password: ' + password);
|
||||
resolve(password);
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
'secure-text',
|
||||
);
|
||||
]
|
||||
: [
|
||||
{
|
||||
text: 'OK',
|
||||
onPress: password => {
|
||||
console.log('OK Pressed, password: ' + password);
|
||||
resolve(password);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
AlertIOS.prompt(title, text, buttons, 'secure-text');
|
||||
});
|
||||
};
|
||||
|
|
|
@ -130,7 +130,7 @@ export default class ScanLndInvoice extends React.Component {
|
|||
}
|
||||
|
||||
console.log('payInvoice took', (end - start) / 1000, 'sec');
|
||||
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
|
||||
EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED); // someone should fetch txs
|
||||
|
||||
alert('Success');
|
||||
this.props.navigation.goBack();
|
||||
|
|
|
@ -126,7 +126,7 @@ export default class SendCreate extends Component {
|
|||
broadcastSuccessMessage: '',
|
||||
});
|
||||
} else {
|
||||
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
|
||||
EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED); // someone should fetch txs
|
||||
this.setState({ broadcastErrorMessage: '' });
|
||||
this.setState({
|
||||
broadcastSuccessMessage: 'Success! TXID: ' + JSON.stringify(result.result),
|
||||
|
|
|
@ -68,7 +68,7 @@ export default class EncryptStorage extends Component {
|
|||
this.setState({ isLoading: true });
|
||||
let p1 = await prompt(loc.settings.password, loc.settings.password_explain).catch(() => {
|
||||
this.setState({ isLoading: false });
|
||||
this.props.navigation.goBack();
|
||||
p1 = undefined;
|
||||
});
|
||||
if (!p1) {
|
||||
this.setState({ isLoading: false });
|
||||
|
@ -76,7 +76,6 @@ export default class EncryptStorage extends Component {
|
|||
}
|
||||
let p2 = await prompt(loc.settings.password, loc.settings.retype_password).catch(() => {
|
||||
this.setState({ isLoading: false });
|
||||
this.props.navigation.goBack();
|
||||
});
|
||||
if (p1 === p2) {
|
||||
await BlueApp.encryptStorage(p1);
|
||||
|
|
|
@ -8,11 +8,13 @@ let loc = require('../../loc');
|
|||
|
||||
export default class Settings extends Component {
|
||||
static navigationOptions = {
|
||||
headerStyle: {
|
||||
backgroundColor: '#FFFFFF',
|
||||
borderBottomWidth: 0,
|
||||
navigationOptions: {
|
||||
headerStyle: {
|
||||
backgroundColor: '#FFFFFF',
|
||||
borderBottomWidth: 0,
|
||||
},
|
||||
headerTintColor: '#0c2550',
|
||||
},
|
||||
headerTintColor: '#0c2550',
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
import { createStackNavigator } from 'react-navigation';
|
||||
import WalletsList from './wallets/list';
|
||||
import Settings from '../screen/settings/settings';
|
||||
import About from '../screen/settings/about';
|
||||
import Language from '../screen/settings/language';
|
||||
import EncryptStorage from '../screen/settings/encryptStorage';
|
||||
|
||||
const WalletsNavigator = createStackNavigator({
|
||||
WalletsList: {
|
||||
screen: WalletsList,
|
||||
},
|
||||
Settings: {
|
||||
screen: Settings,
|
||||
path: 'Settings',
|
||||
},
|
||||
About: {
|
||||
screen: About,
|
||||
path: 'About',
|
||||
},
|
||||
Language: {
|
||||
screen: Language,
|
||||
path: 'Language',
|
||||
},
|
||||
EncryptStorage: {
|
||||
screen: EncryptStorage,
|
||||
path: 'EncryptStorage',
|
||||
},
|
||||
});
|
||||
|
||||
export default WalletsNavigator;
|
|
@ -120,7 +120,7 @@ export default class WalletDetails extends Component {
|
|||
await BlueApp.saveToDisk();
|
||||
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED);
|
||||
EV(EV.enum.WALLETS_COUNT_CHANGED);
|
||||
this.props.navigation.goBack();
|
||||
this.props.navigation.navigate('Wallets');
|
||||
}}
|
||||
title={loc.wallets.details.yes_delete}
|
||||
/>
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
import React, { Component } from 'react';
|
||||
import { View, TouchableOpacity, Text, FlatList, RefreshControl, LayoutAnimation } from 'react-native';
|
||||
import { View, TouchableOpacity, Text, FlatList, RefreshControl, LayoutAnimation, ScrollView } from 'react-native';
|
||||
import {
|
||||
BlueText,
|
||||
BlueTransactionOnchainIcon,
|
||||
ManageFundsBigButton,
|
||||
BlueLoading,
|
||||
SafeBlueArea,
|
||||
WalletsCarousel,
|
||||
|
@ -11,15 +9,12 @@ import {
|
|||
BlueTransactionOutgoingIcon,
|
||||
BlueTransactionPendingIcon,
|
||||
BlueTransactionOffchainIcon,
|
||||
BlueSendButtonIcon,
|
||||
BlueReceiveButtonIcon,
|
||||
BlueList,
|
||||
BlueListItem,
|
||||
BlueHeaderDefaultMain,
|
||||
} from '../../BlueComponents';
|
||||
import { Icon } from 'react-native-elements';
|
||||
import PropTypes from 'prop-types';
|
||||
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet';
|
||||
const BigNumber = require('bignumber.js');
|
||||
let EV = require('../../events');
|
||||
let A = require('../../analytics');
|
||||
|
@ -63,17 +58,32 @@ export default class WalletsList extends Component {
|
|||
isLoading: true,
|
||||
};
|
||||
EV(EV.enum.WALLETS_COUNT_CHANGED, this.refreshFunction.bind(this));
|
||||
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED, this.refreshTransactions.bind(this));
|
||||
|
||||
// here, when we receive TRANSACTIONS_COUNT_CHANGED we do not query
|
||||
// remote server, we just redraw the screen
|
||||
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED, this.refreshFunction.bind(this));
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
this.refreshFunction();
|
||||
} // end of componendDidMount
|
||||
|
||||
LayoutAnimation.configureNext(customLayoutSpringAnimation);
|
||||
this.setState({
|
||||
isLoading: false,
|
||||
dataSource: BlueApp.getTransactions(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully fetches TXs and balance for lastSnappedTo (i.e. current) wallet
|
||||
*/
|
||||
refreshTransactions() {
|
||||
if (!(this.lastSnappedTo < BlueApp.getWallets().length)) {
|
||||
// last card, nop
|
||||
console.log('last card, nop');
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState(
|
||||
{
|
||||
isTransactionsLoading: true,
|
||||
|
@ -88,7 +98,7 @@ export default class WalletsList extends Component {
|
|||
let start = +new Date();
|
||||
await BlueApp.fetchWalletTransactions(that.lastSnappedTo || 0);
|
||||
let end = +new Date();
|
||||
console.log('tx took', (end - start) / 1000, 'sec');
|
||||
console.log('fetch tx took', (end - start) / 1000, 'sec');
|
||||
} catch (err) {
|
||||
noErr = false;
|
||||
console.warn(err);
|
||||
|
@ -109,38 +119,11 @@ export default class WalletsList extends Component {
|
|||
A(A.ENUM.GOT_NONZERO_BALANCE);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
console.log('refreshFunction()');
|
||||
let showSend = false;
|
||||
let showReceive = false;
|
||||
let showManageFundsBig = false;
|
||||
let showManageFundsSmallButton = false;
|
||||
let wallets = BlueApp.getWallets();
|
||||
let wallet = wallets[this.lastSnappedTo || 0];
|
||||
if (wallet) {
|
||||
showSend = wallet.allowSend();
|
||||
showReceive = wallet.allowReceive();
|
||||
}
|
||||
|
||||
if (wallet && wallet.type === new LightningCustodianWallet().type && !showSend) {
|
||||
showManageFundsBig = true;
|
||||
showManageFundsSmallButton = false;
|
||||
}
|
||||
|
||||
if (wallet && wallet.type === new LightningCustodianWallet().type && wallet.getBalance() > 0) {
|
||||
showManageFundsSmallButton = true;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
isLoading: false,
|
||||
isTransactionsLoading: false,
|
||||
showReceiveButton: showReceive,
|
||||
showSendButton: showSend,
|
||||
showManageFundsBigButton: showManageFundsBig,
|
||||
showManageFundsSmallButton,
|
||||
dataSource: BlueApp.getTransactions(this.lastSnappedTo || 0),
|
||||
});
|
||||
}, 1);
|
||||
this.setState({
|
||||
isLoading: false,
|
||||
isTransactionsLoading: false,
|
||||
dataSource: BlueApp.getTransactions(),
|
||||
});
|
||||
}
|
||||
|
||||
txMemo(hash) {
|
||||
|
@ -151,12 +134,11 @@ export default class WalletsList extends Component {
|
|||
}
|
||||
|
||||
handleClick(index) {
|
||||
console.log('cick', index);
|
||||
console.log('click', index);
|
||||
let wallet = BlueApp.wallets[index];
|
||||
if (wallet) {
|
||||
this.props.navigation.navigate('WalletDetails', {
|
||||
address: wallet.getAddress(), // either one of them will work
|
||||
secret: wallet.getSecret(),
|
||||
this.props.navigation.navigate('WalletTransactions', {
|
||||
wallet: wallet,
|
||||
});
|
||||
} else {
|
||||
// if its out of index - this must be last card with incentive to create wallet
|
||||
|
@ -168,63 +150,15 @@ export default class WalletsList extends Component {
|
|||
console.log('onSnapToItem', index);
|
||||
this.lastSnappedTo = index;
|
||||
LayoutAnimation.configureNext(customLayoutSpringAnimation);
|
||||
this.setState({
|
||||
isLoading: false,
|
||||
showReceiveButton: false,
|
||||
showManageFundsBigButton: false,
|
||||
showManageFundsSmallButton: false,
|
||||
showSendButton: false,
|
||||
dataSource: BlueApp.getTransactions(index),
|
||||
});
|
||||
|
||||
if (index < BlueApp.getWallets().length) {
|
||||
// do not show for last card
|
||||
|
||||
let showSend = false;
|
||||
let showReceive = false;
|
||||
let showManageFundsBig = false;
|
||||
let wallets = BlueApp.getWallets();
|
||||
let wallet = wallets[this.lastSnappedTo || 0];
|
||||
if (wallet) {
|
||||
showSend = wallet.allowSend();
|
||||
showReceive = wallet.allowReceive();
|
||||
}
|
||||
console.log({ showSend });
|
||||
let showManageFundsSmallButton = true;
|
||||
if (wallet && wallet.type === new LightningCustodianWallet().type && !showSend) {
|
||||
showManageFundsBig = true;
|
||||
showManageFundsSmallButton = false;
|
||||
}
|
||||
|
||||
if (wallet && wallet.type === new LightningCustodianWallet().type) {
|
||||
} else {
|
||||
showManageFundsSmallButton = false;
|
||||
}
|
||||
|
||||
console.log({ showManageFundsBig });
|
||||
|
||||
LayoutAnimation.configureNext(customLayoutSpringAnimation);
|
||||
this.setState({
|
||||
showReceiveButton: showReceive,
|
||||
showManageFundsBigButton: showManageFundsBig,
|
||||
showManageFundsSmallButton,
|
||||
showSendButton: showSend,
|
||||
});
|
||||
// not the last
|
||||
}
|
||||
|
||||
// now, lets try to fetch balance and txs for this wallet in case it has changed
|
||||
this.lazyRefreshWallet(index);
|
||||
}
|
||||
|
||||
isLightning() {
|
||||
let w = BlueApp.getWallets()[this.lastSnappedTo || 0];
|
||||
if (w && w.type === new LightningCustodianWallet().type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides whether wallet with such index shoud be refreshed,
|
||||
* refreshes if yes and redraws the screen
|
||||
|
@ -237,6 +171,7 @@ export default class WalletsList extends Component {
|
|||
if (!wallets[index]) {
|
||||
return;
|
||||
}
|
||||
|
||||
let oldBalance = wallets[index].getBalance();
|
||||
let noErr = true;
|
||||
let didRefresh = false;
|
||||
|
@ -275,6 +210,24 @@ export default class WalletsList extends Component {
|
|||
|
||||
_keyExtractor = (item, index) => index.toString();
|
||||
|
||||
renderListHeaderComponent = () => {
|
||||
return (
|
||||
<View>
|
||||
<Text
|
||||
style={{
|
||||
paddingLeft: 15,
|
||||
fontWeight: 'bold',
|
||||
fontSize: 24,
|
||||
marginVertical: 8,
|
||||
color: BlueApp.settings.foregroundColor,
|
||||
}}
|
||||
>
|
||||
{loc.transactions.list.title}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { navigate } = this.props.navigation;
|
||||
|
||||
|
@ -283,275 +236,107 @@ export default class WalletsList extends Component {
|
|||
}
|
||||
|
||||
return (
|
||||
<SafeBlueArea>
|
||||
<BlueHeaderDefaultMain leftText={loc.wallets.list.title} onNewWalletPress={() => this.props.navigation.navigate('AddWallet')} />
|
||||
<WalletsCarousel
|
||||
data={BlueApp.getWallets().concat(false)}
|
||||
handleClick={index => {
|
||||
this.handleClick(index);
|
||||
}}
|
||||
onSnapToItem={index => {
|
||||
this.onSnapToItem(index);
|
||||
}}
|
||||
/>
|
||||
<SafeBlueArea style={{ flex: 1, backgroundColor: '#FFFFFF' }}>
|
||||
<ScrollView
|
||||
refreshControl={<RefreshControl onRefresh={() => this.refreshTransactions()} refreshing={this.state.isTransactionsLoading} />}
|
||||
>
|
||||
<BlueHeaderDefaultMain leftText={loc.wallets.list.title} onNewWalletPress={() => this.props.navigation.navigate('AddWallet')} />
|
||||
<WalletsCarousel
|
||||
data={BlueApp.getWallets().concat(false)}
|
||||
handleClick={index => {
|
||||
this.handleClick(index);
|
||||
}}
|
||||
onSnapToItem={index => {
|
||||
this.onSnapToItem(index);
|
||||
}}
|
||||
/>
|
||||
<BlueList>
|
||||
<FlatList
|
||||
ListHeaderComponent={this.renderListHeaderComponent}
|
||||
data={this.state.dataSource}
|
||||
extraData={this.state.dataSource}
|
||||
keyExtractor={this._keyExtractor}
|
||||
renderItem={rowData => {
|
||||
return (
|
||||
<BlueListItem
|
||||
avatar={(() => {
|
||||
// is it lightning refill tx?
|
||||
if (rowData.item.category === 'receive' && rowData.item.confirmations < 3) {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionPendingIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
{(() => {
|
||||
if (this.state.showManageFundsSmallButton) {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
style={{ alignSelf: 'flex-end', right: 10, flexDirection: 'row' }}
|
||||
onPress={() => {
|
||||
let walletIndex = this.lastSnappedTo || 0;
|
||||
if (rowData.item.type && rowData.item.type === 'bitcoind_tx') {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionOnchainIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
if (rowData.item.type === 'paid_invoice') {
|
||||
// is it lightning offchain payment?
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionOffchainIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
let c = 0;
|
||||
for (let w of BlueApp.getWallets()) {
|
||||
if (c++ === walletIndex) {
|
||||
console.log('navigating to secret ', w.getSecret());
|
||||
navigate('ManageFunds', { fromSecret: w.getSecret() });
|
||||
if (!rowData.item.confirmations) {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionPendingIcon />
|
||||
</View>
|
||||
);
|
||||
} else if (rowData.item.value < 0) {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionOutgoingIcon />
|
||||
</View>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionIncommingIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
title={loc.transactionTimeToReadable(rowData.item.received)}
|
||||
subtitle={
|
||||
(rowData.item.confirmations < 7 ? loc.transactions.list.conf + ': ' + rowData.item.confirmations + ' ' : '') +
|
||||
this.txMemo(rowData.item.hash) +
|
||||
(rowData.item.memo || '')
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<BlueText style={{ fontWeight: '600', fontSize: 16 }}>{loc.lnd.title}</BlueText>
|
||||
<Icon
|
||||
style={{ position: 'relative' }}
|
||||
name="link"
|
||||
type="font-awesome"
|
||||
size={14}
|
||||
color={BlueApp.settings.foregroundColor}
|
||||
iconStyle={{ left: 5, transform: [{ rotate: '90deg' }] }}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
|
||||
{(() => {
|
||||
return (
|
||||
<View style={{ flex: 1 }}>
|
||||
<View style={{ flexDirection: 'row', height: 50 }}>
|
||||
<Text
|
||||
style={{
|
||||
paddingLeft: 15,
|
||||
paddingTop: 15,
|
||||
fontWeight: 'bold',
|
||||
fontSize: 24,
|
||||
color: BlueApp.settings.foregroundColor,
|
||||
}}
|
||||
>
|
||||
{loc.transactions.list.title}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
<View
|
||||
style={{
|
||||
top: 20,
|
||||
}}
|
||||
>
|
||||
{(() => {
|
||||
if (BlueApp.getTransactions(this.lastSnappedTo || 0).length === 0) {
|
||||
return (
|
||||
<View>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 18,
|
||||
color: '#9aa0aa',
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
{(this.isLightning() &&
|
||||
'Lightning wallet should be used for your daily\ntransactions. Fees are unfairly cheap and\nspeed is blazing fast.') ||
|
||||
loc.wallets.list.empty_txs1}
|
||||
</Text>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 18,
|
||||
color: '#9aa0aa',
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
{(this.isLightning() && '\nTo start using it tap on "manage funds"\nand topup your balance') ||
|
||||
loc.wallets.list.empty_txs2}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
</View>
|
||||
|
||||
<View style={{ flex: 1 }}>
|
||||
<BlueList>
|
||||
<FlatList
|
||||
refreshControl={
|
||||
<RefreshControl onRefresh={() => this.refreshTransactions()} refreshing={this.state.isTransactionsLoading} />
|
||||
}
|
||||
data={this.state.dataSource}
|
||||
extraData={this.state.dataSource}
|
||||
keyExtractor={this._keyExtractor}
|
||||
renderItem={rowData => {
|
||||
return (
|
||||
<BlueListItem
|
||||
avatar={(() => {
|
||||
// is it lightning refill tx?
|
||||
if (rowData.item.category === 'receive' && rowData.item.confirmations < 3) {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionPendingIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (rowData.item.type && rowData.item.type === 'bitcoind_tx') {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionOnchainIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
if (rowData.item.type === 'paid_invoice') {
|
||||
// is it lightning offchain payment?
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionOffchainIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!rowData.item.confirmations) {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionPendingIcon />
|
||||
</View>
|
||||
);
|
||||
} else if (rowData.item.value < 0) {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionOutgoingIcon />
|
||||
</View>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionIncommingIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
title={loc.transactionTimeToReadable(rowData.item.received)}
|
||||
subtitle={
|
||||
(rowData.item.confirmations < 7 ? loc.transactions.list.conf + ': ' + rowData.item.confirmations + ' ' : '') +
|
||||
this.txMemo(rowData.item.hash) +
|
||||
(rowData.item.memo || '')
|
||||
}
|
||||
onPress={() => {
|
||||
if (rowData.item.hash) {
|
||||
navigate('TransactionDetails', {
|
||||
hash: rowData.item.hash,
|
||||
});
|
||||
}
|
||||
}}
|
||||
badge={{
|
||||
value: 3,
|
||||
textStyle: { color: 'orange' },
|
||||
containerStyle: { marginTop: 0 },
|
||||
}}
|
||||
hideChevron
|
||||
rightTitle={new BigNumber((rowData.item.value && rowData.item.value) || 0).div(100000000).toString()}
|
||||
rightTitleStyle={{
|
||||
fontWeight: '600',
|
||||
fontSize: 16,
|
||||
color: rowData.item.value / 100000000 < 0 ? BlueApp.settings.foregroundColor : '#37c0a1',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
onPress={() => {
|
||||
if (rowData.item.hash) {
|
||||
navigate('TransactionDetails', {
|
||||
hash: rowData.item.hash,
|
||||
});
|
||||
}
|
||||
}}
|
||||
badge={{
|
||||
value: 3,
|
||||
textStyle: { color: 'orange' },
|
||||
containerStyle: { marginTop: 0 },
|
||||
}}
|
||||
hideChevron
|
||||
rightTitle={new BigNumber((rowData.item.value && rowData.item.value) || 0).div(100000000).toString()}
|
||||
rightTitleStyle={{
|
||||
fontWeight: '600',
|
||||
fontSize: 16,
|
||||
color: rowData.item.value / 100000000 < 0 ? BlueApp.settings.foregroundColor : '#37c0a1',
|
||||
}}
|
||||
/>
|
||||
</BlueList>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
})()}
|
||||
<View
|
||||
style={{
|
||||
flexDirection: 'row',
|
||||
alignSelf: 'center',
|
||||
backgroundColor: 'transparent',
|
||||
position: 'absolute',
|
||||
bottom: 30,
|
||||
borderRadius: 15,
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
{(() => {
|
||||
if (this.state.showReceiveButton) {
|
||||
return (
|
||||
<BlueReceiveButtonIcon
|
||||
onPress={() => {
|
||||
let start = +new Date();
|
||||
let walletIndex = this.lastSnappedTo || 0;
|
||||
console.log('receiving on #', walletIndex);
|
||||
|
||||
let c = 0;
|
||||
for (let w of BlueApp.getWallets()) {
|
||||
if (c++ === walletIndex) {
|
||||
console.log('found receiving address, secret=', w.getAddress(), ',', w.getSecret());
|
||||
navigate('ReceiveDetails', { address: w.getAddress(), secret: w.getSecret() });
|
||||
if (w.getAddress()) {
|
||||
// EV(EV.enum.RECEIVE_ADDRESS_CHANGED, w.getAddress());
|
||||
}
|
||||
}
|
||||
}
|
||||
let end = +new Date();
|
||||
console.log('took', (end - start) / 1000, 'sec');
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
|
||||
{(() => {
|
||||
if (this.state.showSendButton) {
|
||||
return (
|
||||
<BlueSendButtonIcon
|
||||
onPress={() => {
|
||||
let walletIndex = this.lastSnappedTo || 0;
|
||||
|
||||
let c = 0;
|
||||
for (let w of BlueApp.getWallets()) {
|
||||
if (c++ === walletIndex) {
|
||||
if (w.type === new LightningCustodianWallet().type) {
|
||||
navigate('ScanLndInvoice', { fromSecret: w.getSecret() });
|
||||
} else {
|
||||
navigate('SendDetails', { fromAddress: w.getAddress(), fromSecret: w.getSecret() });
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
|
||||
{(() => {
|
||||
if (this.state.showManageFundsBigButton) {
|
||||
return (
|
||||
<ManageFundsBigButton
|
||||
onPress={() => {
|
||||
let walletIndex = this.lastSnappedTo || 0;
|
||||
|
||||
let c = 0;
|
||||
for (let w of BlueApp.getWallets()) {
|
||||
if (c++ === walletIndex) {
|
||||
console.log('navigating to secret ', w.getSecret());
|
||||
navigate('ManageFunds', { fromSecret: w.getSecret() });
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
</View>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</BlueList>
|
||||
); })()}
|
||||
</ScrollView>
|
||||
</SafeBlueArea>
|
||||
);
|
||||
}
|
||||
|
|
516
screen/wallets/transactions.js
Normal file
516
screen/wallets/transactions.js
Normal file
|
@ -0,0 +1,516 @@
|
|||
import React, { Component } from 'react';
|
||||
import { Text, Dimensions, Button, View, Image, FlatList, RefreshControl, TouchableOpacity } from 'react-native';
|
||||
import PropTypes from 'prop-types';
|
||||
import { LinearGradient } from 'expo';
|
||||
import {
|
||||
WatchOnlyWallet,
|
||||
HDLegacyBreadwalletWallet,
|
||||
HDSegwitP2SHWallet,
|
||||
LightningCustodianWallet,
|
||||
LegacyWallet,
|
||||
HDLegacyP2PKHWallet,
|
||||
} from '../../class';
|
||||
import {
|
||||
BlueText,
|
||||
BlueTransactionOnchainIcon,
|
||||
ManageFundsBigButton,
|
||||
BlueTransactionIncommingIcon,
|
||||
BlueTransactionOutgoingIcon,
|
||||
BlueTransactionPendingIcon,
|
||||
BlueTransactionOffchainIcon,
|
||||
BlueSendButtonIcon,
|
||||
BlueReceiveButtonIcon,
|
||||
BlueList,
|
||||
BlueListItem,
|
||||
} from '../../BlueComponents';
|
||||
import { Icon } from 'react-native-elements';
|
||||
/** @type {AppStorage} */
|
||||
let BlueApp = require('../../BlueApp');
|
||||
let loc = require('../../loc');
|
||||
const BigNumber = require('bignumber.js');
|
||||
let EV = require('../../events');
|
||||
const { width } = Dimensions.get('window');
|
||||
|
||||
export default class WalletTransactions extends Component {
|
||||
static navigationOptions = ({ navigation }) => {
|
||||
return {
|
||||
headerRight: (
|
||||
<Button
|
||||
onPress={() =>
|
||||
navigation.navigate('WalletDetails', {
|
||||
address: navigation.state.params.wallet.getAddress(),
|
||||
secret: navigation.state.params.wallet.getSecret(),
|
||||
})
|
||||
}
|
||||
title={loc.wallets.options}
|
||||
color="#fff"
|
||||
/>
|
||||
),
|
||||
headerStyle: {
|
||||
backgroundColor: navigation.state.params.headerColor,
|
||||
borderBottomWidth: 0,
|
||||
},
|
||||
headerTintColor: '#FFFFFF',
|
||||
};
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
isLoading: true,
|
||||
isTransactionsLoading: false,
|
||||
wallet: props.navigation.getParam('wallet'),
|
||||
gradientColors: ['#FFFFFF', '#FFFFFF'],
|
||||
dataSource: props.navigation.getParam('wallet').getTransactions(),
|
||||
};
|
||||
|
||||
// here, when we receive REMOTE_TRANSACTIONS_COUNT_CHANGED we fetch TXs and balance for current wallet
|
||||
EV(EV.enum.REMOTE_TRANSACTIONS_COUNT_CHANGED, this.refreshTransactionsFunction.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully fetches TXs and balance for wallet
|
||||
*/
|
||||
refreshTransactionsFunction() {
|
||||
let that = this;
|
||||
setTimeout(function() {
|
||||
that.refreshTransactions();
|
||||
}, 4000); // giving a chance to remote server to propagate
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
this.refreshFunction();
|
||||
let gradient1 = '#65ceef';
|
||||
let gradient2 = '#68bbe1';
|
||||
|
||||
if (new WatchOnlyWallet().type === this.state.wallet.type) {
|
||||
gradient1 = '#7d7d7d';
|
||||
gradient2 = '#4a4a4a';
|
||||
}
|
||||
|
||||
if (new LegacyWallet().type === this.state.wallet.type) {
|
||||
gradient1 = '#40fad1';
|
||||
gradient2 = '#15be98';
|
||||
}
|
||||
|
||||
if (new HDLegacyP2PKHWallet().type === this.state.wallet.type) {
|
||||
gradient1 = '#e36dfa';
|
||||
gradient2 = '#bd10e0';
|
||||
}
|
||||
|
||||
if (new HDLegacyBreadwalletWallet().type === this.state.wallet.type) {
|
||||
gradient1 = '#fe6381';
|
||||
gradient2 = '#f99c42';
|
||||
}
|
||||
|
||||
if (new HDSegwitP2SHWallet().type === this.state.wallet.type) {
|
||||
gradient1 = '#c65afb';
|
||||
gradient2 = '#9053fe';
|
||||
}
|
||||
|
||||
if (new LightningCustodianWallet().type === this.state.wallet.type) {
|
||||
gradient1 = '#f1be07';
|
||||
gradient2 = '#f79056';
|
||||
}
|
||||
|
||||
this.props.navigation.setParams({ headerColor: gradient1, wallet: this.state.wallet });
|
||||
this.setState({ gradientColors: [gradient1, gradient2] });
|
||||
}
|
||||
|
||||
/**
|
||||
* Redraws the screen
|
||||
*/
|
||||
refreshFunction() {
|
||||
setTimeout(() => {
|
||||
console.log('wallets/transactions refreshFunction()');
|
||||
let showSend = false;
|
||||
let showReceive = false;
|
||||
const wallet = this.state.wallet;
|
||||
if (wallet) {
|
||||
showSend = wallet.allowSend();
|
||||
showReceive = wallet.allowReceive();
|
||||
}
|
||||
|
||||
let showManageFundsBigButton = false;
|
||||
let showManageFundsSmallButton = false;
|
||||
if (wallet && wallet.type === new LightningCustodianWallet().type && wallet.getBalance() * 1 === 0) {
|
||||
showManageFundsBigButton = true;
|
||||
showManageFundsSmallButton = false;
|
||||
} else if (wallet && wallet.type === new LightningCustodianWallet().type && wallet.getBalance() > 0) {
|
||||
showManageFundsSmallButton = true;
|
||||
showManageFundsBigButton = false;
|
||||
}
|
||||
|
||||
this.setState({
|
||||
isLoading: false,
|
||||
isTransactionsLoading: false,
|
||||
showReceiveButton: showReceive,
|
||||
showSendButton: showSend,
|
||||
showManageFundsBigButton,
|
||||
showManageFundsSmallButton,
|
||||
dataSource: wallet.getTransactions(),
|
||||
});
|
||||
}, 1);
|
||||
}
|
||||
|
||||
isLightning() {
|
||||
let w = this.state.wallet;
|
||||
if (w && w.type === new LightningCustodianWallet().type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully fetches TXs and balance for wallet
|
||||
*/
|
||||
refreshTransactions() {
|
||||
this.setState(
|
||||
{
|
||||
isTransactionsLoading: true,
|
||||
},
|
||||
async function() {
|
||||
let that = this;
|
||||
setTimeout(async function() {
|
||||
// more responsive
|
||||
let noErr = true;
|
||||
try {
|
||||
/** @type {LegacyWallet} */
|
||||
let wallet = that.state.wallet;
|
||||
await wallet.fetchBalance();
|
||||
let start = +new Date();
|
||||
await wallet.fetchTransactions();
|
||||
let end = +new Date();
|
||||
console.log(wallet.getLabel(), 'fetch tx took', (end - start) / 1000, 'sec');
|
||||
} catch (err) {
|
||||
noErr = false;
|
||||
console.warn(err);
|
||||
}
|
||||
if (noErr) {
|
||||
await BlueApp.saveToDisk(); // caching
|
||||
EV(EV.enum.TRANSACTIONS_COUNT_CHANGED); // let other components know they should redraw
|
||||
}
|
||||
|
||||
that.refreshFunction(); // Redraws the screen
|
||||
}, 1);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
renderWalletHeader = () => {
|
||||
return (
|
||||
<LinearGradient colors={[this.state.gradientColors[0], this.state.gradientColors[1]]} style={{ padding: 15, height: 164 }}>
|
||||
<Image
|
||||
source={
|
||||
(new LightningCustodianWallet().type === this.state.wallet.type && require('../../img/lnd-shape.png')) ||
|
||||
require('../../img/btc-shape.png')
|
||||
}
|
||||
style={{
|
||||
width: 99,
|
||||
height: 94,
|
||||
position: 'absolute',
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
}}
|
||||
/>
|
||||
|
||||
<Text style={{ backgroundColor: 'transparent' }} />
|
||||
<Text
|
||||
numberOfLines={1}
|
||||
style={{
|
||||
backgroundColor: 'transparent',
|
||||
fontSize: 19,
|
||||
color: '#fff',
|
||||
}}
|
||||
>
|
||||
{this.state.wallet.getLabel()}
|
||||
</Text>
|
||||
<Text
|
||||
numberOfLines={1}
|
||||
adjustsFontSizeToFit
|
||||
style={{
|
||||
backgroundColor: 'transparent',
|
||||
fontWeight: 'bold',
|
||||
fontSize: 36,
|
||||
color: '#fff',
|
||||
}}
|
||||
>
|
||||
{loc.formatBalance(this.state.wallet.getBalance())}
|
||||
</Text>
|
||||
<Text style={{ backgroundColor: 'transparent' }} />
|
||||
<Text
|
||||
numberOfLines={1}
|
||||
style={{
|
||||
backgroundColor: 'transparent',
|
||||
fontSize: 13,
|
||||
color: '#fff',
|
||||
}}
|
||||
>
|
||||
{loc.wallets.list.latest_transaction}
|
||||
</Text>
|
||||
<Text
|
||||
numberOfLines={1}
|
||||
style={{
|
||||
backgroundColor: 'transparent',
|
||||
fontWeight: 'bold',
|
||||
fontSize: 16,
|
||||
color: '#fff',
|
||||
}}
|
||||
>
|
||||
{loc.transactionTimeToReadable(this.state.wallet.getLatestTransactionTime())}
|
||||
</Text>
|
||||
</LinearGradient>
|
||||
);
|
||||
};
|
||||
|
||||
txMemo(hash) {
|
||||
if (BlueApp.tx_metadata[hash] && BlueApp.tx_metadata[hash]['memo']) {
|
||||
return BlueApp.tx_metadata[hash]['memo'];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
_keyExtractor = (item, index) => index.toString();
|
||||
|
||||
renderListHeaderComponent = () => {
|
||||
return (
|
||||
<View style={{ flexDirection: 'row', height: 50 }}>
|
||||
<Text
|
||||
style={{
|
||||
paddingLeft: 15,
|
||||
paddingTop: 15,
|
||||
fontWeight: 'bold',
|
||||
fontSize: 24,
|
||||
color: BlueApp.settings.foregroundColor,
|
||||
}}
|
||||
>
|
||||
{loc.transactions.list.title}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { navigate } = this.props.navigation;
|
||||
return (
|
||||
<View style={{ flex: 1 }}>
|
||||
{this.renderWalletHeader()}
|
||||
<View style={{ flex: 1, backgroundColor: '#FFFFFF' }}>
|
||||
<View style={{ position: 'absolute', top: 120, width, zIndex: 1 }}>
|
||||
{(() => {
|
||||
let w = this.state.wallet;
|
||||
if (w.getTransactions().length === 0) {
|
||||
return (
|
||||
<View>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 18,
|
||||
color: '#9aa0aa',
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
{(this.isLightning() &&
|
||||
'Lightning wallet should be used for your daily\ntransactions. Fees are unfairly cheap and\nspeed is blazing fast.') ||
|
||||
loc.wallets.list.empty_txs1}
|
||||
</Text>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 18,
|
||||
color: '#9aa0aa',
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
{(this.isLightning() && '\nTo start using it tap on "manage funds"\nand topup your balance') ||
|
||||
loc.wallets.list.empty_txs2}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
</View>
|
||||
{(() => {
|
||||
if (this.state.showManageFundsSmallButton) {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
style={{ alignSelf: 'flex-end', right: 10, flexDirection: 'row' }}
|
||||
onPress={() => {
|
||||
let walletIndex = 0;
|
||||
|
||||
let c = 0;
|
||||
for (let w of BlueApp.getWallets()) {
|
||||
if (c++ === walletIndex) {
|
||||
console.log('navigating to', w.getLabel());
|
||||
navigate('ManageFunds', { fromSecret: w.getSecret() });
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<BlueText style={{ fontWeight: '600', fontSize: 16 }}>{loc.lnd.title}</BlueText>
|
||||
<Icon
|
||||
style={{ position: 'relative' }}
|
||||
name="link"
|
||||
type="font-awesome"
|
||||
size={14}
|
||||
color={BlueApp.settings.foregroundColor}
|
||||
iconStyle={{ left: 5, transform: [{ rotate: '90deg' }] }}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
<BlueList>
|
||||
<FlatList
|
||||
style={{ flex: 1 }}
|
||||
ListHeaderComponent={this.renderListHeaderComponent}
|
||||
refreshControl={<RefreshControl onRefresh={() => this.refreshTransactions()} refreshing={this.state.isTransactionsLoading} />}
|
||||
data={this.state.dataSource}
|
||||
extraData={this.state.dataSource}
|
||||
keyExtractor={this._keyExtractor}
|
||||
renderItem={rowData => {
|
||||
return (
|
||||
<BlueListItem
|
||||
avatar={(() => {
|
||||
// is it lightning refill tx?
|
||||
if (rowData.item.category === 'receive' && rowData.item.confirmations < 3) {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionPendingIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (rowData.item.type && rowData.item.type === 'bitcoind_tx') {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionOnchainIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
if (rowData.item.type === 'paid_invoice') {
|
||||
// is it lightning offchain payment?
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionOffchainIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!rowData.item.confirmations) {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionPendingIcon />
|
||||
</View>
|
||||
);
|
||||
} else if (rowData.item.value < 0) {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionOutgoingIcon />
|
||||
</View>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<View style={{ width: 25 }}>
|
||||
<BlueTransactionIncommingIcon />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
title={loc.transactionTimeToReadable(rowData.item.received)}
|
||||
subtitle={
|
||||
(rowData.item.confirmations < 7 ? loc.transactions.list.conf + ': ' + rowData.item.confirmations + ' ' : '') +
|
||||
this.txMemo(rowData.item.hash) +
|
||||
(rowData.item.memo || '')
|
||||
}
|
||||
onPress={() => {
|
||||
if (rowData.item.hash) {
|
||||
navigate('TransactionDetails', {
|
||||
hash: rowData.item.hash,
|
||||
});
|
||||
}
|
||||
}}
|
||||
badge={{
|
||||
value: 3,
|
||||
textStyle: { color: 'orange' },
|
||||
containerStyle: { marginTop: 0 },
|
||||
}}
|
||||
hideChevron
|
||||
rightTitle={new BigNumber((rowData.item.value && rowData.item.value) || 0).div(100000000).toString()}
|
||||
rightTitleStyle={{
|
||||
fontWeight: '600',
|
||||
fontSize: 16,
|
||||
color: rowData.item.value / 100000000 < 0 ? BlueApp.settings.foregroundColor : '#37c0a1',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</BlueList>
|
||||
</View>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: 'row',
|
||||
alignSelf: 'center',
|
||||
backgroundColor: 'transparent',
|
||||
position: 'absolute',
|
||||
bottom: 30,
|
||||
borderRadius: 15,
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
{(() => {
|
||||
if (this.state.showReceiveButton) {
|
||||
return (
|
||||
<BlueReceiveButtonIcon
|
||||
onPress={() => {
|
||||
navigate('ReceiveDetails', { address: this.state.wallet.getAddress(), secret: this.state.wallet.getSecret() });
|
||||
if (this.state.wallet.getAddress()) {
|
||||
// EV(EV.enum.RECEIVE_ADDRESS_CHANGED, w.getAddress());
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
|
||||
{(() => {
|
||||
if (this.state.showSendButton) {
|
||||
return (
|
||||
<BlueSendButtonIcon
|
||||
onPress={() => {
|
||||
if (this.state.wallet.type === new LightningCustodianWallet().type) {
|
||||
navigate('ScanLndInvoice', { fromSecret: this.state.wallet.getSecret() });
|
||||
} else {
|
||||
navigate('SendDetails', { fromAddress: this.state.wallet.getAddress(), fromSecret: this.state.wallet.getSecret() });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
|
||||
{(() => {
|
||||
if (this.state.showManageFundsBigButton) {
|
||||
return (
|
||||
<ManageFundsBigButton
|
||||
onPress={() => {
|
||||
navigate('ManageFunds', { fromSecret: this.state.wallet.getSecret() });
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
WalletTransactions.propTypes = {
|
||||
navigation: PropTypes.shape({
|
||||
navigate: PropTypes.func,
|
||||
goBack: PropTypes.func,
|
||||
getParam: PropTypes.func,
|
||||
setParams: PropTypes.func,
|
||||
}),
|
||||
};
|
Loading…
Add table
Reference in a new issue