be-components 5.7.6 → 5.7.8

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.
Files changed (134) hide show
  1. package/lib/commonjs/Competition/components/AthleteMarketCard.js +1 -1
  2. package/lib/commonjs/Competition/components/MatchMarketCard.js +2 -2
  3. package/lib/commonjs/Components/Jerseys.js +25 -13
  4. package/lib/commonjs/Components/Jerseys.js.map +1 -1
  5. package/lib/commonjs/FlashMarket/FlashHolder.js +357 -0
  6. package/lib/commonjs/FlashMarket/FlashHolder.js.map +1 -0
  7. package/lib/commonjs/FlashMarket/api/index.js +9 -0
  8. package/lib/commonjs/FlashMarket/api/index.js.map +1 -1
  9. package/lib/commonjs/FlashMarket/components/MarketTimer.js +39 -0
  10. package/lib/commonjs/FlashMarket/components/MarketTimer.js.map +1 -0
  11. package/lib/commonjs/FlashMarket/components/ProgressBar.js +100 -0
  12. package/lib/commonjs/FlashMarket/components/ProgressBar.js.map +1 -0
  13. package/lib/commonjs/FlashMarket/components/ProgressTimer.js +74 -0
  14. package/lib/commonjs/FlashMarket/components/ProgressTimer.js.map +1 -0
  15. package/lib/commonjs/FlashMarket/index.js +72 -159
  16. package/lib/commonjs/FlashMarket/index.js.map +1 -1
  17. package/lib/commonjs/GolfScoreboard/components/LeaderBetSelector.js +1 -1
  18. package/lib/commonjs/GolfScoreboard/components/LeaderBetsList.js +1 -1
  19. package/lib/commonjs/GolfScoreboard/index.js +3 -3
  20. package/lib/commonjs/MarketComponents/components/AthleteMarket/index.js +1 -1
  21. package/lib/commonjs/MarketComponents/components/AthleteTournamentMarket/index.js +4 -2
  22. package/lib/commonjs/MarketComponents/components/AthleteTournamentMarket/index.js.map +1 -1
  23. package/lib/commonjs/MarketComponents/components/MatchMarket/index.js +1 -1
  24. package/lib/commonjs/MarketComponents/components/TournamentMarket/index.js +1 -0
  25. package/lib/commonjs/MarketComponents/components/TournamentMarket/index.js.map +1 -1
  26. package/lib/commonjs/SocialComponents/SocialOrderCard.js +1 -1
  27. package/lib/commonjs/Ticker/index.js +1 -1
  28. package/lib/commonjs/index.js +7 -0
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/module/Competition/components/AthleteMarketCard.js +1 -1
  31. package/lib/module/Competition/components/MatchMarketCard.js +2 -2
  32. package/lib/module/Components/Jerseys.js +24 -12
  33. package/lib/module/Components/Jerseys.js.map +1 -1
  34. package/lib/module/FlashMarket/FlashHolder.js +348 -0
  35. package/lib/module/FlashMarket/FlashHolder.js.map +1 -0
  36. package/lib/module/FlashMarket/api/index.js +9 -0
  37. package/lib/module/FlashMarket/api/index.js.map +1 -1
  38. package/lib/module/FlashMarket/components/MarketTimer.js +32 -0
  39. package/lib/module/FlashMarket/components/MarketTimer.js.map +1 -0
  40. package/lib/module/FlashMarket/components/ProgressBar.js +92 -0
  41. package/lib/module/FlashMarket/components/ProgressBar.js.map +1 -0
  42. package/lib/module/FlashMarket/components/ProgressTimer.js +66 -0
  43. package/lib/module/FlashMarket/components/ProgressTimer.js.map +1 -0
  44. package/lib/module/FlashMarket/index.js +72 -159
  45. package/lib/module/FlashMarket/index.js.map +1 -1
  46. package/lib/module/GolfScoreboard/components/LeaderBetSelector.js +1 -1
  47. package/lib/module/GolfScoreboard/components/LeaderBetsList.js +1 -1
  48. package/lib/module/GolfScoreboard/index.js +3 -3
  49. package/lib/module/MarketComponents/components/AthleteMarket/index.js +1 -1
  50. package/lib/module/MarketComponents/components/AthleteTournamentMarket/index.js +4 -2
  51. package/lib/module/MarketComponents/components/AthleteTournamentMarket/index.js.map +1 -1
  52. package/lib/module/MarketComponents/components/MatchMarket/index.js +1 -1
  53. package/lib/module/MarketComponents/components/TournamentMarket/index.js +1 -0
  54. package/lib/module/MarketComponents/components/TournamentMarket/index.js.map +1 -1
  55. package/lib/module/SocialComponents/SocialOrderCard.js +1 -1
  56. package/lib/module/Ticker/index.js +1 -1
  57. package/lib/module/index.js +2 -1
  58. package/lib/module/index.js.map +1 -1
  59. package/lib/typescript/lib/commonjs/Components/Jerseys.d.ts.map +1 -1
  60. package/lib/typescript/lib/commonjs/FlashMarket/FlashHolder.d.ts +18 -0
  61. package/lib/typescript/lib/commonjs/FlashMarket/FlashHolder.d.ts.map +1 -0
  62. package/lib/typescript/lib/commonjs/FlashMarket/api/index.d.ts +1 -0
  63. package/lib/typescript/lib/commonjs/FlashMarket/api/index.d.ts.map +1 -1
  64. package/lib/typescript/lib/commonjs/FlashMarket/components/MarketTimer.d.ts +7 -0
  65. package/lib/typescript/lib/commonjs/FlashMarket/components/MarketTimer.d.ts.map +1 -0
  66. package/lib/typescript/lib/commonjs/FlashMarket/components/ProgressBar.d.ts +17 -0
  67. package/lib/typescript/lib/commonjs/FlashMarket/components/ProgressBar.d.ts.map +1 -0
  68. package/lib/typescript/lib/commonjs/FlashMarket/components/ProgressTimer.d.ts +11 -0
  69. package/lib/typescript/lib/commonjs/FlashMarket/components/ProgressTimer.d.ts.map +1 -0
  70. package/lib/typescript/lib/commonjs/FlashMarket/index.d.ts +10 -2
  71. package/lib/typescript/lib/commonjs/FlashMarket/index.d.ts.map +1 -1
  72. package/lib/typescript/lib/commonjs/MarketComponents/components/TournamentMarket/index.d.ts.map +1 -1
  73. package/lib/typescript/lib/commonjs/index.d.ts +1 -0
  74. package/lib/typescript/lib/commonjs/index.d.ts.map +1 -1
  75. package/lib/typescript/lib/module/Components/Jerseys.d.ts +2 -3
  76. package/lib/typescript/lib/module/Components/Jerseys.d.ts.map +1 -1
  77. package/lib/typescript/lib/module/FlashMarket/FlashHolder.d.ts +18 -0
  78. package/lib/typescript/lib/module/FlashMarket/FlashHolder.d.ts.map +1 -0
  79. package/lib/typescript/lib/module/FlashMarket/api/index.d.ts +1 -0
  80. package/lib/typescript/lib/module/FlashMarket/api/index.d.ts.map +1 -1
  81. package/lib/typescript/lib/module/FlashMarket/components/MarketTimer.d.ts +9 -0
  82. package/lib/typescript/lib/module/FlashMarket/components/MarketTimer.d.ts.map +1 -0
  83. package/lib/typescript/lib/module/FlashMarket/components/ProgressBar.d.ts +18 -0
  84. package/lib/typescript/lib/module/FlashMarket/components/ProgressBar.d.ts.map +1 -0
  85. package/lib/typescript/lib/module/FlashMarket/components/ProgressTimer.d.ts +13 -0
  86. package/lib/typescript/lib/module/FlashMarket/components/ProgressTimer.d.ts.map +1 -0
  87. package/lib/typescript/lib/module/FlashMarket/index.d.ts +10 -2
  88. package/lib/typescript/lib/module/FlashMarket/index.d.ts.map +1 -1
  89. package/lib/typescript/lib/module/MarketComponents/components/AthleteTournamentMarket/index.d.ts +2 -1
  90. package/lib/typescript/lib/module/MarketComponents/components/AthleteTournamentMarket/index.d.ts.map +1 -1
  91. package/lib/typescript/lib/module/MarketComponents/components/TournamentMarket/index.d.ts.map +1 -1
  92. package/lib/typescript/lib/module/index.d.ts +2 -1
  93. package/lib/typescript/lib/module/index.d.ts.map +1 -1
  94. package/lib/typescript/src/Components/Jerseys.d.ts.map +1 -1
  95. package/lib/typescript/src/FlashMarket/FlashHolder.d.ts +25 -0
  96. package/lib/typescript/src/FlashMarket/FlashHolder.d.ts.map +1 -0
  97. package/lib/typescript/src/FlashMarket/api/index.d.ts +1 -0
  98. package/lib/typescript/src/FlashMarket/api/index.d.ts.map +1 -1
  99. package/lib/typescript/src/FlashMarket/components/MarketTimer.d.ts +9 -0
  100. package/lib/typescript/src/FlashMarket/components/MarketTimer.d.ts.map +1 -0
  101. package/lib/typescript/src/FlashMarket/components/ProgressBar.d.ts +21 -0
  102. package/lib/typescript/src/FlashMarket/components/ProgressBar.d.ts.map +1 -0
  103. package/lib/typescript/src/FlashMarket/components/ProgressTimer.d.ts +13 -0
  104. package/lib/typescript/src/FlashMarket/components/ProgressTimer.d.ts.map +1 -0
  105. package/lib/typescript/src/FlashMarket/index.d.ts +12 -4
  106. package/lib/typescript/src/FlashMarket/index.d.ts.map +1 -1
  107. package/lib/typescript/src/MarketComponents/components/AthleteTournamentMarket/index.d.ts +3 -2
  108. package/lib/typescript/src/MarketComponents/components/AthleteTournamentMarket/index.d.ts.map +1 -1
  109. package/lib/typescript/src/MarketComponents/components/TournamentMarket/index.d.ts.map +1 -1
  110. package/lib/typescript/src/MarketComponents/index.d.ts +2 -1
  111. package/lib/typescript/src/MarketComponents/index.d.ts.map +1 -1
  112. package/lib/typescript/src/index.d.ts +2 -1
  113. package/lib/typescript/src/index.d.ts.map +1 -1
  114. package/package.json +2 -2
  115. package/src/Competition/components/AthleteMarketCard.tsx +1 -1
  116. package/src/Competition/components/MatchMarketCard.tsx +2 -2
  117. package/src/Components/Jerseys.tsx +12 -8
  118. package/src/FlashMarket/FlashHolder.tsx +288 -0
  119. package/src/FlashMarket/api/index.ts +9 -0
  120. package/src/FlashMarket/components/MarketTimer.tsx +39 -0
  121. package/src/FlashMarket/components/ProgressBar.tsx +61 -0
  122. package/src/FlashMarket/components/ProgressTimer.tsx +69 -0
  123. package/src/FlashMarket/index.tsx +48 -126
  124. package/src/GolfScoreboard/components/LeaderBetSelector.tsx +1 -1
  125. package/src/GolfScoreboard/components/LeaderBetsList.tsx +1 -1
  126. package/src/GolfScoreboard/index.tsx +3 -3
  127. package/src/MarketComponents/components/AthleteMarket/index.tsx +1 -1
  128. package/src/MarketComponents/components/AthleteTournamentMarket/index.tsx +6 -4
  129. package/src/MarketComponents/components/MatchMarket/index.tsx +1 -1
  130. package/src/MarketComponents/components/TournamentMarket/index.tsx +1 -0
  131. package/src/SocialComponents/SocialOrderCard.tsx +1 -1
  132. package/src/Ticker/index.tsx +1 -1
  133. package/src/index.tsx +2 -0
  134. package/src/types.d.ts +5 -0
