-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDialogWithdrawView.tsx
168 lines (147 loc) · 5.81 KB
/
DialogWithdrawView.tsx
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
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {Modal, StyleSheet, TouchableOpacity, View} from "react-native";
import {AppText} from "./AppText";
import AppIcon from "./assets/AppIcon";
import {AppToken} from "./RentLendTokensView";
import {Slice, VictoryPie} from "victory-native";
import {newLockedGold} from "@celo/contractkit/lib/generated/LockedGold";
import {balanceElapsedInPercent, secondsElapsed, secondsElapsedInPercent} from "./date.utils";
import {WithdrawChartView} from "./WithdrawChartView";
import {isOwner, showWithdrawDetails} from "./constants";
import moment from "moment";
// import { BlurView } from 'expo-blur';
interface Props {
readonly isVisible: boolean
readonly onDismiss: () => void
readonly onWithdraw: (tokeId: AppToken['tokenId']) => void
readonly address: string
readonly item: () => AppToken
}
const maxBalance = '990000000000000000'
export const DialogWithdrawView: React.FC<Props> = (props) => {
///let token: AppToken = {...props.item(), balance: '940000000', rentedAt: moment('2021-11-28 10:06').unix().toString()}
let token: AppToken = props.item()
const rentedAt = parseInt(token.rentedAt, 10)
console.log(rentedAt, secondsElapsedInPercent(rentedAt), secondsElapsed(rentedAt))
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const [time, setTime] = useState(secondsElapsedInPercent(rentedAt))
const [balance, setBalance] = useState(() => {
if (isOwner(token, props.address)) {
//return balanceElapsedInPercent(rentedAt, parseInt(token.balance, 10))
//return 1.0 - (parseInt(maxBalance, 10) - parseInt(token.balance, 10)) / parseInt(maxBalance, 10)
}
console.log('balance', (parseInt(maxBalance, 10) - parseInt(token.balance, 10)) / parseInt(maxBalance, 10))
return (parseInt(maxBalance, 10) - parseInt(token.balance, 10)) / parseInt(maxBalance, 10)
//return 0
})
const timeRef = useRef(secondsElapsed(rentedAt))
const height = 250
useEffect(() => {
const time = () => {
setTime((prev) => {
if (prev >= 1) {
if (timeoutRef.current) clearTimeout(timeoutRef.current)
setBalance(1)
return 1
}
timeoutRef.current = setTimeout(time, 1000)
timeRef.current += 1
return timeRef.current / 60
})
}
timeoutRef.current = setTimeout(time, 1000)
return () => {
if (timeoutRef.current) clearTimeout(timeoutRef.current)
}
}, [])
const onWithdrawPress = useCallback(() => {
props.onDismiss()
props.onWithdraw(token.tokenId)
}, [])
return (
<Modal transparent statusBarTranslucent animated visible={props.isVisible} animationType={'fade'}>
<View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<TouchableOpacity
activeOpacity={1}
onPress={props.onDismiss}
style={[StyleSheet.absoluteFillObject, {backgroundColor: 'rgba(0, 0, 0, 0.9)'}]}
/>
<TouchableOpacity activeOpacity={1} style={styles.container}>
<View style={styles.header}>
<AppText fontSize={24} fontFamily={'bold'} color={'white'}>Rented</AppText>
<View style={{flex: 1}}/>
<TouchableOpacity activeOpacity={1} onPress={props.onDismiss} >
<AppIcon type={'icDialogClose'} width={32} height={32}/>
</TouchableOpacity>
</View>
<View style={styles.input}>
<View style={{height: 125, width: '100%'}}>
<WithdrawChartView containerHeight={125} height={height} color={'#353945'} value={1}/>
<WithdrawChartView containerHeight={125} height={height} color={'#ffffff'} value={time}/>
<WithdrawChartView containerHeight={125} height={height} color={'#07DA67'} value={balance}/>
</View>
<View style={{position: 'absolute', bottom: 16 + 16 + 8, alignItems: 'center', left: 0, right: 0}}>
<AppText style={{alignSelf: 'center'}} fontSize={38} fontFamily={'bold'}>1.00</AppText>
</View>
<View style={{flexDirection: 'row', marginTop: 8}}>
<AppText fontSize={12} color={'#777E90'}>0.001</AppText>
<View style={{flex: 1}}/>
<AppText fontSize={12} color={'#777E90'}>0.0165 CELO / SEC</AppText>
<View style={{flex: 1}}/>
<AppText fontSize={12} color={'#777E90'}>1.00</AppText>
</View>
</View>
<View style={styles.footer}>
{showWithdrawDetails(token, props.address) && (
// {true && (
<TouchableOpacity activeOpacity={1} onPress={onWithdrawPress} style={[styles.button, {borderWidth: 0, backgroundColor: 'white'}]}>
<AppText color={'#141416'} fontSize={16} fontFamily={'bold'}>Withdraw</AppText>
</TouchableOpacity>
)}
<View style={{height: 8}}/>
<TouchableOpacity activeOpacity={1} onPress={props.onDismiss} style={styles.button}>
<AppText color={'white'} fontSize={16} fontFamily={'bold'}>Cancel</AppText>
</TouchableOpacity>
</View>
</TouchableOpacity>
</View>
</Modal>
)
};
const styles = StyleSheet.create({
container: {
borderRadius: 24,
width: '88%',
backgroundColor: '#23262F',
paddingBottom: 24
},
header: {
height: 40,
paddingHorizontal: 24,
marginTop: 28,
flexDirection: 'row',
alignItems: 'center'
},
input: {
borderWidth: 1,
borderColor: '#353945',
borderRadius: 12,
marginTop: 32,
padding: 16,
marginHorizontal: 24,
},
footer: {
paddingHorizontal: 24,
marginTop: 32,
flexDirection: 'column'
},
button: {
width: '100%',
alignItems: 'center',
justifyContent: 'center',
height: 48,
borderWidth: 2,
borderColor: '#353945',
borderRadius: 1000
},
})