@everymatrix/casino-wagering-bonuses-controller 1.1.0 → 1.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everymatrix/casino-wagering-bonuses-controller",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "main": "index.js",
5
5
  "svelte": "src/index.ts",
6
6
  "scripts": {
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "62036ada223f2b4f7b64d99a81ab2229ecba3cf1"
39
+ "gitHead": "a331dfb7a0daca971fec89907140c9353dc5f0b3"
40
40
  }
package/rollup.config.js CHANGED
@@ -43,6 +43,9 @@ export default {
43
43
  }),
44
44
  dev && livereload({ watch: ['', 'dist'] }),
45
45
  typescript({
46
+ include: [
47
+ "../casino-wagering-bonus/src/**/*.ts",
48
+ ],
46
49
  sourceMap: !production,
47
50
  inlineSources: !production,
48
51
  }),
@@ -1,111 +1,145 @@
1
1
  <svelte:options tag={null} />
2
2
  <script lang="ts">
3
3
 
4
- export let endpoint = ''
5
- export let lang = ''
6
- export let session = ''
7
- export let sorttype = ''
8
-
9
4
  import '@everymatrix/casino-wagering-bonus'
10
- import { fetchApi, isSetUpdate } from '@everymatrix/casino-wagering-bonus/src/business'
11
- import { clearEventSource, composeEventSourceMessageHandler, updateEventSourceLifeCycle, onMountMessageLifeCycle } from '@everymatrix/casino-wagering-bonus/src/message'
12
- import { cvtParamsToString } from '@everymatrix/casino-wagering-bonus/src/util'
13
- import type { CasinoCommonClientBonusApiDataContractsNodesWageringBonusNode as Bonus } from '@everymatrix/casino-wagering-bonus/src/api'
5
+
6
+ import { fetchApi, setWageringEventSource } from '@everymatrix/casino-wagering-bonus/src/business'
7
+ import {
8
+ clearEventSource,
9
+ composeEventSourceMessageHandler,
10
+ onSvelteMountMessage
11
+ } from '@everymatrix/casino-wagering-bonus/src/message'
12
+ import type { TEventSource } from '@everymatrix/casino-wagering-bonus/src/message'
13
+ import { Bonus, BonusStatus, Lang } from '@everymatrix/casino-wagering-bonus/src/types'
14
+ import { setTranslations } from '@everymatrix/casino-wagering-bonus/src/svelte.i18n';
15
+ import { translations } from '@everymatrix/casino-wagering-bonus/src/translations';
14
16
  import { onMount } from 'svelte';
17
+ import { classWithPart } from '@everymatrix/casino-wagering-bonus/src/util';
15
18
 
16
- enum BonusStatus {
17
- BeforeClaimed = 'BeforeClaimed',
18
- active = 'active',
19
- completed = 'completed',
20
- forfeited = 'forfeited',
21
- expired = 'expired',
22
- released = 'released',
23
- closed = 'closed',
24
- }
19
+ export let endpoint = ''
20
+ export let lang = Lang.en
21
+ export let session = ''
22
+ export let currency: string = 'EUR';
23
+ export let status: BonusStatus = BonusStatus.claimable
24
+ export let limit: string = ''
25
+
26
+ let isMounted = false
27
+ $: isMounted && init()
28
+ onMount(() => {
29
+ isMounted = true
30
+ return () => {
31
+ isMounted = false
32
+ }
33
+ })
25
34
 
26
35
  let bonuses: Bonus[] = []
27
- let eventSource
28
- let isLoading = true;
29
- let errorMessage = ''
36
+ let eventSource: TEventSource
37
+ let isLoading: boolean = true;
38
+ let errorMessage: string = ''
30
39
 