@@ -0,0 +1,288 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Button, Text, View } from "../Components/Themed"
3
+ import { FlashMarketApi } from './api';
4
+ import type { FlashMarketFeeProps, LocationProps, MyPlayerProps, PollCampaignProps, PollOptionProps, PollProps, PollSummaryProps } from '../types';
5
+ import { ActivityIndicator, FlatList, Image } from 'react-native';
6
+ import { useColors } from '../constants/useColors';
7
+ import FlashMarket from '.';
8
+ import { Icons } from '../Components';
9
+ import SocketManager from '../Socket';
10
+ import moment from 'moment-mini';
11
+
12
+ type FlashHolderProps = {
13
+ league_id?:string,
14
+ player_id?:string,
15
+ distinct_id?:string,
16
+ player?:MyPlayerProps
17
+ contest_type?:string,
18
+ contest_id?:string,
19
+ side_type?:string,
20
+ location?:LocationProps,
21
+ side_id?:string,
22
+ poll_id?:string,
23
+ onRequestLocation:() => void,
24
+ onFocusPosition?: (position:{ x:number, y:number, width:number, height:number }) => void,
25
+ onRequestAuthenticate: () => void
26
+ }
27
+ const sections = [ 'selector','flash_market','options','footer' ]
28
+ const FlashHolder = ({ distinct_id, league_id, player_id, player, location, contest_type, contest_id, side_type, side_id, poll_id, onRequestAuthenticate, onFocusPosition, onRequestLocation } : FlashHolderProps) => {
29
+ const Colors = useColors();
30
+ const [ needs_reload, setNeedsReload ] = useState(false);
31
+ const [ socket_campaigns, setSocketCampaigns ] = useState<PollCampaignProps[]>([]);
32
+ const [ socket_poll_options, setSocketPollOptions ] = useState<{
33
+ options:PollOptionProps[],
34
+ summaries:PollSummaryProps[]
35
+ }>({
36
+ options: [],
37
+ summaries: []
38
+ });
39
+ const [ socket_polls, setSocketPolls ] = useState<PollProps[]>([]);
40
+ const [ market_data, setMarketData ] = useState<{
41
+ loading:boolean,
42
+ poll?:PollProps,
43
+ poll_campaign?:PollCampaignProps,
44
+ flash_market_fees:FlashMarketFeeProps[],
45
+ poll_options:PollOptionProps[],
46
+ poll_summaries:PollSummaryProps[]
47
+ }>({
48
+ loading:false,
49
+ poll_options:[],
50
+ poll_summaries:[],
51
+ flash_market_fees:[]
52
+ });
53
+ const { loading, poll_options, poll_summaries, poll_campaign, flash_market_fees } = market_data;
54
+
55
+ const [ flash_data, setFlashData ] = useState<{
56
+ holder_loading:boolean,
57
+ flash_markets:PollProps[]
58
+ }>({
59
+ holder_loading:false,
60
+ flash_markets: []
61
+ });
62
+ const { holder_loading, flash_markets } = flash_data;
63
+ const [ active_flash_market, setActiveFlashMarket ] = useState<string | undefined>(undefined);
64
+ const flash_market = flash_markets.find(fm => fm.poll_id == active_flash_market);
65
+ useEffect(() => {
66
+ loadData();
67
+ },[league_id, contest_type, contest_id, side_type, side_id, poll_id]);
68
+
69
+
70
+ useEffect(() => {
71
+ if(socket_campaigns.length == 0){ return }
72
+ if(!poll_campaign){ return }
73
+ let socket_campaign = socket_campaigns.find(sc => sc.poll_campaign_id == poll_campaign.poll_campaign_id);
74
+ if(!socket_campaign){ return }
75
+ setMarketData({
76
+ ...market_data,
77
+ poll_campaign: socket_campaign
78
+ })
79
+ },[JSON.stringify(socket_campaigns)]);
80
+
81
+ useEffect(() => {
82
+ if(socket_polls.length == 0){ return }
83
+ addToListOfPolls(socket_polls)
84
+ if(!active_flash_market || !flash_market){ return }
85
+ let same_poll = socket_polls.find(p => p.poll_id == active_flash_market);
86
+ if(!same_poll){ return }
87
+ if(same_poll.status == 'active' && flash_market.status == 'pending'){ loadMarket(flash_market.poll_id); return }
88
+ //See if we have that poll!
89
+ setMarketData({ ...market_data, poll: same_poll });
90
+ }, [JSON.stringify(socket_polls)]);
91
+
92
+ const addToListOfPolls = (polls:PollProps[]) => {
93
+ let non_flash_polls = polls.filter(p => !p.flash_active);
94
+ let new_polls = flash_markets.filter(p => !non_flash_polls.find(np => np.poll_id == p.poll_id));
95
+ let flash_polls = polls.filter(p => p.flash_active);
96
+ new_polls = new_polls.filter(fm => !flash_polls.find(np => np.poll_id == fm.poll_id)).concat(flash_polls)
97
+ setFlashData({
98
+ ...flash_data,
99
+ flash_markets: new_polls
100
+ });
101
+ }
102
+
103
+ useEffect(() => {
104
+ if(!flash_market){ return }
105
+ const { options, summaries } = socket_poll_options;
106
+ let active_options = options.filter(o => o.poll_id == active_flash_market);
107
+ let active_summaries = summaries.filter(o => o.poll_id == active_flash_market);
108
+ let new_options = poll_options.filter(po => !active_options.find(so => so.poll_option_id == po.poll_option_id)).concat(active_options)
109
+ let new_summaries = poll_summaries.filter(po => !active_summaries.find(so => so.poll_option_id == po.poll_option_id)).concat(active_summaries)
110
+ //See if we have that poll!
111
+ setMarketData({
112
+ ...market_data,
113
+ poll_options: new_options,
114
+ poll_summaries: new_summaries
115
+ });
116
+ }, [JSON.stringify(socket_poll_options)])
117
+
118
+ const handleSelectPoll = async(poll:PollProps) => {
119
+ loadMarket(poll.poll_id);
120
+ setActiveFlashMarket(poll.poll_id);
121
+ }
122
+
123
+
124
+ const loadData = async() => {
125
+ FlashMarketApi.setEnvironment();
126
+ setFlashData({ ...flash_data, holder_loading:true });
127
+ const plls = await FlashMarketApi.getActiveFlashMarkets();
128
+ setFlashData({
129
+ ...flash_data,
130
+ holder_loading:false,
131
+ flash_markets:plls
132
+ });
133
+ if(!active_flash_market){
134
+ let expiring_poll = plls.sort((a,b) => moment(a.end_datetime).unix() - moment(b.end_datetime).unix())[0]
135
+ if(expiring_poll){ handleSelectPoll(expiring_poll) }
136
+ }
137
+
138
+ }
139
+
140
+ const loadMarket = async(id:string) => {
141
+ setMarketData({ ...market_data, loading: true })
142
+ const pr = await FlashMarketApi.getPollById(id);
143
+ if(!pr){ return }
144
+ const pc = await FlashMarketApi.getPollCampaignById(pr.poll.poll_campaign_id);
145
+ setMarketData({
146
+ ...market_data,
147
+ poll: pr.poll,
148
+ poll_campaign:pc?.poll_campaign,
149
+ poll_options:pr.poll_options,
150
+ flash_market_fees: pc?.flash_market_fees ?? [],
151
+ poll_summaries: pr.poll_summaries,
152
+ loading:false
153
+ });
154
+ }
155
+
156
+ const renderFlashes = (data:{ item:PollProps, index:number }) => {
157
+ const selected = active_flash_market == data.item.poll_id ? true : false
158
+ return (
159
+ <Button
160
+ float
161
+ style={{ padding:4, borderRadius:0, borderTopRightRadius:8, borderTopLeftRadius:8, borderWidth:1, borderBottomWidth:0, borderColor:selected ? Colors.text.success : Colors.borders.light }}
162
+ onPress={() => handleSelectPoll(data.item)}
163
+ >
164
+ {data.item.poll_image ?
165
+ <Image
166
+ source={{ uri: data.item.poll_image?.url }}
167
+ style={{ height:45, width:45 }}
168
+ resizeMode='cover'
169
+ />
170
+ :
171
+ <View transparent style={{ padding:10 }}>
172
+ <Icons.FlameIcon
173
+ size={30}
174
+ color={Colors.text.h1}
175
+ />
176
+ </View>
177
+ }
178
+ </Button>
179
+ )
180
+ }
181
+
182
+ const renderSections = (data:{item:string, index:number}) => {
183
+ switch(data.item){
184
+ case 'selector':
185
+ return (
186
+ <View style={{ flexDirection:'row' }}>
187
+ <View style={{ flex:1 }}>
188
+ <FlatList
189
+ key={'poll_selector'}
190
+ keyExtractor={(item) => item.poll_id.toString()}
191
+ data={flash_markets.sort((a,b) => moment(a.end_datetime).unix() - moment(b.end_datetime).unix())}
192
+ horizontal
193
+ renderItem={renderFlashes}
194
+ />
195
+ </View>
196
+ <View
197
+ style={{ justifyContent:'flex-end', alignItems:'center', padding:5, borderRadius:0, borderTopRightRadius:8, borderTopLeftRadius:8, borderWidth:1, borderBottomWidth:0, borderColor: Colors.borders.light }}
198
+ >
199
+ <Icons.FlameIcon size={24} color={Colors.text.warning} />
200
+ <Text style={{ marginTop:5 }} theme='warning' textAlign='center'>FLASH</Text>
201
+ {holder_loading ?
202
+ <View type='blur' style={{ position:'absolute', top:0, left:0, right:0, bottom:0, justifyContent:'center', alignItems:'center' }}>
203
+ <ActivityIndicator
204
+ size='small'
205
+ color={Colors.text.h1}
206
+ />
207
+ </View>
208
+ :<></>}
209
+ </View>
210
+ </View>
211
+ )
212
+ case 'flash_market':
213
+ if(!active_flash_market){ return <></> }
214
+ return (
215
+ <View transparent>
216
+ <FlashMarket
217
+ player_id={player_id}
218
+ player={player}
219
+ location={location}
220
+ poll={flash_market}
221
+ poll_options={poll_options}
222
+ poll_summaries={poll_summaries}
223
+ poll_campaign={poll_campaign}
224
+ flash_market_fees={flash_market_fees}
225
+ loading={loading}
226
+ hide_image
227
+ card_style={{ borderWidth:1, borderColor:Colors.text.success, borderBottomRightRadius:8, borderBottomLeftRadius:8 }}
228
+ init_expanded
229
+ footer_style={{ borderBottomRightRadius:8, borderBottomLeftRadius:8 }}
230
+ header_style={{ borderTopRightRadius:0, borderTopLeftRadius:0 }}
231
+ onReload={() => loadMarket(active_flash_market)}
232
+ onRequestAuthenticate={onRequestAuthenticate}
233
+ onRequestLocation={onRequestLocation}
234
+ onFocusPosition={onFocusPosition}
235
+ />
236
+ </View>
237
+ )
238
+ default: return <></>
239
+ }
240
+ }
241
+ return (
242
+ <View style={{ margin:10 }}>
243
+ {flash_markets.length > 0 ?
244
+ <FlatList
245
+ key={'flash_sections'}
246
+ keyExtractor={item => item}
247
+ renderItem={renderSections}
248
+ data={sections}
249
+ />
250
+ :<></>}
251
+ <SocketManager
252
+ distinct_id={`flash_${distinct_id}`}
253
+ onConnect={() => {
254
+ if(needs_reload){
255
+ setNeedsReload(false);
256
+ loadData();
257
+ if(!active_flash_market){ return }
258
+ return loadMarket(active_flash_market)
259
+ }
260
+ return
261
+ }}
262
+ onDisconnect={() => setNeedsReload(true)}
263
+ onSocketEvent={(ev) => {
264
+ switch(ev.type){
265
+ case 'UPDATE_POLL_CAMPAIGNS':
266
+ setSocketCampaigns(ev.poll_campaigns)
267
+ break;
268
+ case 'UPDATE_POLLS':
269
+ if(ev.polls.length == 0){ return }
270
+ if(!ev.polls[0]){ return }
271
+ setSocketPolls(ev.polls)
272
+ break
273
+ case 'UPDATE_POLL_OPTIONS':
274
+ setSocketPollOptions({
275
+ options: ev.poll_options,
276
+ summaries: ev.poll_summaries
277
+ })
278
+ break
279
+ default: break;
280
+ }
281
+ }}
282
+ subscribed_events={['UPDATE_POLL_CAMPAIGNS', 'UPDATE_POLLS','UPDATE_POLL_OPTIONS']}
283
+ />
284
+ </View>
285
+ )
286
+ }
287
+
288
+ export default FlashHolder
@@ -27,6 +27,15 @@ const FlashMarketApi = {
27
27
  return undefined
28
28
  }
