@everymatrix/user-transaction-history 1.0.69
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/dist/cjs/app-globals-3a1e7e63.js +5 -0
- package/dist/cjs/index-4699d9a2.js +1382 -0
- package/dist/cjs/index.cjs.js +2 -0
- package/dist/cjs/loader.cjs.js +15 -0
- package/dist/cjs/user-transaction-history.cjs.entry.js +343 -0
- package/dist/cjs/user-transaction-history.cjs.js +25 -0
- package/dist/collection/assets/filter.svg +4 -0
- package/dist/collection/assets/warning.svg +4 -0
- package/dist/collection/collection-manifest.json +12 -0
- package/dist/collection/components/internal/filters.js +13 -0
- package/dist/collection/components/internal/loader.js +2 -0
- package/dist/collection/components/internal/page-size.js +5 -0
- package/dist/collection/components/internal/table.js +20 -0
- package/dist/collection/components/internal/transaction.js +4 -0
- package/dist/collection/components/user-transaction-history/index.js +1 -0
- package/dist/collection/components/user-transaction-history/user-transaction-history.css +406 -0
- package/dist/collection/components/user-transaction-history/user-transaction-history.js +348 -0
- package/dist/collection/contracts/translation.js +1 -0
- package/dist/collection/global/app.js +1 -0
- package/dist/collection/index.js +1 -0
- package/dist/collection/models/transactions-response.model.js +1 -0
- package/dist/collection/utils/currency.utils.js +18 -0
- package/dist/collection/utils/date.util.js +8 -0
- package/dist/collection/utils/locale.util.js +69 -0
- package/dist/collection/utils/utils.js +3 -0
- package/dist/esm/app-globals-0f993ce5.js +3 -0
- package/dist/esm/index-b111cb50.js +1353 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/loader.js +11 -0
- package/dist/esm/user-transaction-history.entry.js +339 -0
- package/dist/esm/user-transaction-history.js +20 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/stencil.config.dev.js +17 -0
- package/dist/stencil.config.js +17 -0
- package/dist/types/Users/raul.vasile/workspace/everymatrix/widgets-monorepo/packages/stencil/user-transaction-history/.stencil/packages/stencil/user-transaction-history/stencil.config.d.ts +2 -0
- package/dist/types/Users/raul.vasile/workspace/everymatrix/widgets-monorepo/packages/stencil/user-transaction-history/.stencil/packages/stencil/user-transaction-history/stencil.config.dev.d.ts +2 -0
- package/dist/types/components/internal/filters.d.ts +8 -0
- package/dist/types/components/internal/loader.d.ts +2 -0
- package/dist/types/components/internal/page-size.d.ts +9 -0
- package/dist/types/components/internal/table.d.ts +7 -0
- package/dist/types/components/internal/transaction.d.ts +3 -0
- package/dist/types/components/user-transaction-history/index.d.ts +1 -0
- package/dist/types/components/user-transaction-history/user-transaction-history.d.ts +40 -0
- package/dist/types/components.d.ts +53 -0
- package/dist/types/contracts/translation.d.ts +2 -0
- package/dist/types/global/app.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/transactions-response.model.d.ts +23 -0
- package/dist/types/stencil-public-runtime.d.ts +1674 -0
- package/dist/types/utils/currency.utils.d.ts +4 -0
- package/dist/types/utils/date.util.d.ts +4 -0
- package/dist/types/utils/locale.util.d.ts +42 -0
- package/dist/types/utils/utils.d.ts +1 -0
- package/dist/user-transaction-history/index.esm.js +0 -0
- package/dist/user-transaction-history/p-57173b50.js +2 -0
- package/dist/user-transaction-history/p-e1255160.js +1 -0
- package/dist/user-transaction-history/p-e43630ee.entry.js +1 -0
- package/dist/user-transaction-history/user-transaction-history.esm.js +1 -0
- package/loader/cdn.js +1 -0
- package/loader/index.cjs.js +1 -0
- package/loader/index.d.ts +24 -0
- package/loader/index.es2017.js +1 -0
- package/loader/index.js +2 -0
- package/loader/package.json +11 -0
- package/package.json +26 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { Localization } from "../../utils/locale.util";
|
|
2
|
+
import { Host, h, getAssetPath } from "@stencil/core";
|
|
3
|
+
import { Loader } from "../internal/loader";
|
|
4
|
+
import { TransactionComponent } from "../internal/transaction";
|
|
5
|
+
import { PageSize } from "../internal/page-size";
|
|
6
|
+
import { Filters } from "../internal/filters";
|
|
7
|
+
import { TableComponent } from "../internal/table";
|
|
8
|
+
export class UserTransactionHistory {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.pageSizes = [10, 25, 50];
|
|
11
|
+
this.pagination = null;
|
|
12
|
+
this.stylingAppended = false;
|
|
13
|
+
this.endpoint = undefined;
|
|
14
|
+
this.session = undefined;
|
|
15
|
+
this.language = Localization.defaultLanguage;
|
|
16
|
+
this.userId = undefined;
|
|
17
|
+
this.translationUrl = undefined;
|
|
18
|
+
this.mobile = false;
|
|
19
|
+
this.clientStyling = null;
|
|
20
|
+
this.clientStylingUrl = null;
|
|
21
|
+
this.page = 0;
|
|
22
|
+
this.pageSize = this.pageSizes[0];
|
|
23
|
+
this.showMobileFilter = false;
|
|
24
|
+
this.to = undefined;
|
|
25
|
+
this.from = undefined;
|
|
26
|
+
this.type = '0';
|
|
27
|
+
this.transactions = undefined;
|
|
28
|
+
this.showLoader = true;
|
|
29
|
+
}
|
|
30
|
+
watchMultiple() {
|
|
31
|
+
this.loadTransactions();
|
|
32
|
+
}
|
|
33
|
+
async componentWillLoad() {
|
|
34
|
+
if (this.translationUrl) {
|
|
35
|
+
await Localization.loadCustomTranslations(this.translationUrl);
|
|
36
|
+
}
|
|
37
|
+
this.loadTransactions();
|
|
38
|
+
}
|
|
39
|
+
componentDidRender() {
|
|
40
|
+
this.getComponentHeight();
|
|
41
|
+
if (!this.stylingAppended && this.stylingContainer) {
|
|
42
|
+
if (this.clientStyling) {
|
|
43
|
+
this.setStyles(this.clientStyling);
|
|
44
|
+
}
|
|
45
|
+
if (this.clientStylingUrl) {
|
|
46
|
+
this.setClientStylingByURL();
|
|
47
|
+
}
|
|
48
|
+
this.stylingAppended = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
getComponentHeight() {
|
|
52
|
+
var _a;
|
|
53
|
+
if (this.mobile) {
|
|
54
|
+
let height = this.el.getBoundingClientRect().height - ((_a = this.el.shadowRoot.querySelector('.table')) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().y);
|
|
55
|
+
this.el.style.setProperty('--heightScrollableContainer', height + 'px');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
setHeightTableProperty() {
|
|
59
|
+
let height = this.getComponentHeight();
|
|
60
|
+
this.el.style.setProperty('--heightScrollableContainer', height + 'px');
|
|
61
|
+
}
|
|
62
|
+
changeTransactionsType(type) {
|
|
63
|
+
this.type = type;
|
|
64
|
+
}
|
|
65
|
+
changePageSize(pageSize) {
|
|
66
|
+
this.pageSize = pageSize;
|
|
67
|
+
}
|
|
68
|
+
prev() {
|
|
69
|
+
var _a;
|
|
70
|
+
if (!((_a = this.pagination) === null || _a === void 0 ? void 0 : _a.previous)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.page--;
|
|
74
|
+
}
|
|
75
|
+
next() {
|
|
76
|
+
var _a;
|
|
77
|
+
if (!((_a = this.pagination) === null || _a === void 0 ? void 0 : _a.next)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.page++;
|
|
81
|
+
}
|
|
82
|
+
applyFilters(from, to) {
|
|
83
|
+
this.from = from ? new Date(from).toISOString() : null;
|
|
84
|
+
this.to = to ? new Date(to).toISOString() : null;
|
|
85
|
+
this.loadTransactions();
|
|
86
|
+
}
|
|
87
|
+
showFilter() {
|
|
88
|
+
this.showMobileFilter = !this.showMobileFilter;
|
|
89
|
+
}
|
|
90
|
+
render() {
|
|
91
|
+
var _a;
|
|
92
|
+
const filterSrc = getAssetPath('../assets/filter.svg');
|
|
93
|
+
const warningSrc = getAssetPath('../assets/warning.svg');
|
|
94
|
+
return (h(Host, { key: 'c850ba36433277706247f4b7c0c08b0ae0fb8c76' }, this.showLoader ? h(Loader, null) : '', h("div", { key: '20b817b5c9cf14e8af0db2ba417d09e21b6921d7', class: "wrapper", ref: el => (this.stylingContainer = el) }, h("div", { key: '3943f4ab79cb0e72083821b424000f96779e78a5', class: { 'types types-mobile': this.mobile, 'types types-desktop': !this.mobile } }, h("button", { key: 'd1f3dfc1f4fc7013bd81c92663f578129f63c0e7', class: 'transaction-type' + ' ' + (this.type === '0' ? 'clicked' : ''), onClick: () => this.changeTransactionsType('0') }, Localization.translate('deposit', this.language)), h("button", { key: '46989070ef6703fdf7c8c7ac6628e9dce731fec6', class: 'transaction-type' + ' ' + (this.type === '1' ? 'clicked' : ''), onClick: () => this.changeTransactionsType('1') }, Localization.translate('withdrawals', this.language))), !this.mobile ? h(PageSize, { language: this.language, pageSizes: this.pageSizes, currentPageSize: this.pageSize, changePageSize: s => this.changePageSize(s) }) : '', this.mobile ? (h("button", { class: "mobile-filter-button", onClick: () => this.showFilter() }, h("img", { src: filterSrc, alt: "Filter" }), Localization.translate('filter', this.language))) : (''), !this.mobile || (this.showMobileFilter && this.mobile) ? h(Filters, { language: this.language, applyFilters: (from, to) => this.applyFilters(from, to) }) : '', ((_a = this.transactions) === null || _a === void 0 ? void 0 : _a.length) > 0 ? (h("div", { class: "table" }, this.mobile ? (h("div", { class: "mobile-table" }, this.transactions.map(transaction => (h(TransactionComponent, Object.assign({}, transaction)))))) : (h(TableComponent, { source: this.transactions, language: this.language })))) : (h("div", { class: "noData" }, h("img", { src: warningSrc, alt: "Warning" }), h("span", null, Localization.translate('noData', this.language)))), h("div", { key: '50710657788295389a20d59e0092dd033e428268', class: "pagination" }, h("button", { key: 'cd29c880eab413a06666dc12c8df38d3ffdcfe2f', onClick: () => this.prev() }, '<'), h("button", { key: 'df351ecd4237433a8ab38766669ac48d2548ed6a', onClick: () => this.next() }, '>')))));
|
|
95
|
+
}
|
|
96
|
+
async loadTransactions() {
|
|
97
|
+
this.showLoader = true;
|
|
98
|
+
try {
|
|
99
|
+
const url = `${this.endpoint}/v1/player/${this.userId}/transactions/banking?${this.getParams()}`;
|
|
100
|
+
const response = await fetch(url, {
|
|
101
|
+
headers: {
|
|
102
|
+
'X-Sessionid': this.session,
|
|
103
|
+
'Content-Type': 'application/json'
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
if (!response.ok) {
|
|
107
|
+
const err = await response.text();
|
|
108
|
+
throw new Error(err);
|
|
109
|
+
}
|
|
110
|
+
const data = await response.json();
|
|
111
|
+
this.pagination = data.pagination;
|
|
112
|
+
this.transactions = data.transactions;
|
|
113
|
+
}
|
|
114
|
+
catch (ex) {
|
|
115
|
+
console.error(ex);
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
this.showLoader = false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
getParams() {
|
|
122
|
+
var _a, _b;
|
|
123
|
+
const now = new Date();
|
|
124
|
+
const offset = (this.page * this.pageSize).toString();
|
|
125
|
+
const startDate = (_a = this.from) !== null && _a !== void 0 ? _a : new Date(now.getFullYear(), now.getMonth(), 1).toISOString();
|
|
126
|
+
const endDate = (_b = this.to) !== null && _b !== void 0 ? _b : new Date(now.getFullYear(), now.getMonth() + 1, 0).toISOString();
|
|
127
|
+
return `offset=${offset}&endDate=${endDate}&startDate=${startDate}&type=${this.type}&limit=${this.pageSize}`;
|
|
128
|
+
}
|
|
129
|
+
setStyles(styles) {
|
|
130
|
+
const cssFile = document.createElement('style');
|
|
131
|
+
cssFile.innerHTML = styles;
|
|
132
|
+
this.stylingContainer.prepend(cssFile);
|
|
133
|
+
}
|
|
134
|
+
async setClientStylingByURL() {
|
|
135
|
+
try {
|
|
136
|
+
const response = await fetch(this.clientStylingUrl);
|
|
137
|
+
if (!response.ok) {
|
|
138
|
+
const err = await response.text();
|
|
139
|
+
throw new Error(err);
|
|
140
|
+
}
|
|
141
|
+
const styles = await response.text();
|
|
142
|
+
this.setStyles(styles);
|
|
143
|
+
}
|
|
144
|
+
catch (ex) {
|
|
145
|
+
console.error(`Failed to load client styles ${this.clientStylingUrl}`, ex);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
static get is() { return "user-transaction-history"; }
|
|
149
|
+
static get encapsulation() { return "shadow"; }
|
|
150
|
+
static get originalStyleUrls() {
|
|
151
|
+
return {
|
|
152
|
+
"$": ["user-transaction-history.scss"]
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
static get styleUrls() {
|
|
156
|
+
return {
|
|
157
|
+
"$": ["user-transaction-history.css"]
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
static get assetsDirs() { return ["../assets"]; }
|
|
161
|
+
static get properties() {
|
|
162
|
+
return {
|
|
163
|
+
"endpoint": {
|
|
164
|
+
"type": "string",
|
|
165
|
+
"mutable": false,
|
|
166
|
+
"complexType": {
|
|
167
|
+
"original": "string | null",
|
|
168
|
+
"resolved": "string",
|
|
169
|
+
"references": {}
|
|
170
|
+
},
|
|
171
|
+
"required": false,
|
|
172
|
+
"optional": false,
|
|
173
|
+
"docs": {
|
|
174
|
+
"tags": [],
|
|
175
|
+
"text": ""
|
|
176
|
+
},
|
|
177
|
+
"attribute": "endpoint",
|
|
178
|
+
"reflect": true
|
|
179
|
+
},
|
|
180
|
+
"session": {
|
|
181
|
+
"type": "string",
|
|
182
|
+
"mutable": false,
|
|
183
|
+
"complexType": {
|
|
184
|
+
"original": "string",
|
|
185
|
+
"resolved": "string",
|
|
186
|
+
"references": {}
|
|
187
|
+
},
|
|
188
|
+
"required": false,
|
|
189
|
+
"optional": false,
|
|
190
|
+
"docs": {
|
|
191
|
+
"tags": [],
|
|
192
|
+
"text": ""
|
|
193
|
+
},
|
|
194
|
+
"attribute": "session",
|
|
195
|
+
"reflect": true
|
|
196
|
+
},
|
|
197
|
+
"language": {
|
|
198
|
+
"type": "string",
|
|
199
|
+
"mutable": false,
|
|
200
|
+
"complexType": {
|
|
201
|
+
"original": "string",
|
|
202
|
+
"resolved": "string",
|
|
203
|
+
"references": {}
|
|
204
|
+
},
|
|
205
|
+
"required": false,
|
|
206
|
+
"optional": false,
|
|
207
|
+
"docs": {
|
|
208
|
+
"tags": [],
|
|
209
|
+
"text": ""
|
|
210
|
+
},
|
|
211
|
+
"attribute": "language",
|
|
212
|
+
"reflect": true,
|
|
213
|
+
"defaultValue": "Localization.defaultLanguage"
|
|
214
|
+
},
|
|
215
|
+
"userId": {
|
|
216
|
+
"type": "string",
|
|
217
|
+
"mutable": false,
|
|
218
|
+
"complexType": {
|
|
219
|
+
"original": "string",
|
|
220
|
+
"resolved": "string",
|
|
221
|
+
"references": {}
|
|
222
|
+
},
|
|
223
|
+
"required": false,
|
|
224
|
+
"optional": false,
|
|
225
|
+
"docs": {
|
|
226
|
+
"tags": [],
|
|
227
|
+
"text": ""
|
|
228
|
+
},
|
|
229
|
+
"attribute": "user-id",
|
|
230
|
+
"reflect": true
|
|
231
|
+
},
|
|
232
|
+
"translationUrl": {
|
|
233
|
+
"type": "string",
|
|
234
|
+
"mutable": false,
|
|
235
|
+
"complexType": {
|
|
236
|
+
"original": "string",
|
|
237
|
+
"resolved": "string",
|
|
238
|
+
"references": {}
|
|
239
|
+
},
|
|
240
|
+
"required": false,
|
|
241
|
+
"optional": false,
|
|
242
|
+
"docs": {
|
|
243
|
+
"tags": [],
|
|
244
|
+
"text": ""
|
|
245
|
+
},
|
|
246
|
+
"attribute": "translation-url",
|
|
247
|
+
"reflect": true
|
|
248
|
+
},
|
|
249
|
+
"mobile": {
|
|
250
|
+
"type": "boolean",
|
|
251
|
+
"mutable": false,
|
|
252
|
+
"complexType": {
|
|
253
|
+
"original": "boolean",
|
|
254
|
+
"resolved": "boolean",
|
|
255
|
+
"references": {}
|
|
256
|
+
},
|
|
257
|
+
"required": false,
|
|
258
|
+
"optional": false,
|
|
259
|
+
"docs": {
|
|
260
|
+
"tags": [],
|
|
261
|
+
"text": ""
|
|
262
|
+
},
|
|
263
|
+
"attribute": "mobile",
|
|
264
|
+
"reflect": true,
|
|
265
|
+
"defaultValue": "false"
|
|
266
|
+
},
|
|
267
|
+
"clientStyling": {
|
|
268
|
+
"type": "string",
|
|
269
|
+
"mutable": false,
|
|
270
|
+
"complexType": {
|
|
271
|
+
"original": "string | null",
|
|
272
|
+
"resolved": "string",
|
|
273
|
+
"references": {}
|
|
274
|
+
},
|
|
275
|
+
"required": false,
|
|
276
|
+
"optional": false,
|
|
277
|
+
"docs": {
|
|
278
|
+
"tags": [],
|
|
279
|
+
"text": ""
|
|
280
|
+
},
|
|
281
|
+
"attribute": "client-styling",
|
|
282
|
+
"reflect": true,
|
|
283
|
+
"defaultValue": "null"
|
|
284
|
+
},
|
|
285
|
+
"clientStylingUrl": {
|
|
286
|
+
"type": "string",
|
|
287
|
+
"mutable": false,
|
|
288
|
+
"complexType": {
|
|
289
|
+
"original": "string | null",
|
|
290
|
+
"resolved": "string",
|
|
291
|
+
"references": {}
|
|
292
|
+
},
|
|
293
|
+
"required": false,
|
|
294
|
+
"optional": false,
|
|
295
|
+
"docs": {
|
|
296
|
+
"tags": [],
|
|
297
|
+
"text": ""
|
|
298
|
+
},
|
|
299
|
+
"attribute": "client-styling-url",
|
|
300
|
+
"reflect": true,
|
|
301
|
+
"defaultValue": "null"
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
static get states() {
|
|
306
|
+
return {
|
|
307
|
+
"page": {},
|
|
308
|
+
"pageSize": {},
|
|
309
|
+
"showMobileFilter": {},
|
|
310
|
+
"to": {},
|
|
311
|
+
"from": {},
|
|
312
|
+
"type": {},
|
|
313
|
+
"transactions": {},
|
|
314
|
+
"showLoader": {}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
static get elementRef() { return "el"; }
|
|
318
|
+
static get watchers() {
|
|
319
|
+
return [{
|
|
320
|
+
"propName": "page",
|
|
321
|
+
"methodName": "watchMultiple"
|
|
322
|
+
}, {
|
|
323
|
+
"propName": "type",
|
|
324
|
+
"methodName": "watchMultiple"
|
|
325
|
+
}, {
|
|
326
|
+
"propName": "session",
|
|
327
|
+
"methodName": "watchMultiple"
|
|
328
|
+
}, {
|
|
329
|
+
"propName": "userId",
|
|
330
|
+
"methodName": "watchMultiple"
|
|
331
|
+
}, {
|
|
332
|
+
"propName": "pageSize",
|
|
333
|
+
"methodName": "watchMultiple"
|
|
334
|
+
}, {
|
|
335
|
+
"propName": "showMobileFilter",
|
|
336
|
+
"methodName": "getComponentHeight"
|
|
337
|
+
}];
|
|
338
|
+
}
|
|
339
|
+
static get listeners() {
|
|
340
|
+
return [{
|
|
341
|
+
"name": "resize",
|
|
342
|
+
"method": "getComponentHeight",
|
|
343
|
+
"target": "window",
|
|
344
|
+
"capture": false,
|
|
345
|
+
"passive": true
|
|
346
|
+
}];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@vaadin/date-picker/theme/lumo/vaadin-date-picker.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class CurrencyFormatter {
|
|
2
|
+
constructor() { }
|
|
3
|
+
static format(currency, value) {
|
|
4
|
+
let result = `${value} ${currency}`;
|
|
5
|
+
try {
|
|
6
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
7
|
+
style: 'currency',
|
|
8
|
+
currency: currency,
|
|
9
|
+
});
|
|
10
|
+
result = formatter.format(value);
|
|
11
|
+
}
|
|
12
|
+
catch (_a) {
|
|
13
|
+
// If we here formatter do not support that currency.
|
|
14
|
+
// Just ignore that and use the currency name instead of it symbol.
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export class DateTransformer {
|
|
2
|
+
constructor() { }
|
|
3
|
+
static dateToFormatedString(date) {
|
|
4
|
+
const dateStr = date.toLocaleDateString('en-gb');
|
|
5
|
+
const timeStr = date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false });
|
|
6
|
+
return `${dateStr}, ${timeStr}`;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export const DEFAULT_TRANSLATIONS = {
|
|
2
|
+
"en": {
|
|
3
|
+
"deposit": "Deposit",
|
|
4
|
+
"withdrawals": "Withdrawals",
|
|
5
|
+
"show": "Show",
|
|
6
|
+
"from": "From",
|
|
7
|
+
"to": "To",
|
|
8
|
+
"filter": "Filter",
|
|
9
|
+
"transactionId": "Transaction ID",
|
|
10
|
+
"date": "Date",
|
|
11
|
+
"amount": "Amount",
|
|
12
|
+
"productType": "Product Type",
|
|
13
|
+
"status": "Status",
|
|
14
|
+
"noData": "There are no account activities"
|
|
15
|
+
},
|
|
16
|
+
"hr": {
|
|
17
|
+
"deposit": "Uplate",
|
|
18
|
+
"withdrawals": "Isplate",
|
|
19
|
+
"show": "Prikaži",
|
|
20
|
+
"from": "Od",
|
|
21
|
+
"to": "Do",
|
|
22
|
+
"filter": "Filter",
|
|
23
|
+
"transactionId": "ID transakcije",
|
|
24
|
+
"date": "Datum",
|
|
25
|
+
"amount": "Iznos",
|
|
26
|
+
"productType": "Vrsta proizvoda",
|
|
27
|
+
"status": "Status",
|
|
28
|
+
"noData": "Nema aktivnosti na računu"
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export class Localization {
|
|
32
|
+
constructor() { }
|
|
33
|
+
static async loadCustomTranslations(translationUrl) {
|
|
34
|
+
try {
|
|
35
|
+
const response = await fetch(translationUrl, {
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
const err = await response.text();
|
|
42
|
+
throw new Error(err);
|
|
43
|
+
}
|
|
44
|
+
const translations = await response.json();
|
|
45
|
+
Localization.updateTranslations(translations);
|
|
46
|
+
}
|
|
47
|
+
catch (ex) {
|
|
48
|
+
console.error(`Failed to load translations ${translationUrl}. ${ex.message}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
static translate(key, locale) {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
const avaliableLocales = Localization.getAvaliableLanguages(locale);
|
|
54
|
+
return ((_b = (_a = Localization.customTranslation) === null || _a === void 0 ? void 0 : _a[avaliableLocales.customLanguage]) === null || _b === void 0 ? void 0 : _b[key]) || Localization.defaultTranslation[avaliableLocales.predefinedLanguage][key];
|
|
55
|
+
}
|
|
56
|
+
static getAvaliableLanguages(locale) {
|
|
57
|
+
var _a;
|
|
58
|
+
const customLanguage = ((_a = Localization.customLanguages) === null || _a === void 0 ? void 0 : _a.includes(locale)) ? locale : Localization.defaultLanguage;
|
|
59
|
+
const predefinedLanguage = Localization.supportedLanguages.includes(locale) ? locale : Localization.defaultLanguage;
|
|
60
|
+
return { predefinedLanguage, customLanguage };
|
|
61
|
+
}
|
|
62
|
+
static updateTranslations(translations) {
|
|
63
|
+
Localization.customLanguages = Array.from(new Set([...Localization.supportedLanguages, ...Object.keys(translations).map(k => k.toLowerCase())]));
|
|
64
|
+
Localization.customTranslation = translations;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
Localization.defaultLanguage = 'en';
|
|
68
|
+
Localization.supportedLanguages = ['en'];
|
|
69
|
+
Localization.defaultTranslation = DEFAULT_TRANSLATIONS;
|