be-components 5.9.7 → 5.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/MarketComponents/api/index.js +136 -0
- package/lib/commonjs/MarketComponents/api/index.js.map +1 -1
- package/lib/commonjs/MarketComponents/components/MarketManager/MarketResolveForm.js +553 -0
- package/lib/commonjs/MarketComponents/components/MarketManager/MarketResolveForm.js.map +1 -0
- package/lib/commonjs/MarketComponents/components/MarketManager/MarketRollbackForm.js +315 -0
- package/lib/commonjs/MarketComponents/components/MarketManager/MarketRollbackForm.js.map +1 -0
- package/lib/commonjs/MarketComponents/components/MarketManager/index.js +570 -0
- package/lib/commonjs/MarketComponents/components/MarketManager/index.js.map +1 -0
- package/lib/commonjs/MarketComponents/components/TeamEventMarket/index.js +35 -0
- package/lib/commonjs/MarketComponents/components/TeamEventMarket/index.js.map +1 -1
- package/lib/commonjs/MarketComponents/components/TournamentMarket/index.js +21 -0
- package/lib/commonjs/MarketComponents/components/TournamentMarket/index.js.map +1 -1
- package/lib/commonjs/MarketComponents/index.js +2 -0
- package/lib/commonjs/MarketComponents/index.js.map +1 -1
- package/lib/module/MarketComponents/api/index.js +136 -0
- package/lib/module/MarketComponents/api/index.js.map +1 -1
- package/lib/module/MarketComponents/components/MarketManager/MarketResolveForm.js +544 -0
- package/lib/module/MarketComponents/components/MarketManager/MarketResolveForm.js.map +1 -0
- package/lib/module/MarketComponents/components/MarketManager/MarketRollbackForm.js +307 -0
- package/lib/module/MarketComponents/components/MarketManager/MarketRollbackForm.js.map +1 -0
- package/lib/module/MarketComponents/components/MarketManager/index.js +561 -0
- package/lib/module/MarketComponents/components/MarketManager/index.js.map +1 -0
- package/lib/module/MarketComponents/components/TeamEventMarket/index.js +35 -0
- package/lib/module/MarketComponents/components/TeamEventMarket/index.js.map +1 -1
- package/lib/module/MarketComponents/components/TournamentMarket/index.js +21 -0
- package/lib/module/MarketComponents/components/TournamentMarket/index.js.map +1 -1
- package/lib/module/MarketComponents/index.js +2 -0
- package/lib/module/MarketComponents/index.js.map +1 -1
- package/lib/typescript/lib/commonjs/MarketComponents/api/index.d.ts +21 -0
- package/lib/typescript/lib/commonjs/MarketComponents/api/index.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/MarketComponents/components/MarketManager/MarketResolveForm.d.ts +14 -0
- package/lib/typescript/lib/commonjs/MarketComponents/components/MarketManager/MarketResolveForm.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/MarketComponents/components/MarketManager/MarketRollbackForm.d.ts +15 -0
- package/lib/typescript/lib/commonjs/MarketComponents/components/MarketManager/MarketRollbackForm.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/MarketComponents/components/MarketManager/index.d.ts +9 -0
- package/lib/typescript/lib/commonjs/MarketComponents/components/MarketManager/index.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/MarketComponents/components/TournamentMarket/index.d.ts +2 -1
- package/lib/typescript/lib/commonjs/MarketComponents/components/TournamentMarket/index.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/MarketComponents/index.d.ts +1 -0
- package/lib/typescript/lib/module/MarketComponents/api/index.d.ts +21 -0
- package/lib/typescript/lib/module/MarketComponents/api/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/MarketComponents/components/MarketManager/MarketResolveForm.d.ts +14 -0
- package/lib/typescript/lib/module/MarketComponents/components/MarketManager/MarketResolveForm.d.ts.map +1 -0
- package/lib/typescript/lib/module/MarketComponents/components/MarketManager/MarketRollbackForm.d.ts +15 -0
- package/lib/typescript/lib/module/MarketComponents/components/MarketManager/MarketRollbackForm.d.ts.map +1 -0
- package/lib/typescript/lib/module/MarketComponents/components/MarketManager/index.d.ts +9 -0
- package/lib/typescript/lib/module/MarketComponents/components/MarketManager/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/MarketComponents/components/TeamEventMarket/index.d.ts +2 -1
- package/lib/typescript/lib/module/MarketComponents/components/TeamEventMarket/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/MarketComponents/components/TournamentMarket/index.d.ts +2 -1
- package/lib/typescript/lib/module/MarketComponents/components/TournamentMarket/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/MarketComponents/index.d.ts +2 -0
- package/lib/typescript/lib/module/MarketComponents/index.d.ts.map +1 -1
- package/lib/typescript/src/MarketComponents/api/index.d.ts +33 -1
- package/lib/typescript/src/MarketComponents/api/index.d.ts.map +1 -1
- package/lib/typescript/src/MarketComponents/components/MarketManager/MarketResolveForm.d.ts +17 -0
- package/lib/typescript/src/MarketComponents/components/MarketManager/MarketResolveForm.d.ts.map +1 -0
- package/lib/typescript/src/MarketComponents/components/MarketManager/MarketRollbackForm.d.ts +17 -0
- package/lib/typescript/src/MarketComponents/components/MarketManager/MarketRollbackForm.d.ts.map +1 -0
- package/lib/typescript/src/MarketComponents/components/MarketManager/index.d.ts +10 -0
- package/lib/typescript/src/MarketComponents/components/MarketManager/index.d.ts.map +1 -0
- package/lib/typescript/src/MarketComponents/components/TeamEventMarket/index.d.ts +2 -1
- package/lib/typescript/src/MarketComponents/components/TeamEventMarket/index.d.ts.map +1 -1
- package/lib/typescript/src/MarketComponents/components/TournamentMarket/index.d.ts +2 -1
- package/lib/typescript/src/MarketComponents/components/TournamentMarket/index.d.ts.map +1 -1
- package/lib/typescript/src/MarketComponents/index.d.ts +10 -2
- package/lib/typescript/src/MarketComponents/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/MarketComponents/api/index.ts +93 -1
- package/src/MarketComponents/components/MarketManager/MarketResolveForm.tsx +354 -0
- package/src/MarketComponents/components/MarketManager/MarketRollbackForm.tsx +202 -0
- package/src/MarketComponents/components/MarketManager/index.tsx +392 -0
- package/src/MarketComponents/components/TeamEventMarket/index.tsx +28 -2
- package/src/MarketComponents/components/TournamentMarket/index.tsx +15 -1
- package/src/MarketComponents/index.tsx +2 -0
- package/src/types.d.ts +25 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { Button, Text, TextInput, View } from "../../../Components/Themed"
|
|
3
|
+
import type { AthleteProps, AthleteStatProps, MarketProps, MarketStatsProps, TeamProps } from '../../../types';
|
|
4
|
+
import { Checkbox, Icons, Switch } from '../../../Components';
|
|
5
|
+
import { Alert, FlatList, Platform } from 'react-native';
|
|
6
|
+
import { MarketComponentApi, MarketComponentHelpers } from '../../api';
|
|
7
|
+
import { useColors } from '../../../constants/useColors';
|
|
8
|
+
import { AthleteImage } from '../../../Components/Jerseys';
|
|
9
|
+
import DropDown from '../../../Components/Dropdown';
|
|
10
|
+
|
|
11
|
+
type MarketResolveFormProps = {
|
|
12
|
+
contest_title:string,
|
|
13
|
+
contest_type:string,
|
|
14
|
+
contest_id:string,
|
|
15
|
+
market:MarketProps,
|
|
16
|
+
side_type?:string,
|
|
17
|
+
side_id?:string,
|
|
18
|
+
teams:TeamProps[],
|
|
19
|
+
athletes:AthleteProps[],
|
|
20
|
+
market_stats:MarketStatsProps[],
|
|
21
|
+
onClose:() => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const sections = ['market','athlete','team','event_form','stat_form']
|
|
25
|
+
const MarketResolveForm = ({ contest_title, contest_id, contest_type, market, athletes, market_stats, side_type, side_id, onClose }:MarketResolveFormProps) => {
|
|
26
|
+
const Colors = useColors();
|
|
27
|
+
const [ expand_athletes, setExpandedAthletes ] = useState(false);
|
|
28
|
+
//åconst [ expand_teams, setExpandedTeams ] = useState(false);
|
|
29
|
+
const [ resolve, setResolve ] = useState<{
|
|
30
|
+
action_loading:boolean,
|
|
31
|
+
side_type?:string,
|
|
32
|
+
side_id?:string,
|
|
33
|
+
stat_value?:string,
|
|
34
|
+
winnings_side?:string,
|
|
35
|
+
no_bet?:boolean,
|
|
36
|
+
no_bet_reason?:string,
|
|
37
|
+
event_stat_value?:string
|
|
38
|
+
}>({
|
|
39
|
+
action_loading: false,
|
|
40
|
+
});
|
|
41
|
+
const { action_loading, stat_value, event_stat_value, winnings_side, no_bet, no_bet_reason } = resolve;
|
|
42
|
+
let rollback_stats = market_stats.filter(s => s.market_id == market.market_id);
|
|
43
|
+
if(resolve.side_type && resolve.side_id){
|
|
44
|
+
rollback_stats = rollback_stats.filter(r => r.side_type == resolve.side_type && r.side_id == resolve.side_id);
|
|
45
|
+
}
|
|
46
|
+
const { total_volume, total_unresolved } = MarketComponentHelpers.getReconFromMarketStats(rollback_stats);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
setResolve({ action_loading: false, side_id, side_type });
|
|
51
|
+
},[contest_id, contest_type, market?.market_id, side_type, side_id])
|
|
52
|
+
|
|
53
|
+
const isValid = () => {
|
|
54
|
+
if(!contest_id || !contest_type){ return false }
|
|
55
|
+
if(!market){ return false }
|
|
56
|
+
if(market.level == 'athlete' && resolve.side_type != 'athlete'){ return false }
|
|
57
|
+
if(market.level == 'athlete' && !resolve.side_id){ return false }
|
|
58
|
+
if(market.level == 'team' && resolve.side_type != 'team'){ return false }
|
|
59
|
+
if(market.level == 'team' && !resolve.side_id){ return false }
|
|
60
|
+
if(total_unresolved == 0){ return false }
|
|
61
|
+
if(market.type == 'Stat'){
|
|
62
|
+
if(!stat_value){ return false }
|
|
63
|
+
if(isNaN(parseInt(stat_value))){ return false }
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
if(market.type == 'Spread'){ return false }
|
|
67
|
+
if(market.type == 'Total'){ return }
|
|
68
|
+
return true
|
|
69
|
+
}
|
|
70
|
+
const is_valid = isValid();
|
|
71
|
+
|
|
72
|
+
const confirmResolve = async() => {
|
|
73
|
+
if(action_loading || !is_valid){ return }
|
|
74
|
+
if(Platform.OS == 'web'){
|
|
75
|
+
const confirmed = await confirm('Are you sure? This will settle all open positions that fit this resolution criteria')
|
|
76
|
+
if(!confirmed){ return }
|
|
77
|
+
return handleResolveMarket()
|
|
78
|
+
} else {
|
|
79
|
+
Alert.alert('Are you sure?', 'This will settle all open positions that fit this resolution criteria', [
|
|
80
|
+
{
|
|
81
|
+
text: 'Cancel',
|
|
82
|
+
style:'cancel',
|
|
83
|
+
onPress:() => console.log('Done')
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
style: 'destructive',
|
|
87
|
+
text: 'Confirm',
|
|
88
|
+
onPress:async() => {
|
|
89
|
+
return handleResolveMarket()
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
]);
|
|
93
|
+
return true
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const handleResolveMarket = async() => {
|
|
98
|
+
if(action_loading){ return }
|
|
99
|
+
if(!is_valid){ return }
|
|
100
|
+
setResolve({ ...resolve, action_loading:true });
|
|
101
|
+
let athlete_stat:AthleteStatProps | undefined = undefined
|
|
102
|
+
if(market.resolver == 'res_event_athlete_stat' && resolve.side_type && resolve.side_id && stat_value){
|
|
103
|
+
athlete_stat = {
|
|
104
|
+
athlete_id: resolve.side_id,
|
|
105
|
+
event_id: contest_id,
|
|
106
|
+
stat: { stat: market.stat, stat_label: market.stat_label ?? '' },
|
|
107
|
+
value: parseFloat(stat_value)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
let ev_stat_value:number|undefined = undefined
|
|
111
|
+
if(market.resolver == 'res_event_stat' && event_stat_value){
|
|
112
|
+
ev_stat_value = parseFloat(event_stat_value)
|
|
113
|
+
}
|
|
114
|
+
await MarketComponentApi.resolveMarket({
|
|
115
|
+
event_id:contest_id,
|
|
116
|
+
event_type:contest_type,
|
|
117
|
+
market_id:market.market_id,
|
|
118
|
+
winnings_side:winnings_side,
|
|
119
|
+
side_id: resolve.side_id,
|
|
120
|
+
side_type: resolve.side_type,
|
|
121
|
+
athlete_stat,
|
|
122
|
+
no_bet:no_bet,
|
|
123
|
+
no_bet_reason: no_bet_reason,
|
|
124
|
+
event_stat_value: ev_stat_value
|
|
125
|
+
});
|
|
126
|
+
setResolve({ ...resolve, action_loading: false });
|
|
127
|
+
onClose();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const renderAthletes = (data:{ item:AthleteProps, index:number}) => {
|
|
131
|
+
const selected = resolve.side_id == data.item.athlete_id ? true : false
|
|
132
|
+
const stats = market_stats.filter(s => s.market_id == market.market_id && s.side_type == 'athlete' && s.side_id == data.item.athlete_id);
|
|
133
|
+
const agg_stats = MarketComponentHelpers.getReconFromMarketStats(stats);
|
|
134
|
+
return (
|
|
135
|
+
<Button style={{ padding:10, flexDirection:'row', alignItems:'center', borderBottomWidth:1, borderColor:Colors.borders.light, borderRadius:0 }} onPress={() => {
|
|
136
|
+
if(selected){ setResolve({ ...resolve, side_id: undefined }) }
|
|
137
|
+
else { setResolve({ ...resolve, side_type: 'athlete', side_id: data.item.athlete_id }) }
|
|
138
|
+
setExpandedAthletes(false);
|
|
139
|
+
}}>
|
|
140
|
+
<AthleteImage
|
|
141
|
+
athlete={data.item}
|
|
142
|
+
size={28}
|
|
143
|
+
/>
|
|
144
|
+
<View style={{ flex:1, marginLeft:10 }}>
|
|
145
|
+
<Text theme='h1'>{data.item.first_name} {data.item.last_name}</Text>
|
|
146
|
+
<Text theme='description' style={{ marginTop:3 }}>Unresolved: {agg_stats.total_unresolved.toFixed(2)}</Text>
|
|
147
|
+
</View>
|
|
148
|
+
<Checkbox
|
|
149
|
+
checked={selected}
|
|
150
|
+
disabled
|
|
151
|
+
style={{ marginLeft:5 }}
|
|
152
|
+
onSelect={() => console.log('')}
|
|
153
|
+
/>
|
|
154
|
+
</Button>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
//const selected_team = teams.find(t => t.team_id == resolve.side_id);
|
|
159
|
+
|
|
160
|
+
const renderSections = (data:{ item:string, index:number }) => {
|
|
161
|
+
switch(data.item){
|
|
162
|
+
case 'market':
|
|
163
|
+
return (
|
|
164
|
+
<View type='row' style={{ padding:10 }}>
|
|
165
|
+
<View transparent style={{ flex:1 }}>
|
|
166
|
+
<Text theme='h2'>{market.type == 'Stat' ? market.stat_label : market.type}</Text>
|
|
167
|
+
<Text style={{ marginTop:3 }} theme='description'>{market.description}</Text>
|
|
168
|
+
</View>
|
|
169
|
+
</View>
|
|
170
|
+
)
|
|
171
|
+
case 'athlete':
|
|
172
|
+
if(market.level != 'athlete'){ return <></> }
|
|
173
|
+
const selected_athlete = athletes.find(a => a.athlete_id == resolve.side_id);
|
|
174
|
+
return (
|
|
175
|
+
<View float style={{ margin:10 }}>
|
|
176
|
+
<Button
|
|
177
|
+
style={{ padding:10, flexDirection:'row', alignItems:'center' }}
|
|
178
|
+
onPress={() => {
|
|
179
|
+
setExpandedAthletes(!expand_athletes)
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
<View style={{ flex:1, flexDirection:'row', alignItems:'center' }}>
|
|
183
|
+
{selected_athlete ?
|
|
184
|
+
<AthleteImage
|
|
185
|
+
athlete={selected_athlete}
|
|
186
|
+
size={28}
|
|
187
|
+
/>
|
|
188
|
+
:<></>}
|
|
189
|
+
<View style={{ flex:1 }}>
|
|
190
|
+
{selected_athlete ?
|
|
191
|
+
<Text theme='h1' style={{ marginLeft:5 }}>{selected_athlete?.first_name} {selected_athlete?.last_name}</Text>
|
|
192
|
+
:
|
|
193
|
+
<Text theme='h1'>Select Athlete</Text>
|
|
194
|
+
}
|
|
195
|
+
<Text theme='description' style={{ marginTop:3, marginLeft:5 }}>Unresolved: ${total_unresolved.toFixed(2)}</Text>
|
|
196
|
+
</View>
|
|
197
|
+
</View>
|
|
198
|
+
<Icons.ChevronIcon direction={expand_athletes ? 'up' : 'down'} size={8} color={Colors.text.h1} />
|
|
199
|
+
</Button>
|
|
200
|
+
{expand_athletes ?
|
|
201
|
+
<FlatList
|
|
202
|
+
data={athletes}
|
|
203
|
+
key={`rollback_athletes`}
|
|
204
|
+
renderItem={renderAthletes}
|
|
205
|
+
keyExtractor={(item) => item.athlete_id.toString()}
|
|
206
|
+
/>
|
|
207
|
+
:<></>}
|
|
208
|
+
</View>
|
|
209
|
+
)
|
|
210
|
+
case 'team':
|
|
211
|
+
if(market.level != 'team'){ return <></> }
|
|
212
|
+
return (
|
|
213
|
+
<></>
|
|
214
|
+
)
|
|
215
|
+
case 'event_form':
|
|
216
|
+
if(market.level != 'event'){ return <></> }
|
|
217
|
+
return (
|
|
218
|
+
<View style={{ margin:10 }}>
|
|
219
|
+
<DropDown
|
|
220
|
+
onOptionSelect={(option) => setResolve({ ...resolve, winnings_side: option })}
|
|
221
|
+
dropdown_options={[
|
|
222
|
+
{ value: 'winnings_side', eligible_options: [ ...market.side_options.map(so => so.side), 'draw' ] }
|
|
223
|
+
]}
|
|
224
|
+
selected_value={winnings_side ?? ''}
|
|
225
|
+
|
|
226
|
+
/>
|
|
227
|
+
{winnings_side == 'draw' ?
|
|
228
|
+
<View float style={{ margin:10, padding:10 }}>
|
|
229
|
+
<View transparent type='row' style={{ }}>
|
|
230
|
+
<View transparent style={{ flex:1}}>
|
|
231
|
+
<Text theme='h1'>No Bet</Text>
|
|
232
|
+
<Text theme='description' style={{ marginTop:3}}>Is this market a no bet (i.e., void?)</Text>
|
|
233
|
+
</View>
|
|
234
|
+
<Switch
|
|
235
|
+
value={no_bet ?? false}
|
|
236
|
+
switch_type='on_off'
|
|
237
|
+
onChange={(val) => setResolve({ ...resolve, no_bet: val })}
|
|
238
|
+
/>
|
|
239
|
+
</View>
|
|
240
|
+
{no_bet ?
|
|
241
|
+
<View type='input' style={{ margin:10 }}>
|
|
242
|
+
<TextInput
|
|
243
|
+
value={no_bet_reason ?? ''}
|
|
244
|
+
|
|
245
|
+
placeholder='Enter reason for no bet'
|
|
246
|
+
|
|
247
|
+
onChangeText={(text) => setResolve({ ...resolve, no_bet_reason: text })}
|
|
248
|
+
/>
|
|
249
|
+
</View>
|
|
250
|
+
:<></>}
|
|
251
|
+
</View>
|
|
252
|
+
:<></>}
|
|
253
|
+
</View>
|
|
254
|
+
)
|
|
255
|
+
case 'event_stat_form':
|
|
256
|
+
if(market.resolver != 'res_event_stat'){ return <></> }
|
|
257
|
+
return (
|
|
258
|
+
<View float style={{ margin:10 }}>
|
|
259
|
+
<View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10 }}>
|
|
260
|
+
<View transparent style={{ flex:1 }}>
|
|
261
|
+
<Text theme='h1'>{market.stat_label}</Text>
|
|
262
|
+
<Text theme='description' style={{ marginTop:3 }}>Enter the value for {market.stat_label} below</Text>
|
|
263
|
+
</View>
|
|
264
|
+
</View>
|
|
265
|
+
<View type='input' style={{ margin:10 }}>
|
|
266
|
+
<TextInput
|
|
267
|
+
value={event_stat_value ?? ''}
|
|
268
|
+
|
|
269
|
+
placeholder='Enter Stat Value Here'
|
|
270
|
+
style={{ textAlign:'center' }}
|
|
271
|
+
onChangeText={(text) => setResolve({ ...resolve, event_stat_value: text })}
|
|
272
|
+
/>
|
|
273
|
+
</View>
|
|
274
|
+
</View>
|
|
275
|
+
)
|
|
276
|
+
case 'stat_form':
|
|
277
|
+
if(market.resolver != 'res_event_athlete_stat'){ return <></> }
|
|
278
|
+
return (
|
|
279
|
+
<View float style={{ margin:10 }}>
|
|
280
|
+
<View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10 }}>
|
|
281
|
+
<View transparent style={{ flex:1 }}>
|
|
282
|
+
<Text theme='h1'>{market.stat_label}</Text>
|
|
283
|
+
<Text theme='description' style={{ marginTop:3 }}>Enter the value for {market.stat_label} below</Text>
|
|
284
|
+
</View>
|
|
285
|
+
</View>
|
|
286
|
+
<View type='input' style={{ margin:10 }}>
|
|
287
|
+
<TextInput
|
|
288
|
+
value={stat_value ?? ''}
|
|
289
|
+
|
|
290
|
+
placeholder='Enter Stat Value Here'
|
|
291
|
+
style={{ textAlign:'center' }}
|
|
292
|
+
onChangeText={(text) => setResolve({ ...resolve, stat_value: text })}
|
|
293
|
+
/>
|
|
294
|
+
</View>
|
|
295
|
+
</View>
|
|
296
|
+
)
|
|
297
|
+
default: return <></>
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
return (
|
|
303
|
+
<View float style={{flex:1}}>
|
|
304
|
+
<View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10 }}>
|
|
305
|
+
<View transparent style={{ flex:1 }}>
|
|
306
|
+
<Text theme='h1'>Resolve Market Form</Text>
|
|
307
|
+
<Text theme='description' style={{ marginTop:3 }}>{contest_title}</Text>
|
|
308
|
+
</View>
|
|
309
|
+
<Button
|
|
310
|
+
title='X'
|
|
311
|
+
style={{ padding:10 }}
|
|
312
|
+
float
|
|
313
|
+
onPress={() => onClose()}
|
|
314
|
+
/>
|
|
315
|
+
</View>
|
|
316
|
+
<View style={{ flex:1 }}>
|
|
317
|
+
<FlatList
|
|
318
|
+
data={sections}
|
|
319
|
+
key='section_list_resolve'
|
|
320
|
+
keyExtractor={(item) => item}
|
|
321
|
+
renderItem={renderSections}
|
|
322
|
+
/>
|
|
323
|
+
</View>
|
|
324
|
+
<View>
|
|
325
|
+
<View style={{ padding:10 }}>
|
|
326
|
+
<Text theme='h2'>Resolution is allowed if there are unsettled positions</Text>
|
|
327
|
+
</View>
|
|
328
|
+
<View type='row' style={{ borderBottomWidth:1, borderColor:Colors.borders.light }}>
|
|
329
|
+
<View style={{ padding:10, flex:1 }}>
|
|
330
|
+
<Text theme='h1' color={Colors.text.h1}>${total_volume.toFixed(2)}</Text>
|
|
331
|
+
<Text theme='description' style={{ marginTop:3 }}>Volume</Text>
|
|
332
|
+
</View>
|
|
333
|
+
<View style={{ padding:10, flex:1 }}>
|
|
334
|
+
<Text theme='h1'>${total_unresolved.toFixed(2)}</Text>
|
|
335
|
+
<Text theme='description' style={{ marginTop:3 }}>Unresolved</Text>
|
|
336
|
+
</View>
|
|
337
|
+
|
|
338
|
+
</View>
|
|
339
|
+
</View>
|
|
340
|
+
|
|
341
|
+
<View type='footer' style={{ flexDirection:'row', padding:10, alignItems:'center' }}>
|
|
342
|
+
<Button
|
|
343
|
+
style={{ flex:1, opacity: action_loading || !is_valid? 0.5:1 }}
|
|
344
|
+
disabled={!is_valid || action_loading}
|
|
345
|
+
type='success'
|
|
346
|
+
title='RESOLVE POSITIONS'
|
|
347
|
+
onPress={() => confirmResolve()}
|
|
348
|
+
/>
|
|
349
|
+
</View>
|
|
350
|
+
</View>
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export default MarketResolveForm
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { Button, Text, View } from "../../../Components/Themed";
|
|
3
|
+
import type { AthleteProps, MarketProps, MarketStatsProps, TeamProps } from '../../../types';
|
|
4
|
+
import { FlatList } from 'react-native';
|
|
5
|
+
import { AthleteImage, TeamImage } from '../../../Components/Jerseys';
|
|
6
|
+
import { Checkbox, Icons } from '../../../Components';
|
|
7
|
+
import { useColors } from '../../../constants/useColors';
|
|
8
|
+
import { MarketComponentHelpers } from '../../api';
|
|
9
|
+
|
|
10
|
+
type MarketRollbackFormProps = {
|
|
11
|
+
contest_title:string,
|
|
12
|
+
contest_type:string,
|
|
13
|
+
contest_id:string,
|
|
14
|
+
market:MarketProps,
|
|
15
|
+
athletes:AthleteProps[],
|
|
16
|
+
teams:TeamProps[],
|
|
17
|
+
side_type?:string,
|
|
18
|
+
side_id?:string,
|
|
19
|
+
market_stats:MarketStatsProps[],
|
|
20
|
+
onClose:() => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const MarketRollbackForm = ({ contest_title, side_type, side_id, teams, athletes, market_stats, contest_id, contest_type, market, onClose }:MarketRollbackFormProps) => {
|
|
24
|
+
const Colors = useColors();
|
|
25
|
+
const [ expand_athletes, setExpandedAthletes ] = useState(false);
|
|
26
|
+
//const [ expand_teams, setExpandedTeams ] = useState(false);
|
|
27
|
+
const [ rollback_form, setRollbackForm ] = useState<{
|
|
28
|
+
action_loading:boolean,
|
|
29
|
+
side_id?:string,
|
|
30
|
+
side_type?:string
|
|
31
|
+
}>({
|
|
32
|
+
action_loading: false
|
|
33
|
+
});
|
|
34
|
+
const { action_loading } = rollback_form
|
|
35
|
+
let rollback_stats = market_stats.filter(s => s.market_id == market.market_id);
|
|
36
|
+
if(rollback_form.side_type && rollback_form.side_id){
|
|
37
|
+
rollback_stats = rollback_stats.filter(r => r.side_type == rollback_form.side_type && r.side_id == rollback_form.side_id);
|
|
38
|
+
}
|
|
39
|
+
const { total_volume, total_paid } = MarketComponentHelpers.getReconFromMarketStats(rollback_stats);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
setRollbackForm({ action_loading: false, side_id, side_type });
|
|
43
|
+
},[contest_id, contest_type, market?.market_id, side_type, side_id])
|
|
44
|
+
|
|
45
|
+
const isValid = () => {
|
|
46
|
+
if(!contest_id || !contest_type){ return false }
|
|
47
|
+
if(!market){ return false }
|
|
48
|
+
if(market.level == 'athlete' && rollback_form.side_type != 'athlete'){ return false }
|
|
49
|
+
if(market.level == 'athlete' && !rollback_form.side_id){ return false }
|
|
50
|
+
if(market.level == 'team' && rollback_form.side_type != 'team'){ return false }
|
|
51
|
+
if(market.level == 'team' && !rollback_form.side_id){ return false }
|
|
52
|
+
if(total_paid == 0){ return false }
|
|
53
|
+
return true
|
|
54
|
+
}
|
|
55
|
+
const is_valid = isValid();
|
|
56
|
+
|
|
57
|
+
const renderTeams = (data:{ item:TeamProps, index:number}) => {
|
|
58
|
+
return (
|
|
59
|
+
<Button style={{ padding:10, flexDirection:'row', alignItems:'center' }}>
|
|
60
|
+
<TeamImage
|
|
61
|
+
team={data.item}
|
|
62
|
+
size={14}
|
|
63
|
+
/>
|
|
64
|
+
<View style={{ flex:1, marginLeft:10 }}>
|
|
65
|
+
<Text theme='h1'>{data.item.market_name} {data.item.name}</Text>
|
|
66
|
+
</View>
|
|
67
|
+
</Button>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const renderAthletes = (data:{ item:AthleteProps, index:number}) => {
|
|
72
|
+
const selected = rollback_form.side_id == data.item.athlete_id ? true : false
|
|
73
|
+
const stats = market_stats.filter(s => s.market_id == market.market_id && s.side_type == 'athlete' && s.side_id == data.item.athlete_id);
|
|
74
|
+
const agg_stats = MarketComponentHelpers.getReconFromMarketStats(stats);
|
|
75
|
+
return (
|
|
76
|
+
<Button style={{ padding:10, flexDirection:'row', alignItems:'center', borderBottomWidth:1, borderColor:Colors.borders.light, borderRadius:0 }} onPress={() => {
|
|
77
|
+
if(selected){ setRollbackForm({ ...rollback_form, side_id: undefined }) }
|
|
78
|
+
else { setRollbackForm({ ...rollback_form, side_type: 'athlete', side_id: data.item.athlete_id }) }
|
|
79
|
+
setExpandedAthletes(false);
|
|
80
|
+
}}>
|
|
81
|
+
<AthleteImage
|
|
82
|
+
athlete={data.item}
|
|
83
|
+
size={28}
|
|
84
|
+
/>
|
|
85
|
+
<View style={{ flex:1, marginLeft:10 }}>
|
|
86
|
+
<Text theme='h1'>{data.item.first_name} {data.item.last_name}</Text>
|
|
87
|
+
<Text theme='description' style={{ marginTop:3 }}>Volume: ${agg_stats.total_volume.toFixed(2)} - Paid Out: {agg_stats.total_paid.toFixed(2)}</Text>
|
|
88
|
+
</View>
|
|
89
|
+
<Checkbox
|
|
90
|
+
checked={selected}
|
|
91
|
+
disabled
|
|
92
|
+
style={{ marginLeft:5 }}
|
|
93
|
+
onSelect={() => console.log('')}
|
|
94
|
+
/>
|
|
95
|
+
</Button>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const selected_athlete = athletes.find(a => a.athlete_id == rollback_form.side_id);
|
|
100
|
+
//const selected_team = teams.find(t => t.team_id == rollback_form.side_id);
|
|
101
|
+
|
|
102
|
+
return (
|
|
103
|
+
<View float style={{ flex:1 }}>
|
|
104
|
+
<View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10 }}>
|
|
105
|
+
<View transparent style={{ flex:1 }}>
|
|
106
|
+
<Text theme='h1'>Rollback Market Form</Text>
|
|
107
|
+
<Text theme='description' style={{ marginTop:3 }}>{contest_title}</Text>
|
|
108
|
+
</View>
|
|
109
|
+
<Button
|
|
110
|
+
title='X'
|
|
111
|
+
style={{ padding:10 }}
|
|
112
|
+
float
|
|
113
|
+
onPress={() => onClose()}
|
|
114
|
+
/>
|
|
115
|
+
</View>
|
|
116
|
+
<View type='body' style={{ flex:1 }}>
|
|
117
|
+
<View type='row' style={{ padding:10 }}>
|
|
118
|
+
<View transparent style={{ flex:1 }}>
|
|
119
|
+
<Text theme='h2'>{market.type == 'Stat' ? market.stat_label : market.type}</Text>
|
|
120
|
+
<Text style={{ marginTop:3 }} theme='description'>{market.description}</Text>
|
|
121
|
+
</View>
|
|
122
|
+
</View>
|
|
123
|
+
<View style={{ padding:10 }}>
|
|
124
|
+
{market.level == 'team' ?
|
|
125
|
+
<View>
|
|
126
|
+
|
|
127
|
+
<FlatList
|
|
128
|
+
data={teams}
|
|
129
|
+
key={`rollback_teams`}
|
|
130
|
+
renderItem={renderTeams}
|
|
131
|
+
keyExtractor={(item) => item.team_id.toString()}
|
|
132
|
+
/>
|
|
133
|
+
</View>
|
|
134
|
+
:market.level == 'athlete' ?
|
|
135
|
+
<View float>
|
|
136
|
+
<Button
|
|
137
|
+
style={{ padding:10, flexDirection:'row', alignItems:'center' }}
|
|
138
|
+
onPress={() => {
|
|
139
|
+
setExpandedAthletes(!expand_athletes)
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
<View style={{ flex:1, flexDirection:'row', alignItems:'center' }}>
|
|
143
|
+
{selected_athlete ?
|
|
144
|
+
<AthleteImage
|
|
145
|
+
athlete={selected_athlete}
|
|
146
|
+
size={28}
|
|
147
|
+
/>
|
|
148
|
+
:<></>}
|
|
149
|
+
<View style={{ flex:1 }}>
|
|
150
|
+
{selected_athlete ?
|
|
151
|
+
<Text theme='h1' style={{ marginLeft:5 }}>{selected_athlete?.first_name} {selected_athlete?.last_name}</Text>
|
|
152
|
+
:
|
|
153
|
+
<Text theme='h1'>Select Athlete</Text>
|
|
154
|
+
}
|
|
155
|
+
<Text theme='description' style={{ marginTop:3, marginLeft:5 }}>Volume: ${total_volume.toFixed(2)} - Paid Out: ${total_paid.toFixed(2)}</Text>
|
|
156
|
+
</View>
|
|
157
|
+
</View>
|
|
158
|
+
<Icons.ChevronIcon direction={expand_athletes ? 'up' : 'down'} size={8} color={Colors.text.h1} />
|
|
159
|
+
</Button>
|
|
160
|
+
{expand_athletes ?
|
|
161
|
+
<FlatList
|
|
162
|
+
data={athletes}
|
|
163
|
+
key={`rollback_athletes`}
|
|
164
|
+
renderItem={renderAthletes}
|
|
165
|
+
keyExtractor={(item) => item.athlete_id.toString()}
|
|
166
|
+
/>
|
|
167
|
+
:<></>}
|
|
168
|
+
</View>
|
|
169
|
+
:<></>}
|
|
170
|
+
</View>
|
|
171
|
+
</View>
|
|
172
|
+
<View>
|
|
173
|
+
<View style={{ padding:10 }}>
|
|
174
|
+
<Text theme='h2'>Rollback is allowed if pay outs have occurred</Text>
|
|
175
|
+
</View>
|
|
176
|
+
<View type='row' style={{ borderBottomWidth:1, borderColor:Colors.borders.light }}>
|
|
177
|
+
<View style={{ padding:10, flex:1 }}>
|
|
178
|
+
<Text theme='h1' color={Colors.text.h1}>${total_volume.toFixed(2)}</Text>
|
|
179
|
+
<Text theme='description' style={{ marginTop:3 }}>Volume</Text>
|
|
180
|
+
</View>
|
|
181
|
+
<View style={{ padding:10, flex:1 }}>
|
|
182
|
+
<Text theme='h1'>${total_paid.toFixed(2)}</Text>
|
|
183
|
+
<Text theme='description' style={{ marginTop:3 }}>Paid Out</Text>
|
|
184
|
+
</View>
|
|
185
|
+
|
|
186
|
+
</View>
|
|
187
|
+
</View>
|
|
188
|
+
|
|
189
|
+
<View type='footer' style={{ flexDirection:'row', padding:10, alignItems:'center' }}>
|
|
190
|
+
<Button
|
|
191
|
+
style={{ flex:1, opacity: action_loading || !is_valid? 0.5:1 }}
|
|
192
|
+
disabled={!is_valid || action_loading}
|
|
193
|
+
type='success'
|
|
194
|
+
title='ROLLBACK SETTLEMENTS'
|
|
195
|
+
onPress={() => console.log('ROLLBACK!!!')}
|
|
196
|
+
/>
|
|
197
|
+
</View>
|
|
198
|
+
</View>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export default MarketRollbackForm
|