31
- const init = async () => {
32
- if(!endpoint || !lang || !session) return;
33
- isLoading = true
40
+ setTranslations(translations)
34
41
 
35
- const result: any = await fetchApi.list(endpoint, lang, {
36
- session,
37
- sorttype,
38
- })
42
+ const eventSourceHandler = composeEventSourceMessageHandler({
43
+ "WageringProgressUpdate": (data: any) => {
44
+ bonuses = bonuses.map(bonus => {
45
+ let item = data?.items[bonus.bonusWalletID]
39
46
 
40
- if(!result.success) {
41
- errorMessage = result.errorMessage
42
- }else{
43
- bonuses = result.items
47
+ if(!item) return bonus
44
48
 
45
- setEventSource()
46
- }
49
+ let { status: _status, level, levelIncrement, gap } = item
50
+ let _bonus: Bonus = {...bonus}
47
51
 
48
- isLoading = false
49
-
50
-
51
- }
52
+ _bonus = { ..._bonus, wageringProgress: {
53
+ ..._bonus.wageringProgress,
54
+ currentLevel: level,
55
+ currentLevelIncrement: levelIncrement,
56
+ gap,
57
+ } }
52
58
 
53
- const eventSourceHandler = composeEventSourceMessageHandler({
54
- "WageringProgressUpdate": (data) => {
55
- bonuses = bonuses.map(bonus => {
56
- let currentLevel = data?.items[bonus.bonusWalletID]
57
- if(currentLevel){
58
- return { ...bonus, currentLevel }
59
- }else{
60
- return bonus
59
+ if(_status){
60
+ _bonus = { ..._bonus, status: _status}
61
+ setTimeout(() => init(), 500)
61
62
  }
63
+
64
+ return _bonus
62
65
  })
63
66
  },
64
67
  })
65
68
 
66
- const setEventSource = () =>{
67
- if(!bonuses) return;
68
-
69
- const params = {
70
- bonusWalletIDs: bonuses?.filter(_bonus => isSetUpdate(_bonus, BonusStatus)).map(bonus => bonus.bonusWalletID).join(','),
71
- XSessionId: session,
72
- }
69
+ const initCore = async () => {
70
+ const response = await fetchApi.list(endpoint, session, {
71
+ lang,
72
+ status,
73
+ limit,
74
+ })
75
+
76
+ if(!response.success) {
77
+ errorMessage = response.errorMessage
78
+ }else{
79
+ bonuses = (response.items || response.bonuses)
80
+ // if(status !== BonusStatus.claimable){
81
+ // bonuses = _bonuses.filter(bonus => bonus.status === status)
82
+ // }else{
83
+ // bonuses = _bonuses
84
+ // }
73
85
 
74
- const url = `${endpoint}/bonus/wagering/updates?${cvtParamsToString(params)}`;
86
+ clearEventSource(eventSource, eventSourceHandler)
87
+ if(status === BonusStatus.active){
88
+ eventSource = setWageringEventSource(endpoint, session, bonuses, eventSourceHandler)
89
+ }
90
+ }
91
+ }
92
+
93
+ const init = async () => {
94
+ if(!isMounted || !status || !lang || !session || !endpoint) return;
75
95
 
76
- eventSource = updateEventSourceLifeCycle(
77
- url,
78
- eventSource,
79
- eventSourceHandler,
80
- )
96
+ isLoading = true
97
+ await initCore()
98
+ isLoading = false
81
99
  }
82
100
 
83
- onMountMessageLifeCycle({
84
- 'OnWageringBonusClaimed': () => init()
101
+ onSvelteMountMessage({
102
+ 'OnWageringBonusClaimed': () => init(),
103
+ 'OnWageringBonusExpired': () => init(),
85
104
  })
105
+ onMount(() => () => clearEventSource(eventSource, eventSourceHandler))
86
106
 
87
107
  $: endpoint && init()
88
108
  $: lang && init()
89
109
  $: session && init()
90
-
91
- onMount(() => {
92
- return () => {
93
- clearEventSource(eventSource, eventSourceHandler)
94
- eventSource = null
95
- }
96
- })
110
+
97
111
  </script>
98
112
 
113
+ <div {...classWithPart("WageringTabs")}>
114
+ <ul>
115
+ {#each Object.keys(BonusStatus) as _status}
116
+ <li
117
+ class={status === BonusStatus[_status] ? "active" : ""}
118
+ on:click={() => {
119
+ if(status === BonusStatus[_status]) return;
120
+ status = BonusStatus[_status]
121
+ init()
122
+ }}
123
+ >
124
+ {BonusStatus[_status]}
125
+ </li>
126
+ {/each}
127
+ </ul>
128
+ </div>
129
+
99
130
  {#if isLoading}
100
131
  Loading, please wait ...
101
132
  {:else}
102
133
  {#if bonuses.length > 0}
103
- {#each bonuses as item, index}
104
- <casino-wagering-bonus
105
- {endpoint}
106
- {lang}
107
- {session}
108
- rawbonus={JSON.stringify(item)}
134
+ {#each bonuses as item}
135
+ <casino-wagering-bonus {...{
136
+ endpoint,
137
+ session,
138
+ lang,
139
+ currency,
140
+ rawbonus: JSON.stringify(item),
141
+ status,
142
+ }}
109
143
  />
110
144
  {/each}
111
145
  {:else}
@@ -138,4 +172,21 @@
138
172
  margin-bottom: 30px;
139
173
  }
140
174
 
175
+ .WageringTabs {
176
+ margin: 20px 0;
177
+
178
+ li {
179
+ display: inline;
180
+ margin: 10px 10px 10px 0;
181
+ padding: 10px;
182
+ border: 1px #ccc solid;
183
+ cursor: pointer;
184
+
185
+ &.active {
186
+ border-color:aquamarine;
187
+ font-weight: 700;
188
+ }
189
+ }
190
+ }
191
+
141
192
  </style>
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import CasinoWageringBonusesController from './CasinoWageringBonusesController.svelte';
2
-
2
+ // @ts-ignore
3
3
  !customElements.get('casino-wagering-bonuses-controller') && customElements.define('casino-wagering-bonuses-controller', CasinoWageringBonusesController);
4
4
  export default CasinoWageringBonusesController;
package/tsconfig.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "extends": "@tsconfig/svelte/tsconfig.json",
3
3
 
4
- "include": ["src/**/*"],
4
+ "include": [
5
+ "src/**/*",
6
+ "../casino-wagering-bonus/src/**/*"
7
+ ],
5
8
  "exclude": ["node_modules/*", "__sapper__/*", "public/*"]
6
9
  }