29
29
  },
30
+ getActiveFlashMarkets: async():Promise<PollProps[]> => {
31
+ try {
32
+ const resp = await axios.get(`${AUTH_SVC_API}/v2/pm/flash/active`);
33
+ return resp.data.polls
34
+ } catch (e) {
35
+ console.log(e);
36
+ return []
37
+ }
38
+ },
30
39
  getPollCampaignById : async(poll_campaign_id:string):Promise<{ poll_campaign:PollCampaignProps, flash_market_fees:FlashMarketFeeProps[] } | undefined> => {
31
40
  try {
32
41
  const resp = await axios.get(`${AUTH_SVC_API}/v1/polls/campaigns/campaign/${poll_campaign_id}`)
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { View } from "../../Components/Themed";
3
+ import ProgressTimer from './ProgressTimer';
4
+ import type { PollProps } from '../../types';
5
+ import moment from 'moment-mini';
6
+
7
+ type MarketTimerProps = {
8
+ poll:PollProps,
9
+ onTimesUp:() => void
10
+ }
11
+
12
+ const MarketTimer = ({ poll, onTimesUp }:MarketTimerProps) => {
13
+
14
+ let start = moment().subtract(1, 'hour');
15
+ if(poll.start_datetime){ start = moment(poll.start_datetime) }
16
+ let stop = moment(poll.end_datetime);
17
+
18
+ let diff = stop.diff(start, 'seconds'); //Diff is going to be the Max value
19
+ let current_value = stop.diff(moment(), 'seconds');
20
+
21
+ //return (<></>)
22
+
23
+ if(diff <= 0){ return <></> }
24
+
25
+ return (
26
+ <View>
27
+ <ProgressTimer
28
+ max_value={diff}
29
+ current_value={current_value}
30
+ increment_type={'seconds'}
31
+ time_id={poll.poll_id}
32
+ max_label={moment(poll.end_datetime).format('ddd hh:mm a')}
33
+ onTimesUp={onTimesUp}
34
+ />
35
+ </View>
36
+ )
37
+ }
38
+
39
+ export default MarketTimer
@@ -0,0 +1,61 @@
1
+ import React, { useState } from 'react';
2
+ import { View } from 'react-native';
3
+ import { useColors } from '../../constants/useColors';
4
+ import { Text } from '../../Components/Themed';
5
+
6
+ type ProgressBarProps = {
7
+ hide_labels?:boolean,
8
+ height?:number,
9
+ max_value:number,
10
+ current_value:number,
11
+ background_color:string,
12
+ fill_color:string,
13
+ max_label?:string,
14
+ val_color?:string,
15
+ val_label?:string,
16
+ round_decimal?:number,
17
+ hide_max_val?:boolean,
18
+ val_format?: {
19
+ loc: 'front'|'back',
20
+ label: string
21
+ }
22
+ }
23
+
24
+ const ProgressBar = ({ max_value, val_format, round_decimal, hide_max_val, val_color, current_value, height, hide_labels, background_color, fill_color, max_label, val_label }:ProgressBarProps) => {
25
+ const Colors = useColors();
26
+ const [ progressSize, setProgressSize ] = useState({ x:0, y:0, width:0, height:0 })
27
+
28
+ const getProgressWidth = (current_value:number) => {
29
+ let progress = current_value / max_value
30
+ if(progress > 1){ progress = 1 }
31
+ return progressSize.width * progress
32
+ }
33
+
34
+ const rounded = round_decimal ?? 2
35
+
36
+ return (
37
+ <View style={{ padding:10 }}>
38
+ <View style={{ flexDirection:'row' }}>
39
+ <View style={{ flex:1, padding:height??8, backgroundColor:background_color??Colors.views.header, borderRadius:4 }} onLayout={(ev) => {
40
+ const { x, y, width, height } = ev.nativeEvent.layout
41
+ setProgressSize({ x, y, width, height })
42
+ }}>
43
+ <View style={{ borderRadius:4, position:'absolute', backgroundColor:fill_color??Colors.text.h1, right:getProgressWidth(current_value??0), top:0, width:4, height:progressSize.height }} />
44
+ </View>
45
+ </View>
46
+ {!hide_labels ?
47
+ <View style={{ flexDirection:'row', justifyContent:'space-between', alignItems:'center', marginTop:10}}>
48
+ <Text size={12} color={val_color ?? Colors.text.h1}>{val_label?`${val_label}: `:''}{val_format?.loc=='front'?val_format.label:''}{current_value?.toFixed(rounded)}{val_format?.loc=='back'?val_format.label:''}</Text>
49
+ {hide_max_val && max_label ?
50
+ <Text size={12} color={Colors.text.h1}>{max_label}</Text>
51
+ :
52
+ <Text size={12} color={Colors.text.h1}>{max_label?`${max_label}: `:''}{val_format?.loc=='front'?val_format.label:''}{max_value?.toFixed(rounded)}{val_format?.loc=='back'?val_format.label:''}</Text>
53
+ }
54
+ </View>
55
+ :<></>}
56
+ </View>
57
+
58
+ )
59
+ }
60
+
61
+ export default ProgressBar
@@ -0,0 +1,69 @@
1
+ import React from 'react';
2
+ import { useEffect, useState } from "react";
3
+ import { useColors } from "../../constants/useColors";
4
+ import ProgressBar from './ProgressBar';
5
+
6
+ type ProgressTimerProps = {
7
+ max_value: number,
8
+ time_id:string,
9
+ current_value:number
10
+ increment_type?:'seconds'|'minutes'
11
+ max_label?:string,
12
+ update_multiplier?: number
13
+ onTimesUp:() => void
14
+ }
15
+
16
+ const ProgressTimer = ({increment_type, current_value, max_value, time_id, max_label, onTimesUp}:ProgressTimerProps) => {
17
+ const Colors = useColors();
18
+ const [ started, setStarted ] = useState(false);
19
+ const [ seconds_remaining, setSecondsRemaining ] = useState<{
20
+ time_id?:string,
21
+ seconds:number
22
+ }>({
23
+ seconds:0
24
+ });
25
+ const increment_time = increment_type == 'minutes' ? 60000 : 1000
26
+ useEffect(() => {
27
+ if(!time_id){ return }
28
+ setSecondsRemaining({
29
+ time_id,
30
+ seconds: current_value
31
+ });
32
+ setStarted(true);
33
+ },[time_id])
34
+
35
+ useEffect(() => {
36
+ if(!started){ return }
37
+ if(seconds_remaining.seconds > 0){
38
+ if(time_id != seconds_remaining.time_id){ return }
39
+ setTimeout(() => {
40
+ setSecondsRemaining({
41
+ time_id,
42
+ seconds: seconds_remaining.seconds - 1
43
+ })
44
+ }, increment_time);
45
+ } else {
46
+ if(time_id != seconds_remaining.time_id){ return }
47
+ onTimesUp();
48
+ setStarted(false);
49
+ }
50
+ },[seconds_remaining])
51
+
52
+
53
+ if(seconds_remaining.seconds == 0){ return <></> }
54
+
55
+ return (
56
+ <ProgressBar
57
+ max_value={max_value}
58
+ val_label={`${increment_type} remaining`.toUpperCase()}
59
+ current_value={seconds_remaining.seconds}
60
+ background_color={Colors.views.header}
61
+ max_label={max_label}
62
+ round_decimal={0}
63
+ hide_max_val
64
+ fill_color={Colors.text.action}
65
+ />
66
+ )
67
+ }
68
+
69
+ export default ProgressTimer