|
@@ -6,6 +6,7 @@ import React, { Component } from 'react';
|
|
|
import { FlatList, StyleSheet } from 'react-native';
|
|
import { FlatList, StyleSheet } from 'react-native';
|
|
|
import { View, Text } from 'react-native';
|
|
import { View, Text } from 'react-native';
|
|
|
import PagerView from 'react-native-pager-view';
|
|
import PagerView from 'react-native-pager-view';
|
|
|
|
|
+import apiCharge from '../../api/apiCharge';
|
|
|
import apiWallets from '../../api/apiWallets';
|
|
import apiWallets from '../../api/apiWallets';
|
|
|
import { ElevationObject } from '../../components/Button';
|
|
import { ElevationObject } from '../../components/Button';
|
|
|
import VbeSkeleton from '../../components/VbeSkeleton';
|
|
import VbeSkeleton from '../../components/VbeSkeleton';
|
|
@@ -19,9 +20,7 @@ export default class Wallets extends Component {
|
|
|
loading: true,
|
|
loading: true,
|
|
|
wallets: [],
|
|
wallets: [],
|
|
|
active: 0,
|
|
active: 0,
|
|
|
- history: {
|
|
|
|
|
-
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ history: {},
|
|
|
historyList: [],
|
|
historyList: [],
|
|
|
loadingList: false
|
|
loadingList: false
|
|
|
};
|
|
};
|
|
@@ -31,14 +30,37 @@ export default class Wallets extends Component {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
this.getWalletsInfo();
|
|
this.getWalletsInfo();
|
|
|
}, 500);
|
|
}, 500);
|
|
|
|
|
+ this.props.navigation.addListener('focus', () => {
|
|
|
|
|
+ if (!this.state.loading) {
|
|
|
|
|
+ this.refresh();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ refresh() {
|
|
|
|
|
+ this.setState({
|
|
|
|
|
+ history: {},
|
|
|
|
|
+ historyList: [],
|
|
|
|
|
+ loadingList: true
|
|
|
|
|
+ }, () => {
|
|
|
|
|
+ this.getWalletsInfo(true);
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- getWalletsInfo() {
|
|
|
|
|
|
|
+ getWalletsInfo(refresh) {
|
|
|
apiWallets.getWalletsInfo().then(res => {
|
|
apiWallets.getWalletsInfo().then(res => {
|
|
|
if (res.data) {
|
|
if (res.data) {
|
|
|
this.setState({
|
|
this.setState({
|
|
|
wallets: res.data
|
|
wallets: res.data
|
|
|
})
|
|
})
|
|
|
|
|
+ if (refresh) {
|
|
|
|
|
+ let wallet = this.state.wallets[this.state.active];
|
|
|
|
|
+ if (wallet && wallet.walletTypeCode) {
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ this.getTransactionInfo(wallet.walletTypeCode);
|
|
|
|
|
+ }, 300);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}).catch(err => {
|
|
}).catch(err => {
|
|
|
toastShort(err)
|
|
toastShort(err)
|
|
@@ -98,6 +120,23 @@ export default class Wallets extends Component {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ setDefault(index) {
|
|
|
|
|
+ const code = this.state.wallets[index]?.walletTypeCode;
|
|
|
|
|
+ if (code) {
|
|
|
|
|
+ Dialog.showProgressDialog();
|
|
|
|
|
+ apiCharge.setDefaultPaymentType({
|
|
|
|
|
+ defaultPaymentMethod: code
|
|
|
|
|
+ }).then(res => {
|
|
|
|
|
+ toastShort("success");
|
|
|
|
|
+ this.getWalletsInfo();
|
|
|
|
|
+ }).catch(err => {
|
|
|
|
|
+ toastShort(err)
|
|
|
|
|
+ }).finally(() => {
|
|
|
|
|
+ Dialog.dismissLoading();
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
divideView = (props) => {
|
|
divideView = (props) => {
|
|
|
return (<View style={styles.divideView}></View>)
|
|
return (<View style={styles.divideView}></View>)
|
|
|
}
|
|
}
|
|
@@ -108,8 +147,8 @@ export default class Wallets extends Component {
|
|
|
<VbeSkeleton
|
|
<VbeSkeleton
|
|
|
style={[ui.flex1, $padding(16)]}
|
|
style={[ui.flex1, $padding(16)]}
|
|
|
layout={[
|
|
layout={[
|
|
|
- {width: "100%", height: 200, borderRadius: 16},
|
|
|
|
|
- {width: "100%", height: $vh(100) - 320, borderRadius: 16, marginTop: 24},
|
|
|
|
|
|
|
+ {width: "100%", height: 210, borderRadius: 16},
|
|
|
|
|
+ {width: "100%", height: $vh(100) - 330, borderRadius: 16, marginTop: 24},
|
|
|
]}
|
|
]}
|
|
|
animationDirection={"horizontalRight"}
|
|
animationDirection={"horizontalRight"}
|
|
|
/>
|
|
/>
|
|
@@ -119,10 +158,13 @@ export default class Wallets extends Component {
|
|
|
<View style={styles.container}>
|
|
<View style={styles.container}>
|
|
|
<PagerView
|
|
<PagerView
|
|
|
style={styles.pagerView}
|
|
style={styles.pagerView}
|
|
|
- initialPage={0}
|
|
|
|
|
|
|
+ initialPage={this.state.active}
|
|
|
onPageSelected={e => this.changeCard(e)}>
|
|
onPageSelected={e => this.changeCard(e)}>
|
|
|
{ this.state.wallets.map((item, index) => (
|
|
{ this.state.wallets.map((item, index) => (
|
|
|
- <ViewWallet key={index} wallet={item}/>
|
|
|
|
|
|
|
+ <ViewWallet
|
|
|
|
|
+ key={index}
|
|
|
|
|
+ wallet={item}
|
|
|
|
|
+ setDefault={() => this.setDefault(index)}/>
|
|
|
))}
|
|
))}
|
|
|
</PagerView>
|
|
</PagerView>
|
|
|
<View style={styles.indicatorView}>
|
|
<View style={styles.indicatorView}>
|
|
@@ -165,7 +207,7 @@ const styles = StyleSheet.create({
|
|
|
backgroundColor: pageBackground
|
|
backgroundColor: pageBackground
|
|
|
},
|
|
},
|
|
|
pagerView: {
|
|
pagerView: {
|
|
|
- height: 200
|
|
|
|
|
|
|
+ height: 210
|
|
|
},
|
|
},
|
|
|
indicatorView: {
|
|
indicatorView: {
|
|
|
padding: 8,
|
|
padding: 8,
|