forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reorderWallets.js
212 lines (197 loc) · 6.65 KB
/
reorderWallets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import React, { useEffect, useRef, useContext, useState } from 'react';
import { View, Image, Text, StyleSheet, StatusBar, I18nManager, Pressable, useColorScheme, Platform } from 'react-native';
import { BluePrivateBalance } from '../../BlueComponents';
import DraggableFlatList, { ScaleDecorator } from '../../components/react-native-draggable-flatlist';
import LinearGradient from 'react-native-linear-gradient';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import { useNavigation, useTheme } from '@react-navigation/native';
import navigationStyle from '../../components/navigationStyle';
import { LightningCustodianWallet, LightningLdkWallet, MultisigHDWallet } from '../../class';
import WalletGradient from '../../class/wallet-gradient';
import loc, { formatBalance, transactionTimeToReadable } from '../../loc';
import { BlueStorageContext } from '../../blue_modules/storage-context';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
const styles = StyleSheet.create({
root: {
flex: 1,
},
itemRoot: {
backgroundColor: 'transparent',
padding: 10,
},
gradient: {
padding: 15,
borderRadius: 10,
minHeight: 164,
elevation: 5,
},
image: {
width: 99,
height: 94,
position: 'absolute',
bottom: 0,
right: 0,
},
transparentText: {
backgroundColor: 'transparent',
},
tip: {
marginHorizontal: 16,
borderRadius: 12,
padding: 16,
marginVertical: 24,
},
label: {
backgroundColor: 'transparent',
fontSize: 19,
color: '#fff',
writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr',
},
balance: {
backgroundColor: 'transparent',
fontWeight: 'bold',
fontSize: 36,
color: '#fff',
writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr',
},
latestTxLabel: {
backgroundColor: 'transparent',
fontSize: 13,
color: '#fff',
writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr',
},
latestTxValue: {
backgroundColor: 'transparent',
fontWeight: 'bold',
fontSize: 16,
color: '#fff',
writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr',
},
});
const ReorderWallets = () => {
const sortableList = useRef();
const { colors } = useTheme();
const { wallets, setWalletsWithNewOrder } = useContext(BlueStorageContext);
const { navigate } = useNavigation();
const stylesHook = {
root: {
backgroundColor: colors.elevated,
},
tip: {
backgroundColor: colors.ballOutgoingExpired,
},
};
const [walletData, setWalletData] = useState([]);
useEffect(() => {
setWalletData(wallets);
}, [wallets]);
const navigateToWallet = wallet => {
const walletID = wallet.getID();
navigate('WalletTransactions', {
walletID,
walletType: wallet.type,
key: `WalletTransactions-${walletID}`,
});
};
const renderItem = ({ item, drag, isActive }) => {
return (
<ScaleDecorator>
<Pressable
accessibilityRole="button"
disabled={isActive}
onLongPress={drag}
onPress={() => navigateToWallet(item)}
shadowOpacity={40 / 100}
shadowOffset={{ width: 0, height: 0 }}
shadowRadius={5}
style={styles.itemRoot}
>
<LinearGradient shadowColor="#000000" colors={WalletGradient.gradientsFor(item.type)} style={styles.gradient}>
<Image
source={(() => {
switch (item.type) {
case LightningLdkWallet.type:
case LightningCustodianWallet.type:
return I18nManager.isRTL ? require('../../img/lnd-shape-rtl.png') : require('../../img/lnd-shape.png');
case MultisigHDWallet.type:
return I18nManager.isRTL ? require('../../img/vault-shape-rtl.png') : require('../../img/vault-shape.png');
default:
return I18nManager.isRTL ? require('../../img/btc-shape-rtl.png') : require('../../img/btc-shape.png');
}
})()}
style={styles.image}
/>
<Text style={styles.transparentText} />
<Text numberOfLines={1} style={styles.label}>
{item.getLabel()}
</Text>
{item.hideBalance ? (
<BluePrivateBalance />
) : (
<Text numberOfLines={1} adjustsFontSizeToFit style={styles.balance}>
{formatBalance(Number(item.getBalance()), item.getPreferredBalanceUnit(), true)}
</Text>
)}
<Text style={styles.transparentText} />
<Text numberOfLines={1} style={styles.latestTxLabel}>
{loc.wallets.list_latest_transaction}
</Text>
<Text numberOfLines={1} style={styles.latestTxValue}>
{item.getTransactions().find(tx => tx.confirmations === 0)
? loc.transactions.pending.toLowerCase()
: transactionTimeToReadable(item.getLatestTransactionTime())}
</Text>
</LinearGradient>
</Pressable>
</ScaleDecorator>
);
};
const onChangeOrder = () => {
ReactNativeHapticFeedback.trigger('impactMedium', { ignoreAndroidSystemSettings: false });
};
const onDragBegin = () => {
ReactNativeHapticFeedback.trigger('selection', { ignoreAndroidSystemSettings: false });
};
const onRelease = () => {
ReactNativeHapticFeedback.trigger('impactLight', { ignoreAndroidSystemSettings: false });
};
const onDragEnd = ({ data }) => {
setWalletsWithNewOrder(data);
setWalletData(data);
};
const _keyExtractor = (_item, index) => index.toString();
const ListHeaderComponent = (
<View style={[styles.tip, stylesHook.tip]}>
<Text style={{ color: colors.foregroundColor }}>{loc.wallets.reorder_instructions}</Text>
</View>
);
return (
<GestureHandlerRootView style={[styles.root, stylesHook.root]}>
<StatusBar
barStyle={Platform.select({ ios: 'light-content', default: useColorScheme() === 'dark' ? 'light-content' : 'dark-content' })}
/>
<DraggableFlatList
ListHeaderComponent={ListHeaderComponent}
ref={sortableList}
dragItemOverflow
data={walletData}
keyExtractor={_keyExtractor}
renderItem={renderItem}
onChangeOrder={onChangeOrder}
onDragBegin={onDragBegin}
onRelease={onRelease}
onDragEnd={onDragEnd}
containerStyle={styles.root}
/>
</GestureHandlerRootView>
);
};
ReorderWallets.navigationOptions = navigationStyle(
{
headerHideBackButton: true,
headerLargeTitle: true,
closeButton: true,
},
opts => ({ ...opts, headerTitle: loc.wallets.reorder_title }),
);
export default ReorderWallets;