-
Notifications
You must be signed in to change notification settings - Fork 2
/
App.js
1781 lines (1704 loc) · 96.5 KB
/
App.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import React, { PureComponent } from 'react';
import {View, Image, Text, UIManager, Platform} from 'react-native'
import moment from 'moment-timezone';
import SplashScreen from 'react-native-splash-screen';
import { allActionDucer, appStateActionDucer } from './APP/actionCreator';
import { APPREADY, AUTHENTICATED, LOGIN, PARTNER_CONFIG, SPORT_COMPETITION, SPORTSBOOK_ANY, RIDS_PUSH, LOGOUT, PROFILE, MODAL, PROFILE_EMPTY, LANG, SCREEN_FN, GAME_VIEW, COMPETITIONS_DATA, BETSLIP, PREMATCH_DATA, LIVE_DATA, HOME_DATA, SPORT, BETHISTORY } from './APP/actionReducers';
import * as appConfig from './appconfig.json';
import NetInfo from "@react-native-community/netinfo";
import { dataStorage, scrollToBottom, setBetStakeInputVal, updateBrowserHistoryState } from './APP/common';
import WS from './APP/services/WS';
import API from './APP/services/api';
import {calcMD5} from './APP/utils/jsmd5'
import {makeText} from './APP/utils/index'
import DrawerNav from './APP/navigation'
import { enableScreens } from 'react-native-screens';
enableScreens();
if (Platform.OS === 'android') {
if (UIManager.setLayoutAnimationEnabledExperimental) {
UIManager.setLayoutAnimationEnabledExperimental(true);
}
}
const $api = API.getInstance()
export default class App extends PureComponent {
constructor(props) {
super(props)
this.state = {
authUser: {},
isInternetAvail:true,
windowActive: true,
inactiveTimedout:false,
canResubscribe:false
}
this.lang = props.appState.lang
this.language_cookie = null
this.socket = null
this.reconnectInterval = null
this.resubscribe = this.resubscribe.bind(this)
this.socketOpen = this.socketOpen.bind(this)
this.socketMessage = this.socketMessage.bind(this)
this.socketClose = this.socketClose.bind(this)
this.socketError = this.socketError.bind(this)
this.receiveParseJSON = this.receiveParseJSON.bind(this)
this.sendRequest = this.sendRequest.bind(this)
this.unsubscribe = this.unsubscribe.bind(this)
this.addEventToSelection = this.addEventToSelection.bind(this)
this.loginUser = this.loginUser.bind(this)
this.clearSearch = this.clearSearch.bind(this)
this.connectSocket = this.connectSocket.bind(this)
this.bulkUnsubscribe = this.bulkUnsubscribe.bind(this)
this.handleRequestSessionResponse = this.handleRequestSessionResponse.bind(this)
this.setAuthenticated = this.setAuthenticated.bind(this)
this.promotedGames = this.promotedGames.bind(this)
this.popularCompetitions = this.popularCompetitions.bind(this)
this.handleSportData = this.handleSportData.bind(this)
this.handleSportDataPrematch = this.handleSportDataPrematch.bind(this)
this.handleGameData = this.handleGameData.bind(this)
this.handleMarketData = this.handleMarketData.bind(this)
this.handleEventData = this.handleEventData.bind(this)
this.handleBetResponse = this.handleBetResponse.bind(this)
this.sportCompetitionList = this.sportCompetitionList.bind(this)
this.validate = this.validate.bind(this)
this.retrieve = this.retrieve.bind(this)
this.getEvents = this.getEvents.bind(this)
this.getBetHistory = this.getBetHistory.bind(this)
this.clearSearch = this.clearSearch.bind(this)
this.getUserBalanceMain = this.getUserBalanceMain.bind(this)
this.autoGetBalance = this.autoGetBalance.bind(this)
this.rids = { ...props.sportsbook.rids }
this.subscriptions = {}
this.swarmErrors = {
'-1': 'Fialed',
0: 'No error',
1: 'Bad Request',
2: 'Invalid Command',
3: 'Service Unavailable',
4: 'Request Timeout',
5: 'No Session',
6: 'Subscription not found',
7: 'Not subscribed',
10: 'Invalid Level',
11: 'Invalid Field',
12: 'Invalid Credentials',
20: 'Not enough balance for operation',
21: 'Operation not allowed',
22: 'Limit reached',
23: 'Service temporary is down',
99: 'Unknown Error',
1000: 'Internal Error',
1001: 'User not found',
1002: 'Wrong Login/Password',
1003: 'User blocked',
1004: 'User dismissed',
1005: 'Incorrect old password',
1008: 'Logging in the page is not possible, since user is not activated or verified',
1009: 'Such a verification code does not exist',
1012: 'Incorrect phone number',
1013: 'Password is too short',
1014: 'Failed to send verification SMS',
1023: 'User is not verified via email',
1099: 'Fork exception',
1100: 'Game is already started',
1102: 'Game start time is already past',
1103: 'Bet editing time is already past',
1104: 'Bet is payed',
1105: 'Bet status not fixed',
1106: 'Bet lose',
1107: 'Bet is online',
1108: 'Wrong value for coefficient',
1109: 'Wrong value for amount (in case of system bet - amount is less than minimum allowed)',
1021: 'Pass should contain at least 8 chars: upper and lowercase English letters, at least one digit and no space',
1112: 'Request is already paid!',
1113: 'Request is already stored!',
1117: 'Wrong login or E-mail',
1118: 'Duplicate Login',
1119: 'Duplicate EMail',
1120: 'Duplicate nickname',
1122: 'Duplicate personal Id',
1123: 'Duplicate doc number',
1124: 'Amount is not in valid range',
1125: 'Bet type error',
1126: 'Bet declined by SKKS',
1127: 'Duplicate phone number',
1150: 'You yet are not allowed to bet on the given event yet',
1151: 'Duplicate Facebook ID',
1170: 'Card lot blocked',
1171: 'Scratch card already activated',
1172: 'Scratch card blocked',
1174: 'Wrong scratch card currency (not supported for user currency)',
1200: 'Wrong value exception',
1273: 'Wrong scratch card number',
1300: 'Double value exception',
1400: 'Double event exception',
1500: 'Limit exception',
1550: 'The sum exceeds maximum allowable limit',
1560: 'The sum is less than minimum allowable limit',
1600: 'There is going the correction of coefficient.',
1700: 'Wrong access exception',
1800: 'Odds changed from %s to %s',
1900: 'The events can be included only in the express',
2000: 'Odds restriction exception',
2003: 'Bet state error',
2005: 'Cashdesk not found',
2006: 'Cashdesk not registered',
2007: 'Currency mismatch',
2008: 'Client excluded',
2009: 'Client locked',
2018: 'Email should not be an empty',
2020: 'First name should not be an empty',
2024: 'Invalid email',
2033: 'Market suspended',
2036: 'Game suspended',
2048: 'Wrong region',
2051: 'Partner api access not activated',
2052: 'Partner api Client Balance Error',
2053: 'Partner api client limit error',
2054: 'Partner api empty method',
2055: 'Partner api empty request body',
2056: 'Partner api max allowable limit',
2057: 'Partner api min allowable limit',
2058: 'Partner api PassToken error',
2059: 'Partner api timestamp expired',
2060: 'Partner api token expired',
2061: 'Partner api user blocked',
2062: 'Partner api wrong hash',
2063: 'Partner api wrong login email',
2064: 'Partner api wrong access',
2065: 'Partner not found',
2066: 'Partner commercial fee not found',
2072: 'Reset code expired',
2074: 'Same password and login',
2075: 'Selection not found',
2076: 'Selection count mismatch',
2077: 'Event suspended',
2078: 'Sport mismatch',
2080: 'Sport not supported for the partner',
2091: 'Password expired',
2093: 'Username already exist',
2098: 'Wrong currency code',
2100: 'Payment restriction exception',
2200: 'Client limit exception',
2302: 'Terminal balance exception',
2400: 'Insufficient balance',
2403: 'Pending withdrawal requests',
2404: 'Cash out not allowed',
2405: 'Bonus not found',
2406: 'Partner bonus not found',
2407: 'Client has active bonus',
2408: 'Invalid client verification step',
2409: 'Partner setting not allow this type of self exclusion',
2410: 'Invalid self exclusion type',
2411: 'Invalid client limit type',
2412: 'Invalid client bonus',
2413: 'Client restricted for action',
2414: 'Selection singles only',
2415: 'Partner not supported test client',
2416: 'Partner not using loyalty program',
2417: 'Point exchange range exceed',
2418: 'Client not using loyalty program',
2419: 'Partner limit amount exceed',
2420: 'Client has accepted bonus',
2421: 'Partner api error',
2422: 'Team not found',
2423: 'Invalid client verification step state',
2424: 'Partner sports book currency setting',
2425: 'Client bet min stake limit error',
2426: 'Max deposit request sum',
2427: 'Email wrong hash',
2428: 'Client already self excluded',
2429: 'Transaction amount exceeds frozen money',
2430: 'Wrong hash',
2431: 'Partner Mismatch',
2432: 'Match Not Visible',
2433: 'Loyalty Level Not Found',
2434: 'Max withdrawal amount',
2436: 'Selection suspended before start time',
2437: 'Bonus not allowed for super bet',
3000: 'Too many invalid login attempts',
3001: 'Currency not supported',
3015: 'Negative amount',
3019: 'Bet selections cannot be chained together',
50000: 'Failed to place bet, please try again later'
}
this.clearBetSelectionsTimeout=null
this.rids[1].callback = this.handleRequestSessionResponse
this.rids[2].callback = this.setAuthenticated
this.rids[3].callback = this.handleProfileData.bind(this)
this.rids[4].callback = this.handlePartner.bind(this)
this.rids[5].callback = this.userBonusData
this.rids[6].callback = this.userSearchGamesData.bind(this)
this.rids[6.5].callback = this.userSearchCompetitionData.bind(this)
this.rids[7].callback = this.handleSportData
this.rids["7.5"].callback = this.handleSportDataPrematch
this.rids[8].callback = this.handleGameData
this.rids[9].callback = this.handleMarketData
this.rids[10].callback = this.handleEventData.bind(this)
this.rids[11].callback = this.sportCompetitionList
this.rids[12].callback = this.handleBetResponse
this.rids[13].callback = this.gameResultsData.bind(this)
this.rids[14].callback = this.betHistoryData.bind(this)
this.rids['14.5'].callback = this.betHistoryDataOpen.bind(this)
this.rids[15].callback = this.promotedGames
this.rids[16].callback = this.popularCompetitions
this.rids[17].callback = this.bettingRules.bind(this)
this.rids[18].callback = this.currencyConfig.bind(this)
this.rids[19].callback = this.handleLiveNow.bind(this)
this.rids[20].callback = this.handleUpcoming.bind(this)
this.rids[21].callback = this.userFreeBets.bind(this)
props.dispatch(appStateActionDucer(RIDS_PUSH, { ...this.rids }))
}
componentDidMount() {
this.unsubscribeNetInfo = NetInfo.addEventListener(state => {
this.props.dispatch(allActionDucer(APPREADY, {hasInternetConnection:state.isConnected }))
});
this.props.loadApp()
.then(hasLoginState=>{
const activeView = this.props.sportsbook.activeView,socketState = null!== this.socket ?this.socket.getReadyState():10
if(activeView ==='Live' ||activeView ==='Prematch' ||activeView ==='Home'|| this.props.modalOpen)
if(socketState !== WebSocket.OPEN && socketState!== WebSocket.CONNECTING && !this.state.inactiveTimedout)this.connectSocket()
if(hasLoginState){
this.props.dispatch(appStateActionDucer(LOGIN, { isLoggedIn: true }))
const {id,AuthToken,mobile}= hasLoginState
this.props.dispatch(appStateActionDucer(PROFILE, {uid:id,AuthToken:AuthToken,mobilenumber:mobile }))
}
}).then(this.props.dispatchAppReady)
this.props.dispatch(allActionDucer(SCREEN_FN,{loadHomeData:this.loadHomeData.bind(this),
getEvents:this.getEvents,
dispatchLogOut:this.logoutUser.bind(this),
addEventToSelection:this.addEventToSelection, sendRequest:this.sendRequest, unsubscribe:this.unsubscribe,
subscribeToSelection:this.subscribeToSelection.bind(this), handleBetResponse:this.handleBetResponse,
retrieve:this.getEvents, getBetslipFreebets:this.getBetslipFreebets.bind(this),handleSportUpdate:this.handleSportUpdate.bind(this),
bulkUnsubscribe:this.bulkUnsubscribe,popularInSportsBook:this.popularInSportsBook.bind(this) }))
SplashScreen.hide()
}
componentDidUpdate(){
const activeView = this.props.appState.activeView,socketState = null!== this.socket ?this.socket.getReadyState():10
if(activeView ==='Live' ||activeView ==='Prematch' ||activeView ==='Home'){
if(socketState !== WebSocket.OPEN && socketState!== WebSocket.CONNECTING && !this.state.inactiveTimedout)this.connectSocket()
}else{
if((socketState === WebSocket.OPEN || socketState=== WebSocket.CONNECTING) && (socketState!==WebSocket.CLOSED &&socketState!==WebSocket.CLOSING)){null !==this.socket &&this.socket.close();this.props.dispatch(allActionDucer(SPORTSBOOK_ANY,{sessionData:{}}))}
}
if(!this.props.appState.isLoggedIn){
dataStorage('loginState',{},0)
.then(userData=>{
if(userData)
{userData = JSON.parse(userData)
if (userData.id && userData.AuthToken) {
this.props.dispatch(appStateActionDucer(LOGIN, { isLoggedIn: true }))
this.getUserBalanceMain()
}}
})
}
}
componentWillUnmount() {
clearInterval(this.reconnectInterval)
clearInterval(this.getBalanceInterval)
clearInterval(this.webPing)
clearInterval(this.visiblewindowInterval)
clearInterval(this.reloadpageAfterTimeout)
clearTimeout(this.unsubscribeTimeout)
clearTimeout(this.logoutTimeout)
clearTimeout(this.changingOutcomeTimeout)
clearTimeout(this.isQuickBetStakeZeroTimeout)
clearTimeout(this.betPlacedTimeout)
clearTimeout(this.betFailedTimeout)
clearTimeout(this.clearBetSelectionsTimeout)
null !==this.socket && this.socket.getReadyState() === WebSocket.OPEN && this.socket.close()
this.unsubscribeNetInfo();
}
getUserBalanceMain(){
dataStorage('loginState',{},0)
.then(userData=>{
if(userData){
userData= JSON.parse(userData)
const {id,AuthToken,mobile} = userData,$time = moment().format('YYYY-MM-DD H:mm:ss'),hash=
calcMD5(`AuthToken${AuthToken}uid${id}mobile${mobile}time${$time}${this.props.appState.$publicKey}`)
$api.getBalance({uid:id,AuthToken:AuthToken,mobile:mobile,time:$time,hash:hash},this.afterBalance.bind(this))
$api.getUserInfo({uid:id,AuthToken:AuthToken,mobile:mobile,time:$time,hash:hash},this.afterBalance.bind(this))
this.getBalanceInterval = setInterval(()=>{this.autoGetBalance()},5000)
this.loginUser()
}
})
}
autoGetBalance(){
dataStorage('loginState',{},0)
.then(userData=>{
if(userData){
userData = JSON.parse(userData)
const {id,AuthToken,mobile} = userData,$time = moment().format('YYYY-MM-DD H:mm:ss'),hash=
calcMD5(`AuthToken${AuthToken}uid${id}mobile${mobile}time${$time}${this.props.appState.$publicKey}`)
$api.getBalance({uid:id,AuthToken:AuthToken,mobile:mobile,time:$time,hash:hash},this.afterBalance.bind(this))
}
})
}
afterBalance({data}){
const res =data.data
if(res.hasOwnProperty("balance")){
const {balance,bonus}=this.props.profile
if(balance!==res.balance || bonus!==res.bonus)
this.props.dispatch(appStateActionDucer(PROFILE, { ...data.data }))
else return true
}else{
this.props.dispatch(appStateActionDucer(PROFILE, { ...data.data }))
}
}
socketOpen(e) {
// this.props.dispatch(appStateActionDucer(APPREADY, { isReady: true }))
clearInterval(this.reconnectInterval)
this.rids[1].request = {
command: "request_session",
params: {
site_id: appConfig.config.partnerID,
language: this.lang,
source: 1
},
rid: 1
}
this.sendRequest(this.rids[1].request);
this.interval = setInterval(() => {
if (this.props.appState.isLoggedIn) {
this.getClientBalance()
}
}, 30000)
}
socketMessage(event) {
let data = this.receiveParseJSON(event)
// if (data.code !== 0) {
// console.log(JSON.stringify(data))
// makeText('An error occured whiles trying to fetch data')
// }
if (data.data === null || data === null) {
return;
}
let rids = this.props.sportsbook.rids
switch (data.rid) {
case 1: //session
case 2: //authentication
case 3: //use profile
case 4: //partner data
case 5: //user bonuses
case 6: //user game search
case 6.5: //user game search
case 11: // sports comopetitions list
case 12: // bet or booking
case 13: //results games
case 14: //bet history
case "14.5": //open bets history
case 15: //popular competitions
case 16: //popular games
case 17: //betting rules
case 18: //currency configuration
case 21: //free bets
rids[data.rid].callback(data)
break;
case 7: // sports data
case "7.5": // sports data
case 8: // games data
case 9: //markets data
case 10: //events data
case 19: //live now
case 20: //upcoming
case "0":
this.handleSubscriptionResponse(data)
break;
case 2000:
// console.log(data)
break;
case 2001:
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { site_recaptch_key: data.data.result }));
break;
default:
if (rids[data.rid]) rids[data.rid].callback(data)
else console.warn('Got second response for request or invalid rid:', data);
break;
}
}
socketClose(event) {
// console.warn('Socket is closed. Reconnect will be attempted in 3 second.');
}
socketError(event) {
// console.warn('Socket encountered error: ', event);
this.socket.close()
this.reconnectInterval = setInterval(() => {
this.connectSocket();
}, 5000);
}
connectSocket() {
this.socket = new WS("wss://eu-swarm-ws.betconstruct.com/")
this.language_cookie = null
if (this.language_cookie) {
if (this.language_cookie === "fr-fr")
{ this.lang = "fra"
moment.locale('fr'); // 'fr'
}
else if (this.language_cookie === "en-gb")
{ this.lang = "eng"
moment.locale('en'); // 'en'
}
else if(this.language_cookie === "zh-cn"){
this.lang = "zhh"
moment.locale('zh'); // 'chinese'
}
}
this.props.dispatch(allActionDucer(LANG, { lang: this.lang }));
this.socket.onSocketOpen(this.socketOpen)
// Listen for messages
this.socket.onSocketMessage(this.socketMessage)
this.socket.onSocketClose(this.socketClose)
this.socket.onSocketError(this.socketError)
}
handleRequestSessionResponse(data) {
if(data.data){
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { sessionData: data.data }));
// this.sendRequest({
// "command": "get_captcha_info",
// "params": {},
// rid: 2000
// }
// );
this.sendRequest({ command: 'recaptcha_sitekey', params: {}, rid: 2001 });
this.getConfig()
// self.sendRequest({command:"get_partner_sport_group",params:{},rid:125})
// self.sendRequest({command:"get_bet_shops",params:{},rid:125})
// self.sendRequest({command:"get_captcha_url",params:{},rid:125})
this.rids[17].request = { command: "get_sport_bonus_rules", params: {}, rid: 17 }
this.sendRequest(this.rids[17].request)
this.loginUser()}
if(this.state.canResubscribe){
this.resubscribe()
}
dataStorage('betSlip',{},0)
.then((betSlip)=>{
if(betSlip){
let storeBetSlip = JSON.parse(betSlip)
if (null !== storeBetSlip && undefined !== storeBetSlip ) {
if (moment(storeBetSlip.expires).isAfter(moment())) {
if (Object.keys(storeBetSlip.bets).length) {
this.props.dispatch(allActionDucer(BETSLIP, { betSelections: storeBetSlip.bets }))
this.subscribeToSelection(storeBetSlip.bets)
}
} else {
dataStorage('betSlip', {}, 2)
}
}
}
})
}
sendRequest(request) {
// console.log('WS.sendRequest', request);
try {
let sendingDataText = JSON.stringify(request);
this.socket.send(sendingDataText);
} catch (reason) {
console.warn(reason);
}
}
receiveParseJSON(message) {
try {
return JSON.parse(message.data);
} catch (e) {
console.warn('cannot parse websocket response:', message.data, e);
return null;
}
}
loginUser() {
dataStorage('loginState',{},0).then(userData=>{
if(userData){
userData = JSON.parse(userData)
const id= userData.id,
AuthToken= userData.AuthToken
if (id !== null && AuthToken !== null) {
this.rids[2].request = {
command: "restore_login",
params: {
user_id: parseInt(id),
auth_token: AuthToken
}, rid: 2
}
this.sendRequest(this.rids[2].request)
}
}
})
}
logoutUser(type=null) {
clearInterval(this.getBalanceInterval)
dataStorage('loginState',{},0)
.then(userData=>{
if(userData){
userData = JSON.parse(userData)
id= userData.id,
AuthToken= userData.AuthToken
if (id !== null && AuthToken !== null)
{
dataStorage('loginState',{},2)
this.sendRequest({
command: "logout",
params: {}
})
type && (this.logoutTimeout = setTimeout(()=>{this.props.dispatch(allActionDucer(MODAL,{accVerifyOpen:true,formType:'login'}))},3000))
}
this.props.dispatch(appStateActionDucer(LOGOUT, { }))
this.props.dispatch(appStateActionDucer(PROFILE_EMPTY, { }))
}
})
}
setAuthenticated(user) {
const dispatch=this.props.dispatch
dispatch(allActionDucer(SPORTSBOOK_ANY, { authUser: { ...user.data }}))
dispatch(allActionDucer(BETSLIP, {betSlipMode: 2 }))
if(this.props.appState.isLoggedIn){
this.getClientProfile()
this.getClientBalance()
this.getClientBonus(2)}
}
getClientBalance() {
this.rids[3].request = {
command: "get_balance", rid: 3
}
this.sendRequest(this.rids[3].request)
}
getClientProfile() {
this.rids[3].request = {
command: "get_user",
params: {
}, rid: 3
}
this.sendRequest(this.rids[3].request)
}
userFreeBets(data) {
data.data.details && data.data.details.length && this.props.dispatch(allActionDucer(BETSLIP, { freeBets: data.data.details, freeBetStake: data.data.details[0] }))
}
getBetslipFreebets() {
if(this.props.sportsbook.authUser.has_freebets){
let selectionArr = [], {betSelections,betMode,acceptMode} = this.props.betslip
Object.keys(betSelections).forEach((selected) => {
selectionArr.push({ event_id: betSelections[selected].eventId, price: betSelections[selected].price })
})
let params = {
command: "get_freebets_for_betslip",
params: {
type: betMode,
source: 1,
is_offer: 0,
mode: acceptMode,
each_way: false,
bets: selectionArr
// "is_live":true
}, rid: 21,
}
this.sendRequest(params)
}
}
getClientBonus(type) {
this.rids[5].request = {
command: "get_bonus_details",
params: {
free_bonuses: type === 1 ? false : true
}, rid: 5
}
this.sendRequest(this.rids[5].request)
}
gameResultsData(data) {
void 0 !== data.data.games && this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { resultsGames: data.data.games.game, loadResultsGames: false }))
}
bettingRules(data) {
data.data.details !==void 0 && this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { sportsbettingRules: data.data.details }))
}
betHistoryData(data) {
void 0 !== data.data &&this.props.dispatch(allActionDucer(BETHISTORY, { bets_history: data.data, loadingHistory: false, reloadHistory: !1 }))
}
betHistoryDataOpen(data) {
let dispatch=this.props.dispatch;
// let {openBetsSubid} = this.props.betslip
// if (openBetsSubid !== null && openBetsSubid !== undefined)
// if (subscriptions[openBetsSubid]) {
// this.unsubscribe(openBetsSubid)
// delete subscriptions[openBetsSubid]
// }
// subscriptions[data.subid] = { subid: data.subid, callback: (data) => this.handleOpenBetsUpdate(data), subStateVarName: 'openBetsSubid',request:this.rids[data.rid].request }
// this.subscriptions = subscriptions
// console.log(data);
void 0 !== data.data &&dispatch(allActionDucer(BETHISTORY, { openBetHistory: data.data, loadingOpenHistory: false, reloadOpenHistory: !1,openBetsSubid:data.subid }))
}
handleOpenBetsUpdate(data){
if (data === null || data === undefined)
return
let openBetHistory = { ...this.props.betsHistoryData.openBetHistory.bets};
// Object.keys(openBetHistory).forEach((gameID) => {
// if (void 0 !== data.bets[openBetHistory[gameID].eventId] && null !== data.event[openBetHistory[gameID].eventId]) {
// if (openBetHistory[gameID].price !== data.event[openBetHistory[gameID].eventId].price) {
// openBetHistory[gameID].initialPrice = openBetHistory[gameID].price
// openBetHistory[gameID].price = data.event[openBetHistory[gameID].eventId].price
// if (openBetHistory[gameID].suspended) openBetHistory[gameID].suspended = 0
// }
// } else if (null === data.event[openBetHistory[gameID].eventId]) {
// openBetHistory[gameID].suspended = 1
// }
// })
// this.props.dispatch(allActionDucer(BETSLIP, { betSelections: betSelections }))
}
handleProfileData(data) {
try {
let { authUser } = this.props.sportsbook,dispatch=this.props.dispatch,{isLoggedIn}=this.props.appState
if (authUser.user_id && data.data.auth_token) {
authUser = { ...authUser, ...data.data }
isLoggedIn && this.getBetslipFreebets()
dispatch(allActionDucer(AUTHENTICATED, { ...authUser }))
}
else if (authUser.user_id && data.data.data.profile) {
authUser = { ...authUser, ...data.data.data.profile[authUser.user_id] }
dispatch(allActionDucer(AUTHENTICATED, { ...authUser }))
}
} catch (error) {
console.log(error)
}
}
handlePartner(data) {
this.props.dispatch(allActionDucer(PARTNER_CONFIG, { ...data.data.data.partner[appConfig.config.partnerID] }))
this.rids[18].request = {
command: "get",
params: {
source: "config.currency",
what: { currency: [] },
where:
{ currency: { name: data.data.data.partner[appConfig.config.partnerID].currency } }
}, rid: 18
}
this.sendRequest(this.rids[18].request)
}
handleBetResponse(data) {
if (data.data.result === 'OK' || 0 === data.data.result)
this.betSuccess(data)
else { this.betFailed(data.data.details ? data.data.details.hasOwnProperty('api_code')?data.data.details.api_code : data.data.result? data.data.result: 50000:50000)}
}
sportCompetitionList(data) {
data.data.details && Array.isArray(data.data.details)&& this.props.dispatch(allActionDucer(SPORT_COMPETITION, { data: data.data.details }))
}
userSearchGamesData(data) {
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { searchData: data.data.data, searching: false }))
}
userSearchCompetitionData(data) {
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { searchDataC: data.data.data, searching: false }))
}
currencyConfig(data) {
// console.log(data)
}
userBonusData(data) {
// console.log(data)
}
promotedGames(data) {
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { populargamesData: data.data.data.sport,pgSID:data.data.sid }))
}
popularCompetitions(data) {
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { popularcompetitionData: data.data.data.sport,pcSID:data.data.sid }))
}
handleSportData(data) {
let subscriptions = this.subscriptions,dispatch=this.props.dispatch;
let {sportsubid} = this.props.liveData
if (sportsubid !== null && sportsubid !== undefined)
if (subscriptions[sportsubid]) {
this.unsubscribe(sportsubid)
delete subscriptions[sportsubid]
}
subscriptions[data.subid] = { subid: data.subid, callback: (data) => this.handleSportUpdate(data,'liveData',LIVE_DATA, 'data'), subStateVarName: 'sportsubid',request:this.rids[data.rid].request }
this.subscriptions = subscriptions
if(data.data &&Object.keys(data.data.sport).length){
dispatch(allActionDucer(SPORTSBOOK_ANY, {sportsubid: data.subid, subscriptions: subscriptions }))
dispatch(allActionDucer(LIVE_DATA, {data: data.data, loadSports: false,refreshing:false}))
}else {
dispatch(allActionDucer(SPORTSBOOK_ANY, { sportsubid: data.subid,subscriptions: subscriptions}))
dispatch(allActionDucer(LIVE_DATA, {data: [],loadSports: false,refreshing:false }))
}
}
handleSportDataPrematch(data) {
let subscriptions = this.subscriptions,dispatch=this.props.dispatch;
let {sportsubid} = this.props.prematchData
if (sportsubid !== null && sportsubid !== undefined)
if (subscriptions[sportsubid]) {
this.unsubscribe(sportsubid)
delete subscriptions[sportsubid]
}
subscriptions[data.subid] = { subid: data.subid, callback: (data) => this.handleSportUpdate(data,'prematchData',PREMATCH_DATA, 'data'), subStateVarName: 'sportsubid',request:this.rids[data.rid].request }
this.subscriptions = subscriptions
if(data.data &&Object.keys(data.data.sport).length){
dispatch(allActionDucer(SPORTSBOOK_ANY, {sportsubid: data.subid, subscriptions: subscriptions }))
dispatch(allActionDucer(PREMATCH_DATA, {data: data.data, loadSports: false,refreshing:false}))
}else {
dispatch(allActionDucer(SPORTSBOOK_ANY, { sportsubid: data.subid,subscriptions: subscriptions}))
dispatch(allActionDucer(PREMATCH_DATA, {data: [],loadSports: false,refreshing:false }))
}
}
handleGameData(data) {
let subscriptions = this.subscriptions;
let { inviewGamesubid} = this.props.sportsbook
if (inviewGamesubid !== null && inviewGamesubid !== undefined)
if (subscriptions[inviewGamesubid]) {
this.unsubscribe(inviewGamesubid)
delete subscriptions[inviewGamesubid]
}
subscriptions[data.subid] = { subid: data.subid, callback: this.handleGameUpdate.bind(this), subStateVarName: 'inviewGamesubid',request:this.rids[data.rid].request }
this.subscriptions = subscriptions
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { inviewGamesubid: data.subid}))
this.props.dispatch(allActionDucer(COMPETITIONS_DATA, { competitionData: data.data.sport, loadCompetition: false,refreshing:false }))
}
handleMarketData(data) {
let subscriptions = this.subscriptions;
const { inviewMarketsubid } = this.props.sportsbook
if (inviewMarketsubid !== null && inviewMarketsubid !== undefined)
if (subscriptions[inviewMarketsubid]) {
this.unsubscribe(inviewMarketsubid)
delete subscriptions[inviewMarketsubid]
}
subscriptions[data.subid] = { subid: data.subid, callback: this.handleMarketUpdate.bind(this), subStateVarName: 'inviewMarketsubid',request:this.rids[data.rid].request }
this.subscriptions = subscriptions
let activeGame = data.data.game[Object.keys(data.data.game)[0]],marketData = activeGame && activeGame.market?{...activeGame.market}:{}
activeGame && delete activeGame.market
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { inviewMarketsubid: data.subid}))
this.props.dispatch(allActionDucer(GAME_VIEW, {marketData: marketData,activeGame:activeGame, loadMarket: false }))
}
handleEventData(data) {
let subscriptions = this.subscriptions;
let { selectionSub } = this.props.sportsbook,{betSelections}=this.props.betslip
if (selectionSub !== null && selectionSub !== undefined) {
if (subscriptions[selectionSub]) {
this.unsubscribe(selectionSub)
delete subscriptions[selectionSub]
}
}
subscriptions[data.subid] = { subid: data.subid, callback: this.handleEventUpdate.bind(this), subStateVarName: 'selectedSub',request:this.rids[data.rid].request }
this.subscriptions = subscriptions
if (data === null || data === undefined)
return
betSelections = { ...betSelections };
Object.keys(betSelections).forEach((gameID) => {
if (data.data.event[betSelections[gameID].eventId] && null !== data.data.event[betSelections[gameID].eventId]) {
if (betSelections[gameID].price !== data.data.event[betSelections[gameID].eventId].price) {
betSelections[gameID].initialPrice = betSelections[gameID].price
betSelections[gameID].price = data.data.event[betSelections[gameID].eventId].price
if (betSelections[gameID].suspended) betSelections[gameID].suspended = 0
}
} else if (null === data.data.event[betSelections[gameID].eventId] || undefined === data.data.event[betSelections[gameID].eventId]) {
betSelections[gameID].suspended = 1
}
})
dataStorage('betSlip', {}, 0)
.then(storeSlip=>{
if (storeSlip) {storeSlip =JSON.parse(storeSlip); storeSlip.bets = betSelections; dataStorage('betSlip', storeSlip.bets) }
})
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, {selectionSub: data.subid }))
this.props.dispatch(allActionDucer(BETSLIP, { betSelections: betSelections}))
}
handleSubscriptionResponse(response) {
let code = response.code, { swarmResCode,subscriptions } = this.props.sportsbook;
this.subscriptions = {...this.subscriptions,...subscriptions}
code = code === undefined ? response.data.code : code;
if (code === swarmResCode.OK) { //everything is ok
if (response.data.hasOwnProperty('subid')) {
if(response.data.subid=== "14.7") console.log(response)
this.rids[response.rid].callback({...response.data,rid:response.rid})
}
else {
Object.keys(response.data).forEach((subid) => {
if (this.subscriptions[subid]) this.subscriptions[subid].callback(response.data[subid])
})
}
} else if (code === swarmResCode.SESSION_LOST) {
//Config.env.authorized = false;
// session = null;
// this.resubscribe();
// checkLoggedInState();
} else { // unknown error
console.log(response);
}
}
unsubscribe(subid,subIdName=null) {
this.sendRequest({
command: "unsubscribe",
params: {
subid: subid
}
})
null !== subIdName && this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, {[subIdName]:null}))
}
resubscribe(type=null) {
if(type==='*'){
this.subscriptions.forEach((subData, subId) => {
// Zergling.subscribe(subData.request, subData.callback).then(function (response) {
// subData.callback(response.data);
// });
// //delete subscriptions[subId]; //clear previous data because we'll receive full data when resubscribing
});
}else{
const {activeView,marketData,competitionData}=this.props.sportsbook, sidname=[]
if(activeView ==='Live'||activeView ==='Prematch')
{
sidname.push('sportsubid')
if(Object.keys(competitionData).length)
sidname.push('inviewGamesubid')
if(Object.keys(marketData).length)
sidname.push('inviewMarketsubid')
}
else if(activeView ==='Home'){
// sidname.push('pgSID')
sidname.push('liveNowSubId')
sidname.push('upcomingSubId')
// sidname.push('pcSID')
}
for(let id in sidname){
const subid = this.props.sportsbook[sidname[id]]
void 0 !== this.props.sportsbook.subscriptions[subid] && this.sendRequest(this.props.sportsbook.subscriptions[subid].request)
}
}
this.setState({canResubscribe:false})
}
bulkUnsubscribe(subsArr, base = false) {
let subs = [], subsStates = {},individaulSub={}, data = base ? this.subscriptions : subsArr
Object.keys(data).forEach((sub) => {
// subsStates[data[sub].subStateVarName] = null
// individaulSub[data[sub]]=null
subs.push(data[sub].subid)
// delete this.subscriptions[sub]
})
this.sendRequest({
command: "unsubscribe_bulk",
params: {
subids: subs
}
})
// base && (individaulSub = {inviewMarketsubid:null,
// subid:null,
// inviewGamesubid:null,
// sportsubid:null,
// upcomingSubId:null,
// liveNowSubId:null,})
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, {subscriptions:this.subscriptions,...subsStates}))
}
handleLiveNow(data) {
let subscriptions = this.subscriptions;
const { liveNowSubId } = this.props.sportsbook
if (liveNowSubId !== null && liveNowSubId !== undefined)
if (subscriptions[liveNowSubId]) {
this.unsubscribe(liveNowSubId)
delete subscriptions[liveNowSubId]
}
subscriptions[data.subid] = { subid: data.subid, callback: (data) => this.handleSportUpdate(data,'homeData',HOME_DATA, 'liveNowData'), subStateVarName: 'liveNowSubId',request:this.rids[data.rid].request }
this.subscriptions = subscriptions
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { liveNowSubId: data.subid}))
this.props.dispatch(allActionDucer(HOME_DATA, {liveNowData: data.data, loadLiveNow: false }))
}
handleUpcoming(data) {
let subscriptions = this.subscriptions;
const { upcomingSubId } = this.props.sportsbook
if (upcomingSubId !== null && upcomingSubId !== undefined)
if (subscriptions[upcomingSubId]) {
this.unsubscribe(upcomingSubId)
delete subscriptions[upcomingSubId]
}
subscriptions[data.subid] = { subid: data.subid, callback: (data) => this.handleSportUpdate(data,'homeData',HOME_DATA, 'upcomingData'), subStateVarName: 'upcomingSubId' ,request:this.rids[data.rid].request }
this.subscriptions = subscriptions
this.props.dispatch(allActionDucer(SPORTSBOOK_ANY, { upcomingSubId: data.subid}))
this.props.dispatch(allActionDucer(HOME_DATA, {upcomingData: data.data, loadUpcomingEvents: false }))
}
isLowBalance(){
clearTimeout(this.isLowBalanceTimeout)
this.isLowBalanceTimeout = setTimeout(()=>{this.props.dispatch(allActionDucer(SPORTSBOOK_ANY,{lowBalance:false}))},5000)
}
addEventToSelection(game, market, event,extra) {
let {activeView,isLoggedIn}=this.props.appState, {betSelections}=this.props.betslip,{selectionSub} = this.props.sportsbook,{isQuickBet,quickBetStake}=this.props.liveData,dispatch=this.props.dispatch,betSelectionsClone = { ...betSelections }
let stateData = {}, betSlen = Object.keys(betSelectionsClone).length;
if(isQuickBet && activeView==='Live'){
if(!isLoggedIn){
makeText('You must login first in order to use quick bet')
return
}
if (quickBetStake > 0) {
const profile = this.props.profile
let isLowBalance= (profile.bonus === '0.00' && parseFloat(profile.balance).toFixed(2)<quickBetStake)||(parseFloat(profile.bonus)>0 &&parseFloat(profile.games.split(',').includes('1')?profile.bonus:'0').toFixed(2) < quickBetStake) ? true : false,state = {}
if(isLowBalance){
state.showBetSlipNoty= isLowBalance
state.lowBalance = isLowBalance
state.betSlipNotyMsg= profile.bonus === '0.00'?<View><Text trans="">Insufficient balance <Text >Deposit</Text></Text></View>:<View><Text>Insufficient bonus balance, consume bonus in order to use main balance</Text></View>
state.betSlipNotyType='warning'
clearTimeout(this.isLowBalanceTimeout)
this.isLowBalanceTimeout = setTimeout(()=>{this.props.dispatch(allActionDucer(BETSLIP,{lowBalance:false,showBetSlipNoty:false,betSlipNotyMsg:'',betSlipNotyType:''}))},8000)
}else{
clearTimeout(this.isLowBalanceTimeout)
state.betInprogress=true
this.placeQuickBet({ event_id: event.id, price: event.price })
}
this.props.dispatch(allActionDucer(BETSLIP, state))
} else {
this.props.dispatch(allActionDucer(BETSLIP, { isQuickBetStakeZero: true,showBetSlipNoty: true,betSlipNotyType:'error', betSlipNotyMsg:'Stake is required for bet' }))
clearTimeout(this.isQuickBetStakeZeroTimeout)
this.isQuickBetStakeZeroTimeout = setTimeout(() => {
dispatch(allActionDucer(BETSLIP, { isQuickBetStakeZero: false,betInprogress:false }))
}, 5000)
}
return
}
if (betSelectionsClone[market.id] && betSelectionsClone[market.id].eventId === event.id) {
Object.keys(betSelectionsClone).forEach((sID,k)=>{
if(parseInt(sID,10)!==market.id){
let newconflicts=betSelectionsClone[sID].conflicts.slice(0)
for(let conflict in newconflicts){
if(newconflicts[conflict].marketId ===market.id){
betSelectionsClone[sID].conflicts.splice(parseInt(conflict),1)
}
}
}
})
delete betSelectionsClone[market.id]
betSlen = Object.keys(betSelectionsClone).length
} else {
let conflicts = []
if (betSelectionsClone[market.id]) {
stateData.changingOutcome = true
stateData.showBetSlipNoty = true
stateData.betSlipNotyMsg = 'Selection outcome has changed'
stateData.betSlipNotyType = 'warning'
clearTimeout(this.changingOutcomeTimeout)
this.changingOutcomeTimeout = setTimeout(() => {
dispatch(allActionDucer(SPORTSBOOK_ANY,{ changingOutcome: false }));
}, 5000);
}else{
const mExpressID = void 0!==market.express_id?market.express_id:1
Object.keys(betSelectionsClone).forEach((sID,k)=>{