be-components 0.7.4 → 0.7.6
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/Authenticator/Components/AuthStrategyIdentifier.js +113 -0
- package/lib/commonjs/Authenticator/Components/AuthStrategyIdentifier.js.map +1 -0
- package/lib/commonjs/Authenticator/Components/StrategyForm.js +238 -71
- package/lib/commonjs/Authenticator/Components/StrategyForm.js.map +1 -1
- package/lib/commonjs/Authenticator/index.js +7 -4
- package/lib/commonjs/Authenticator/index.js.map +1 -1
- package/lib/commonjs/Poll/api/index.js +38 -1
- package/lib/commonjs/Poll/api/index.js.map +1 -1
- package/lib/commonjs/Poll/flashmarket/index.js +354 -0
- package/lib/commonjs/Poll/flashmarket/index.js.map +1 -0
- package/lib/commonjs/Poll/index.js +21 -6
- package/lib/commonjs/Poll/index.js.map +1 -1
- package/lib/module/Authenticator/Components/AuthStrategyIdentifier.js +106 -0
- package/lib/module/Authenticator/Components/AuthStrategyIdentifier.js.map +1 -0
- package/lib/module/Authenticator/Components/StrategyForm.js +239 -72
- package/lib/module/Authenticator/Components/StrategyForm.js.map +1 -1
- package/lib/module/Authenticator/index.js +7 -4
- package/lib/module/Authenticator/index.js.map +1 -1
- package/lib/module/Poll/api/index.js +38 -1
- package/lib/module/Poll/api/index.js.map +1 -1
- package/lib/module/Poll/flashmarket/index.js +345 -0
- package/lib/module/Poll/flashmarket/index.js.map +1 -0
- package/lib/module/Poll/index.js +21 -6
- package/lib/module/Poll/index.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/Authenticator/Components/AuthStrategyIdentifier.d.ts +11 -0
- package/lib/typescript/src/Authenticator/Components/AuthStrategyIdentifier.d.ts.map +1 -0
- package/lib/typescript/src/Authenticator/Components/StrategyForm.d.ts +4 -1
- package/lib/typescript/src/Authenticator/Components/StrategyForm.d.ts.map +1 -1
- package/lib/typescript/src/Authenticator/index.d.ts +2 -1
- package/lib/typescript/src/Authenticator/index.d.ts.map +1 -1
- package/lib/typescript/src/Poll/api/index.d.ts +5 -1
- package/lib/typescript/src/Poll/api/index.d.ts.map +1 -1
- package/lib/typescript/src/Poll/flashmarket/index.d.ts +10 -0
- package/lib/typescript/src/Poll/flashmarket/index.d.ts.map +1 -0
- package/lib/typescript/src/Poll/index.d.ts +8 -2
- package/lib/typescript/src/Poll/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Authenticator/Components/AuthStrategyIdentifier.tsx +72 -0
- package/src/Authenticator/Components/StrategyForm.tsx +208 -53
- package/src/Authenticator/api/types.d.ts +2 -1
- package/src/Authenticator/index.tsx +8 -3
- package/src/Poll/api/index.ts +35 -1
- package/src/Poll/flashmarket/index.tsx +231 -0
- package/src/Poll/index.tsx +29 -9
- package/src/index.tsx +1 -0
- package/src/types.d.ts +3 -1
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { ActivityIndicator, View, Image, TouchableOpacity } from "react-native";
|
|
3
|
+
import type { PollCampaignProps, PollOptionProps, PollProps, PollResponseProps, PollSummaryProps } from '../../types';
|
|
4
|
+
import Colors from '../../constants/colors';
|
|
5
|
+
import { Spring, Text, TextInput } from '../../Components';
|
|
6
|
+
import { PollApi, PollCampaignApi, PollResponseApi, PollResponseHelpers } from '../api';
|
|
7
|
+
import { view_styles } from '../../constants/styles';
|
|
8
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
type FlashMarketProps = {
|
|
12
|
+
poll_id:string,
|
|
13
|
+
next_allowed?:boolean,
|
|
14
|
+
player_id?:string,
|
|
15
|
+
onRequestAuthenticate:() => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const MAX_IMAGE_SIZE = 125
|
|
19
|
+
const MAX_OPTION_WIDTH = 200
|
|
20
|
+
|
|
21
|
+
const FlashMarket = ({ poll_id, player_id, onRequestAuthenticate }:FlashMarketProps) => {
|
|
22
|
+
const [ flash_size, setFlashSize ] = useState({ height:0, width:0 });
|
|
23
|
+
const [ data, setData ] = useState<
|
|
24
|
+
{
|
|
25
|
+
loading:boolean,
|
|
26
|
+
poll_campaign?:PollCampaignProps,
|
|
27
|
+
poll?:PollProps,
|
|
28
|
+
poll_options:PollOptionProps[],
|
|
29
|
+
poll_summaries: PollSummaryProps[],
|
|
30
|
+
poll_response?:PollResponseProps,
|
|
31
|
+
show_complete:boolean,
|
|
32
|
+
}
|
|
33
|
+
>({
|
|
34
|
+
loading:false,
|
|
35
|
+
poll_options: [],
|
|
36
|
+
poll_summaries: [],
|
|
37
|
+
show_complete: false
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const { loading, poll, poll_options, poll_summaries, poll_response } = data;
|
|
41
|
+
|
|
42
|
+
let visible_options = poll_options
|
|
43
|
+
if(poll_response && poll_response.status == 'pending'){ visible_options = poll_options.filter(po => po.poll_option_id == poll_response.poll_option_id) }
|
|
44
|
+
|
|
45
|
+
let image_size = flash_size.width * 0.2
|
|
46
|
+
if(image_size > MAX_IMAGE_SIZE){ image_size = MAX_IMAGE_SIZE }
|
|
47
|
+
let option_width = (flash_size.width * 0.8 / 2) - 25
|
|
48
|
+
if(option_width > MAX_OPTION_WIDTH){ option_width = MAX_OPTION_WIDTH }
|
|
49
|
+
|
|
50
|
+
useEffect(( ) => {
|
|
51
|
+
getDataFromServer(poll_id)
|
|
52
|
+
},[poll_id, player_id])
|
|
53
|
+
|
|
54
|
+
const getDataFromServer = async(poll_id:string) => {
|
|
55
|
+
setData({ ...data, loading:true })
|
|
56
|
+
const resp = await PollApi.getPollById(poll_id);
|
|
57
|
+
const pc = await PollCampaignApi.getPollCampaignById(resp.poll.poll_campaign_id)
|
|
58
|
+
let my_response:PollResponseProps | undefined = undefined
|
|
59
|
+
//First if there is a player_id - lets grab from the server first
|
|
60
|
+
if(player_id){
|
|
61
|
+
my_response = await PollResponseApi.getResponseByPollId(poll_id)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if(!my_response){
|
|
65
|
+
//If no-response - check cache
|
|
66
|
+
let cached_response = await AsyncStorage.getItem(`response:${poll_id}`)
|
|
67
|
+
if(cached_response){
|
|
68
|
+
my_response = JSON.parse(cached_response);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
setData({
|
|
72
|
+
loading:false,
|
|
73
|
+
poll_campaign: pc,
|
|
74
|
+
poll: resp.poll,
|
|
75
|
+
poll_options: resp.poll_options,
|
|
76
|
+
poll_summaries: resp.poll_summaries,
|
|
77
|
+
poll_response: my_response,
|
|
78
|
+
show_complete: my_response && my_response?.status != 'pending' ? true : false
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const handleSelectOption = async(po:PollOptionProps) => {
|
|
83
|
+
if(!poll){ return }
|
|
84
|
+
if(poll_response && poll_response.status != 'pending'){ return setData({ ...data, show_complete: true }) }
|
|
85
|
+
let cached_response = await AsyncStorage.getItem(`response:${poll_id}`)
|
|
86
|
+
if(cached_response){
|
|
87
|
+
if(JSON.parse(cached_response).poll_option_id == po.poll_option_id){
|
|
88
|
+
await AsyncStorage.removeItem(`response:${poll_id}`)
|
|
89
|
+
return setData({ ...data, poll_response: undefined })
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
let stake = poll_response?.stake ?? poll.minimum_stake
|
|
93
|
+
let draft_response:PollResponseProps = {
|
|
94
|
+
poll_id:poll.poll_id,
|
|
95
|
+
poll_option_id:po.poll_option_id,
|
|
96
|
+
stake: stake,
|
|
97
|
+
market_type: 'FREE',
|
|
98
|
+
poll_response_id: '',
|
|
99
|
+
player_id: '',
|
|
100
|
+
winnings: 0,
|
|
101
|
+
response_body: {},
|
|
102
|
+
status: 'pending',
|
|
103
|
+
create_datetime: '',
|
|
104
|
+
last_update_datetime: ''
|
|
105
|
+
}
|
|
106
|
+
await AsyncStorage.setItem(`response:${poll_id}`, JSON.stringify(draft_response))
|
|
107
|
+
|
|
108
|
+
setData({
|
|
109
|
+
...data,
|
|
110
|
+
poll_response: draft_response
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const handleSubmit = async() => {
|
|
115
|
+
if(!poll_response){ return }
|
|
116
|
+
if(poll_response.status != 'pending'){ return }
|
|
117
|
+
if(!player_id){ return onRequestAuthenticate() }
|
|
118
|
+
let stake_number = parseFloat(poll_response.stake as string)
|
|
119
|
+
if(isNaN(stake_number)){ return }
|
|
120
|
+
const new_resp = await PollResponseApi.createPollResponse({ ...poll_response, stake: stake_number })
|
|
121
|
+
const updated_ps = PollResponseHelpers.updateSummariesWithResponse(new_resp, poll_summaries)
|
|
122
|
+
setData({
|
|
123
|
+
...data,
|
|
124
|
+
poll_response: new_resp,
|
|
125
|
+
poll_summaries: updated_ps,
|
|
126
|
+
show_complete: true
|
|
127
|
+
})
|
|
128
|
+
await AsyncStorage.removeItem(`response:${poll_id}`)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
//const selected_option = poll_options.find(po => po.poll_option_id == poll_response?.poll_option_id)
|
|
133
|
+
//const selected_summary = poll_summaries.find(ps => ps.poll_option_id == poll_response?.poll_option_id)
|
|
134
|
+
//const correct_option = poll_options.find(po => po.result_ind == 'win');
|
|
135
|
+
//const correct_summary = poll_summaries.find(ps => ps.poll_option_id == correct_option?.poll_option_id);
|
|
136
|
+
|
|
137
|
+
const renderPollOptions = (data:{item:PollOptionProps, show_summary?:boolean, index:number}) => {
|
|
138
|
+
const selected = data.item.poll_option_id == poll_response?.poll_option_id ? true : false
|
|
139
|
+
const poll_summary = poll_summaries.find(ps => ps.poll_option_id == data.item.poll_option_id);
|
|
140
|
+
const color = PollResponseHelpers.getOptionColor(data.item, poll_response)
|
|
141
|
+
return (
|
|
142
|
+
<View>
|
|
143
|
+
|
|
144
|
+
<TouchableOpacity
|
|
145
|
+
//disabled={poll_response && poll_response.status != 'pending' ? true : false}
|
|
146
|
+
style={{ flexDirection:'row', width:option_width, alignItems:'center', margin:5, borderRadius:22, padding:10, borderWidth:selected?1:0, borderColor:Colors.brand.midnight, backgroundColor:color, ...view_styles.float }}
|
|
147
|
+
onPress={() => handleSelectOption(data.item)}>
|
|
148
|
+
{data.show_summary && poll_summary ?
|
|
149
|
+
<View style={{ position:'absolute', top:0, left:0, bottom:0, borderRadius:22, backgroundColor:color, opacity:0.6, width: option_width * poll_summary.pct }}/>
|
|
150
|
+
:<></>}
|
|
151
|
+
<Text style={{ flex:1 }} size={14} color={Colors.brand.midnight} weight={'bold'} textAlign={data.show_summary?'left':'center'}>{data.item.option_name}</Text>
|
|
152
|
+
{data.show_summary && poll_summary ?
|
|
153
|
+
<Text style={{ marginLeft:10, padding:5, borderRadius:selected?100:0, backgroundColor:selected?Colors.shades.white:undefined, ...view_styles.float }} size={12} color={Colors.brand.midnight} weight='bold' >{(poll_summary.pct*100).toFixed()}%</Text>
|
|
154
|
+
:<></>}
|
|
155
|
+
</TouchableOpacity>
|
|
156
|
+
</View>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if(loading || !poll){
|
|
161
|
+
return (
|
|
162
|
+
<View>
|
|
163
|
+
<ActivityIndicator size={'large'} color={Colors.brand.midnight}/>
|
|
164
|
+
</View>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<View style={{ flex:1 }}>
|
|
170
|
+
<View style={{ backgroundColor:Colors.shades.white, flexDirection:'row' }} onLayout={(ev) => {
|
|
171
|
+
const { height, width } = ev.nativeEvent.layout;
|
|
172
|
+
setFlashSize({ height, width })
|
|
173
|
+
}}>
|
|
174
|
+
{!poll_response || poll_response.status != 'pending' ?
|
|
175
|
+
<View style={{ padding:10 }}>
|
|
176
|
+
<Image
|
|
177
|
+
source={{ uri: poll.poll_image?.url ?? 'https://res.cloudinary.com/hoabts6mc/image/upload/v1718979933/question_mark_ro0ac5.webp' }}
|
|
178
|
+
style={{ height:image_size, width:image_size }}
|
|
179
|
+
resizeMode='cover'
|
|
180
|
+
/>
|
|
181
|
+
</View>
|
|
182
|
+
:<></>}
|
|
183
|
+
<View style={{ flex:1 }} nativeID='question'>
|
|
184
|
+
<View style={{ padding:10, borderBottomWidth:1, borderBottomColor:Colors.shades.shade600 }}>
|
|
185
|
+
<Text size={16} color={Colors.brand.midnight} weight='bold'>{poll.poll_question}</Text>
|
|
186
|
+
</View>
|
|
187
|
+
<View nativeID='poll_options' style={{ flex:1, padding:5, flexDirection:'row', flexWrap:'wrap', justifyContent:'center', alignItems:'center'}}>
|
|
188
|
+
{visible_options.sort((a,b) => a.priority - b.priority).map((po, i) => {
|
|
189
|
+
return renderPollOptions({ item:po, index:i, show_summary:poll_response && poll_response.status != 'pending' ? true : false })
|
|
190
|
+
})}
|
|
191
|
+
</View>
|
|
192
|
+
</View>
|
|
193
|
+
{poll_response?.status == 'pending' ?
|
|
194
|
+
<Spring
|
|
195
|
+
slide='horizontal'
|
|
196
|
+
to={0}
|
|
197
|
+
from={100}
|
|
198
|
+
>
|
|
199
|
+
<View style={{justifyContent:'space-between', backgroundColor:Colors.shades.shade600 }}>
|
|
200
|
+
<View style={{ padding:10, borderBottomWidth:1, borderBottomColor:Colors.shades.shade100 }}>
|
|
201
|
+
<Text size={16} color={Colors.brand.midnight} textAlign='center' weight='bold'>{poll.confidence_allowed ? 'HOW MUCH?': 'ARE YOU SURE?'}</Text>
|
|
202
|
+
</View>
|
|
203
|
+
{poll.confidence_allowed ?
|
|
204
|
+
<View style={{ flex:1, padding:5 }}>
|
|
205
|
+
<View style={{flexDirection:'row', backgroundColor:Colors.shades.white, borderRadius:22 }}>
|
|
206
|
+
<Text style={{ padding:10 }}>{poll.market_type == 'FOR_MONEY' ? '$' : 'E'}</Text>
|
|
207
|
+
<TextInput
|
|
208
|
+
style={{ padding:10, borderWidth:0, borderTopLeftRadius:0, borderBottomLeftRadius:0, backgroundColor:'transparent', width: flash_size.width * 0.22,}}
|
|
209
|
+
autoFocus
|
|
210
|
+
value={poll_response.stake as string}
|
|
211
|
+
onChangeText={(text) => setData({
|
|
212
|
+
...data,
|
|
213
|
+
poll_response: { ...poll_response, stake:text }
|
|
214
|
+
})}
|
|
215
|
+
/>
|
|
216
|
+
</View>
|
|
217
|
+
</View>
|
|
218
|
+
:<View style={{flex:1}} />}
|
|
219
|
+
<TouchableOpacity style={{ marginTop:10, backgroundColor:Colors.utility.success, padding:10, paddingLeft:20, paddingRight:20, justifyContent:'center', alignItems:'center' }}
|
|
220
|
+
onPress={() => handleSubmit()}>
|
|
221
|
+
<Text weight='bold' size={14} color={Colors.shades.white}>SUBMIT</Text>
|
|
222
|
+
</TouchableOpacity>
|
|
223
|
+
</View>
|
|
224
|
+
</Spring>
|
|
225
|
+
:<></>}
|
|
226
|
+
</View>
|
|
227
|
+
</View>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export default FlashMarket
|
package/src/Poll/index.tsx
CHANGED
|
@@ -1,25 +1,45 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import CampaignPlay from "./components/CampaignPlay"
|
|
3
3
|
import { PollCampaignApi } from './api';
|
|
4
|
+
import FlashMarket from './flashmarket';
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
type PollCampaignModuleProps = {
|
|
7
|
-
poll_campaign_id
|
|
8
|
+
poll_campaign_id?:string,
|
|
9
|
+
poll_id?:string,
|
|
10
|
+
player_id?:string,
|
|
11
|
+
height?:number,
|
|
12
|
+
width?:number,
|
|
13
|
+
type: 'campaign' | 'poll',
|
|
14
|
+
onRequestAuthenticate: () => void
|
|
8
15
|
}
|
|
9
|
-
const PollCampaign = ({ poll_campaign_id }: PollCampaignModuleProps ) => {
|
|
16
|
+
const PollCampaign = ({ poll_campaign_id, poll_id, type, player_id, onRequestAuthenticate }: PollCampaignModuleProps ) => {
|
|
10
17
|
const [ loaded, setLoaded ] = useState(false);
|
|
11
18
|
useEffect(() => {
|
|
12
19
|
PollCampaignApi.setEnvironment();
|
|
13
20
|
setLoaded(true)
|
|
14
21
|
},[])
|
|
15
22
|
if(!loaded){ return <></> }
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
if(type == 'campaign' && poll_campaign_id){
|
|
24
|
+
return (
|
|
25
|
+
<CampaignPlay
|
|
26
|
+
onRequestAuthenticate={() => console.log('')}
|
|
27
|
+
poll_campaign_id={poll_campaign_id}
|
|
28
|
+
onFinished={() => console.log('finished!!')}
|
|
29
|
+
/>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
if(type == 'poll' && poll_id){
|
|
33
|
+
return (
|
|
34
|
+
<FlashMarket
|
|
35
|
+
poll_id={poll_id}
|
|
36
|
+
player_id={player_id}
|
|
37
|
+
onRequestAuthenticate={onRequestAuthenticate}
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
return <></>
|
|
42
|
+
|
|
23
43
|
}
|
|
24
44
|
|
|
25
45
|
export default PollCampaign
|
package/src/index.tsx
CHANGED
package/src/types.d.ts
CHANGED
|
@@ -357,6 +357,7 @@ export interface PollProps {
|
|
|
357
357
|
poll_id:string,
|
|
358
358
|
poll_campaign_id:string,
|
|
359
359
|
poll_question: string,
|
|
360
|
+
market_type:'FOR_MONEY'|'FREE',
|
|
360
361
|
status:string,
|
|
361
362
|
coupon_campaign_id?:string,
|
|
362
363
|
coupon_payout_type?:any,
|
|
@@ -373,6 +374,7 @@ export interface PollProps {
|
|
|
373
374
|
hidden_clue?:string,
|
|
374
375
|
minimum_stake:number,
|
|
375
376
|
priority: number,
|
|
377
|
+
confidence_allowed?: boolean,
|
|
376
378
|
end_datetime: any,
|
|
377
379
|
winning_option_id?:string,
|
|
378
380
|
winning_value?:string,
|
|
@@ -423,7 +425,7 @@ export interface PollResponseProps {
|
|
|
423
425
|
email?:string,
|
|
424
426
|
device_id?:string,
|
|
425
427
|
parimutuel_odds?:number,
|
|
426
|
-
stake:number,
|
|
428
|
+
stake:number|string,
|
|
427
429
|
market_type: 'FREE' | 'FOR_MONEY',
|
|
428
430
|
result_ind?:'win'|'lose'|'draw',
|
|
429
431
|
winnings:number,
|