tf-checkout-react 1.3.46 → 1.3.47-beta.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/dist/.DS_Store +0 -0
- package/dist/api/index.d.ts +10 -0
- package/dist/components/addonsContainer/utils/index.d.ts +1 -4
- package/dist/components/billing-info-container/utils.d.ts +20 -1
- package/dist/components/myTicketsContainer/tableConfig.d.ts +1 -4
- package/dist/components/ticketsContainer/TicketRow.d.ts +6 -1
- package/dist/components/ticketsContainer/TicketsSection.d.ts +6 -1
- package/dist/components/ticketsContainer/crypto.d.ts +24 -0
- package/dist/tf-checkout-react.cjs.development.js +4701 -1324
- package/dist/tf-checkout-react.cjs.development.js.map +1 -1
- package/dist/tf-checkout-react.cjs.production.min.js +1 -1
- package/dist/tf-checkout-react.cjs.production.min.js.map +1 -1
- package/dist/tf-checkout-react.esm.js +4702 -1324
- package/dist/tf-checkout-react.esm.js.map +1 -1
- package/dist/tf-checkout-styles.css +1 -1
- package/dist/types/billing-info-data.d.ts +5 -0
- package/dist/utils/getWalletName.d.ts +1 -0
- package/dist/utils/loadProfile.d.ts +32 -0
- package/package.json +3 -1
- package/src/.DS_Store +0 -0
- package/src/api/index.ts +42 -1
- package/src/assets/.DS_Store +0 -0
- package/src/components/addonsContainer/utils/index.tsx +1 -1
- package/src/components/billing-info-container/index.tsx +271 -11
- package/src/components/billing-info-container/style.css +1 -1
- package/src/components/billing-info-container/utils.ts +98 -5
- package/src/components/loginModal/index.tsx +70 -5
- package/src/components/loginModal/style.css +2 -2
- package/src/components/ticketsContainer/TicketRow.tsx +55 -5
- package/src/components/ticketsContainer/TicketsSection.tsx +15 -1
- package/src/components/ticketsContainer/crypto.js +528 -0
- package/src/components/ticketsContainer/index.tsx +216 -2
- package/src/components/waitingList/index.tsx +1 -1
- package/src/env.ts +2 -2
- package/src/types/billing-info-data.ts +6 -0
- package/src/utils/getWalletName.tsx +10 -0
- package/src/utils/loadProfile.tsx +47 -0
- package/src/components/common/dist/PhoneNumberField.js +0 -96
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
import detectEthereumProvider from '@metamask/detect-provider'
|
|
2
|
+
import _get from "lodash/get"
|
|
3
|
+
import Web3 from 'web3'
|
|
4
|
+
|
|
5
|
+
import { authorizeWithWallet, cryptoA0K1, cryptoAccount, cryptoAddress, cryptoConnect } from "../../api"
|
|
6
|
+
|
|
7
|
+
const EthereumWrapper = function (exceptionHandler, errorCodes) {
|
|
8
|
+
let web3
|
|
9
|
+
const ERRORS = errorCodes
|
|
10
|
+
let selectedAddress = undefined
|
|
11
|
+
|
|
12
|
+
const isSupported = function () {
|
|
13
|
+
return new Promise(success => {
|
|
14
|
+
detectEthereumProvider().then(provider => {
|
|
15
|
+
if (provider) {
|
|
16
|
+
success(true)
|
|
17
|
+
} else {
|
|
18
|
+
success(false)
|
|
19
|
+
}
|
|
20
|
+
}).catch(() => success(false))
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const enable = function () {
|
|
25
|
+
return new Promise((success, reject) => {
|
|
26
|
+
window.ethereum.request({ method: 'eth_requestAccounts' }).then(() => {
|
|
27
|
+
web3 = new Web3(window.ethereum)
|
|
28
|
+
success(true)
|
|
29
|
+
}).catch(error => {
|
|
30
|
+
let errorCode = ERRORS.WEB3_ERROR
|
|
31
|
+
if (error.code === 4001) {
|
|
32
|
+
errorCode = ERRORS.CONNECTION_REJECTED
|
|
33
|
+
}
|
|
34
|
+
reject(exceptionHandler('web3js', error.message, '', errorCode))
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getAddress = function () {
|
|
40
|
+
return web3.eth.getCoinbase().then(address => {
|
|
41
|
+
selectedAddress = address
|
|
42
|
+
return address
|
|
43
|
+
}).catch(error => Promise.reject(exceptionHandler('web3js', error.message, '', error.WEB3_ERROR)))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const getSignature = function (address, nonce, message) {
|
|
47
|
+
return new Promise((success, reject) => {
|
|
48
|
+
web3.eth.personal.sign(message + nonce, address, '', (error, result) => {
|
|
49
|
+
|
|
50
|
+
if (error) {
|
|
51
|
+
let errorCode = ERRORS.WEB3_ERROR
|
|
52
|
+
if (error.code === 4001) {
|
|
53
|
+
errorCode = ERRORS.SIGNATURE_REJECTED
|
|
54
|
+
}
|
|
55
|
+
reject(exceptionHandler('web3js', error.message, '', errorCode))
|
|
56
|
+
} else {
|
|
57
|
+
success(result)
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const getA0k1verseNFTs = function (address, ticketHash, amount) {
|
|
64
|
+
return new Promise(async (success, reject) => {
|
|
65
|
+
try {
|
|
66
|
+
const response = await cryptoA0K1(address, ticketHash, amount)
|
|
67
|
+
success(_get(response, 'data.data'))
|
|
68
|
+
} catch(error) {
|
|
69
|
+
let message = _get(error, 'response.data.message')
|
|
70
|
+
const statusCode = _get(error, 'response.status')
|
|
71
|
+
if (!message) {
|
|
72
|
+
message = _get(error, 'response.statusText')
|
|
73
|
+
}
|
|
74
|
+
let errorCode = ERRORS.SERVER_ERROR
|
|
75
|
+
if (statusCode === 404) {
|
|
76
|
+
errorCode = ERRORS.TICKET_TYPE_NOT_FOUND
|
|
77
|
+
}
|
|
78
|
+
reject(exceptionHandler('backend', message, '', errorCode))
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const hasAccountChanged = function () {
|
|
84
|
+
const currentAccount = selectedAddress
|
|
85
|
+
return getAddress().then(address => Promise.resolve(currentAccount !== address))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
isSupported,
|
|
90
|
+
enable,
|
|
91
|
+
getAddress,
|
|
92
|
+
getSignature,
|
|
93
|
+
getA0k1verseNFTs,
|
|
94
|
+
hasAccountChanged,
|
|
95
|
+
ERRORS,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const SolanaWrapper = function (exceptionHandler, errorCodes) {
|
|
100
|
+
let solana
|
|
101
|
+
const ERRORS = errorCodes
|
|
102
|
+
let publicKey = undefined
|
|
103
|
+
|
|
104
|
+
const ByteBase64Converter = function (){
|
|
105
|
+
/*
|
|
106
|
+
MIT License
|
|
107
|
+
|
|
108
|
+
Copyright (c) 2020 Egor Nepomnyaschih
|
|
109
|
+
|
|
110
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
111
|
+
of this software and associated documentation files (the 'Software'), to deal
|
|
112
|
+
in the Software without restriction, including without limitation the rights
|
|
113
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
114
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
115
|
+
furnished to do so, subject to the following conditions:
|
|
116
|
+
|
|
117
|
+
The above copyright notice and this permission notice shall be included in all
|
|
118
|
+
copies or substantial portions of the Software.
|
|
119
|
+
|
|
120
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
121
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
122
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
123
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
124
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
125
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
126
|
+
SOFTWARE.
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
/*
|
|
130
|
+
// This constant can also be computed with the following algorithm:
|
|
131
|
+
const base64abc = [],
|
|
132
|
+
A = 'A'.charCodeAt(0),
|
|
133
|
+
a = 'a'.charCodeAt(0),
|
|
134
|
+
n = '0'.charCodeAt(0);
|
|
135
|
+
for (let i = 0; i < 26; ++i) {
|
|
136
|
+
base64abc.push(String.fromCharCode(A + i));
|
|
137
|
+
}
|
|
138
|
+
for (let i = 0; i < 26; ++i) {
|
|
139
|
+
base64abc.push(String.fromCharCode(a + i));
|
|
140
|
+
}
|
|
141
|
+
for (let i = 0; i < 10; ++i) {
|
|
142
|
+
base64abc.push(String.fromCharCode(n + i));
|
|
143
|
+
}
|
|
144
|
+
base64abc.push('+');
|
|
145
|
+
base64abc.push('/');
|
|
146
|
+
*/
|
|
147
|
+
const base64abc = [
|
|
148
|
+
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
|
149
|
+
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
|
150
|
+
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
151
|
+
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
152
|
+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
|
|
153
|
+
]
|
|
154
|
+
|
|
155
|
+
/*
|
|
156
|
+
// This constant can also be computed with the following algorithm:
|
|
157
|
+
const l = 256, base64codes = new Uint8Array(l);
|
|
158
|
+
for (let i = 0; i < l; ++i) {
|
|
159
|
+
base64codes[i] = 255; // invalid character
|
|
160
|
+
}
|
|
161
|
+
base64abc.forEach((char, index) => {
|
|
162
|
+
base64codes[char.charCodeAt(0)] = index;
|
|
163
|
+
});
|
|
164
|
+
base64codes['='.charCodeAt(0)] = 0; // ignored anyway, so we just need to prevent an error
|
|
165
|
+
*/
|
|
166
|
+
const base64codes = [
|
|
167
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
168
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
|
169
|
+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63,
|
|
170
|
+
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 0, 255, 255,
|
|
171
|
+
255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
|
172
|
+
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255,
|
|
173
|
+
255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
|
174
|
+
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
function getBase64Code(charCode) {
|
|
178
|
+
if (charCode >= base64codes.length) {
|
|
179
|
+
throw new Error('Unable to parse base64 string.')
|
|
180
|
+
}
|
|
181
|
+
const code = base64codes[charCode]
|
|
182
|
+
if (code === 255) {
|
|
183
|
+
throw new Error('Unable to parse base64 string.')
|
|
184
|
+
}
|
|
185
|
+
return code
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function bytesToBase64(bytes) {
|
|
189
|
+
let result = ''; let i; const l = bytes.length
|
|
190
|
+
for (i = 2; i < l; i += 3) {
|
|
191
|
+
result += base64abc[bytes[i - 2] >> 2]
|
|
192
|
+
result += base64abc[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)]
|
|
193
|
+
result += base64abc[((bytes[i - 1] & 0x0F) << 2) | (bytes[i] >> 6)]
|
|
194
|
+
result += base64abc[bytes[i] & 0x3F]
|
|
195
|
+
}
|
|
196
|
+
if (i === l + 1) { // 1 octet yet to write
|
|
197
|
+
result += base64abc[bytes[i - 2] >> 2]
|
|
198
|
+
result += base64abc[(bytes[i - 2] & 0x03) << 4]
|
|
199
|
+
result += '=='
|
|
200
|
+
}
|
|
201
|
+
if (i === l) { // 2 octets yet to write
|
|
202
|
+
result += base64abc[bytes[i - 2] >> 2]
|
|
203
|
+
result += base64abc[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)]
|
|
204
|
+
result += base64abc[(bytes[i - 1] & 0x0F) << 2]
|
|
205
|
+
result += '='
|
|
206
|
+
}
|
|
207
|
+
return result
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function base64ToBytes(str) {
|
|
211
|
+
if (str.length % 4 !== 0) {
|
|
212
|
+
throw new Error('Unable to parse base64 string.')
|
|
213
|
+
}
|
|
214
|
+
const index = str.indexOf('=')
|
|
215
|
+
if (index !== -1 && index < str.length - 2) {
|
|
216
|
+
throw new Error('Unable to parse base64 string.')
|
|
217
|
+
}
|
|
218
|
+
const missingOctets = str.endsWith('==') ? 2 : str.endsWith('=') ? 1 : 0
|
|
219
|
+
const n = str.length
|
|
220
|
+
const result = new Uint8Array(3 * (n / 4))
|
|
221
|
+
let buffer
|
|
222
|
+
for (let i = 0, j = 0; i < n; i += 4, j += 3) {
|
|
223
|
+
buffer =
|
|
224
|
+
(getBase64Code(str.charCodeAt(i)) << 18) |
|
|
225
|
+
(getBase64Code(str.charCodeAt(i + 1)) << 12) |
|
|
226
|
+
(getBase64Code(str.charCodeAt(i + 2)) << 6) |
|
|
227
|
+
getBase64Code(str.charCodeAt(i + 3))
|
|
228
|
+
result[j] = buffer >> 16
|
|
229
|
+
result[j + 1] = (buffer >> 8) & 0xFF
|
|
230
|
+
result[j + 2] = buffer & 0xFF
|
|
231
|
+
}
|
|
232
|
+
return result.subarray(0, result.length - missingOctets)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function base64encode(str, encoder) {
|
|
236
|
+
return bytesToBase64(encoder.encode(str))
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function base64decode(str, decoder) {
|
|
240
|
+
return decoder.decode(base64ToBytes(str))
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
bytesToBase64,
|
|
245
|
+
base64encode,
|
|
246
|
+
base64decode,
|
|
247
|
+
getBase64Code
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const isSupported = function () {
|
|
253
|
+
return new Promise(success => {
|
|
254
|
+
let solanaLoaded = false
|
|
255
|
+
const solanaDetection = function() {
|
|
256
|
+
if(window.solana !== undefined) {
|
|
257
|
+
solanaLoaded = true;
|
|
258
|
+
({ solana } = window)
|
|
259
|
+
success(true)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
window.addEventListener('load', solanaDetection)
|
|
263
|
+
setTimeout(() => {
|
|
264
|
+
window.removeEventListener('load', solanaDetection)
|
|
265
|
+
if(!solanaLoaded){
|
|
266
|
+
solanaDetection()
|
|
267
|
+
success(false)
|
|
268
|
+
}
|
|
269
|
+
}, 3000)
|
|
270
|
+
solanaDetection()
|
|
271
|
+
})
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const enable = function () {
|
|
275
|
+
return new Promise((success, reject) => {
|
|
276
|
+
solana.connect().then(response=> {
|
|
277
|
+
publicKey = response.publicKey.toString()
|
|
278
|
+
success(true)
|
|
279
|
+
}).catch(error=> {
|
|
280
|
+
reject(exceptionHandler('solana-web3js', error, '', ERRORS.WEB3_ERROR))
|
|
281
|
+
})
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const getAddress = function () {
|
|
286
|
+
return new Promise((success, reject) => {
|
|
287
|
+
if(publicKey === undefined) {
|
|
288
|
+
return reject(exceptionHandler('solana-web3js', 'NO PUBLIC ADDRESS', '', ERRORS.WEB3_ERROR))
|
|
289
|
+
}
|
|
290
|
+
return success(publicKey)
|
|
291
|
+
})
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const getSignature = function (address, nonce, message) {
|
|
295
|
+
return new Promise((success, reject) => {
|
|
296
|
+
const encodedMessage = new TextEncoder().encode(message + nonce)
|
|
297
|
+
solana.signMessage(encodedMessage, 'utf8').then(signedMessage => {
|
|
298
|
+
const signature = ByteBase64Converter().bytesToBase64(signedMessage.signature)
|
|
299
|
+
success(signature)
|
|
300
|
+
}).catch(error => {
|
|
301
|
+
let errorCode = ERRORS.WEB3_ERROR
|
|
302
|
+
if (error.code === 4001) {
|
|
303
|
+
errorCode = ERRORS.SIGNATURE_REJECTED
|
|
304
|
+
}
|
|
305
|
+
reject(exceptionHandler('web3js', error.message, '', errorCode))
|
|
306
|
+
})
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
isSupported,
|
|
312
|
+
enable,
|
|
313
|
+
getAddress,
|
|
314
|
+
getSignature,
|
|
315
|
+
ERRORS,
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export const CryptoIntegration = function () {
|
|
320
|
+
const ERRORS = {
|
|
321
|
+
API_KEY_MISSING: 1,
|
|
322
|
+
ACCOUNT_NOT_FOUND: 2,
|
|
323
|
+
CONNECTION_REJECTED: 3,
|
|
324
|
+
SIGNATURE_REJECTED: 4,
|
|
325
|
+
SIGNATURE_MISMATCHED: 5,
|
|
326
|
+
NOT_AUTHENTICATED:6,
|
|
327
|
+
WEB3_ERROR: 9,
|
|
328
|
+
SERVER_ERROR: 10,
|
|
329
|
+
METHOD_NOT_SUPPORTED_BY_BLOCKCHAIN: 11,
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const BLOCKCHAINS = [
|
|
333
|
+
'ethereum',
|
|
334
|
+
'solana'
|
|
335
|
+
]
|
|
336
|
+
|
|
337
|
+
const availableWallets = []
|
|
338
|
+
const supportedWallets = [
|
|
339
|
+
{
|
|
340
|
+
identifier: BLOCKCHAINS[0],
|
|
341
|
+
wrapper: EthereumWrapper(exception, ERRORS),
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
identifier: BLOCKCHAINS[1],
|
|
345
|
+
wrapper: SolanaWrapper(exception, ERRORS),
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
|
|
349
|
+
let selectedBlockchain
|
|
350
|
+
let walletWrapper
|
|
351
|
+
|
|
352
|
+
const getWalletWrapperByIdentifier = function (identifier) {
|
|
353
|
+
return supportedWallets.filter(wallet => wallet.identifier === identifier)[0]
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const generateOnSupportedMethod = function (identifier) {
|
|
357
|
+
return function (isSupported) {
|
|
358
|
+
if (isSupported) {
|
|
359
|
+
const confirmedWallet = getWalletWrapperByIdentifier(identifier)
|
|
360
|
+
availableWallets.push(confirmedWallet)
|
|
361
|
+
const event = new CustomEvent('ttf.crypto.new-wallet', { detail: { identifier } })
|
|
362
|
+
window.dispatchEvent(event)
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const checkAvailableWallets = function () {
|
|
368
|
+
for (let i = 0; i < supportedWallets.length; i++) {
|
|
369
|
+
const { wrapper } = supportedWallets[i]
|
|
370
|
+
const { identifier } = supportedWallets[i]
|
|
371
|
+
wrapper.isSupported().then(generateOnSupportedMethod(identifier))
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const setBlockchain = function (blockchain) {
|
|
376
|
+
walletWrapper = getWalletWrapperByIdentifier(blockchain).wrapper
|
|
377
|
+
selectedBlockchain = blockchain
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function exception(source, message, stacktrace, errorCode) {
|
|
381
|
+
return {
|
|
382
|
+
source,
|
|
383
|
+
message,
|
|
384
|
+
stacktrace,
|
|
385
|
+
errorCode
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const getAuthenticatedUserAddress = function () {
|
|
390
|
+
return new Promise(async (success, reject) => {
|
|
391
|
+
try {
|
|
392
|
+
const response = await cryptoAccount(selectedBlockchain)
|
|
393
|
+
success({
|
|
394
|
+
address: _get(response, 'data.data.crypto_address'),
|
|
395
|
+
nonce: _get(response, 'data.data.eth_nonce')
|
|
396
|
+
})
|
|
397
|
+
} catch(error) {
|
|
398
|
+
let message = _get(error, 'response.data.message')
|
|
399
|
+
const statusCode = _get(error, 'response.status')
|
|
400
|
+
if (!message) {
|
|
401
|
+
message = _get(error, 'response.statusText')
|
|
402
|
+
}
|
|
403
|
+
let errorCode = ERRORS.SERVER_ERROR
|
|
404
|
+
if (statusCode === 404) {
|
|
405
|
+
errorCode = ERRORS.ACCOUNT_NOT_FOUND
|
|
406
|
+
} else if (statusCode === 401) {
|
|
407
|
+
errorCode = ERRORS.NOT_AUTHENTICATED
|
|
408
|
+
}
|
|
409
|
+
reject(exception('backend', message, '', errorCode))
|
|
410
|
+
}
|
|
411
|
+
})
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const getNonceFromAddress = function (address) {
|
|
415
|
+
return new Promise(async (success, reject) => {
|
|
416
|
+
try {
|
|
417
|
+
const response = await cryptoAddress(selectedBlockchain, address)
|
|
418
|
+
const nonce = _get(response, 'data.data.eth_nonce')
|
|
419
|
+
success(nonce)
|
|
420
|
+
} catch(error) {
|
|
421
|
+
let message = _get(error, 'response.data.message')
|
|
422
|
+
const statusCode = _get(error, 'response.status')
|
|
423
|
+
if (!message) {
|
|
424
|
+
message = _get(error, 'response.statusText')
|
|
425
|
+
}
|
|
426
|
+
let errorCode = ERRORS.SERVER_ERROR
|
|
427
|
+
if (statusCode === 404) {
|
|
428
|
+
errorCode = ERRORS.ACCOUNT_NOT_FOUND
|
|
429
|
+
}
|
|
430
|
+
reject(exception('backend', message, '', errorCode))
|
|
431
|
+
}
|
|
432
|
+
})
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
const connectAddress = function (address, signature) {
|
|
436
|
+
return new Promise(async (success, reject) => {
|
|
437
|
+
try {
|
|
438
|
+
await cryptoConnect(selectedBlockchain, address, signature)
|
|
439
|
+
success()
|
|
440
|
+
} catch(error) {
|
|
441
|
+
let message = _get(error, 'response.data.message')
|
|
442
|
+
const statusCode = _get(error, 'response.status')
|
|
443
|
+
if (!message) {
|
|
444
|
+
message = _get(error, 'response.statusText')
|
|
445
|
+
}
|
|
446
|
+
let errorCode = ERRORS.SERVER_ERROR
|
|
447
|
+
if (statusCode === 404) {
|
|
448
|
+
errorCode = ERRORS.ACCOUNT_NOT_FOUND
|
|
449
|
+
} else if (statusCode === 422) {
|
|
450
|
+
errorCode = ERRORS.SIGNATURE_MISMATCHED
|
|
451
|
+
}
|
|
452
|
+
reject(exception('backend', message, '', errorCode))
|
|
453
|
+
}
|
|
454
|
+
})
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const authAddress = function (address, signature) {
|
|
458
|
+
return new Promise(async (success, reject) => {
|
|
459
|
+
try {
|
|
460
|
+
await authorizeWithWallet(address, signature, selectedBlockchain)
|
|
461
|
+
success()
|
|
462
|
+
} catch (error) {
|
|
463
|
+
let message = _get(error, 'response.data.message')
|
|
464
|
+
const statusCode = _get(error, 'response.status')
|
|
465
|
+
if (!message) {
|
|
466
|
+
message = _get(error, 'response.statusText')
|
|
467
|
+
}
|
|
468
|
+
let errorCode = ERRORS.SERVER_ERROR
|
|
469
|
+
if (statusCode === 404) {
|
|
470
|
+
errorCode = ERRORS.ACCOUNT_NOT_FOUND
|
|
471
|
+
} else if (statusCode === 422) {
|
|
472
|
+
errorCode = ERRORS.SIGNATURE_MISMATCHED
|
|
473
|
+
}
|
|
474
|
+
reject(exception('backend', message, '', errorCode))
|
|
475
|
+
}
|
|
476
|
+
})
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const isSupported = function () {
|
|
480
|
+
return walletWrapper.isSupported()
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
const enable = function () {
|
|
484
|
+
return walletWrapper.enable()
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const getAddress = function () {
|
|
488
|
+
return walletWrapper.getAddress()
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const getSignature = function (address, nonce, message) {
|
|
492
|
+
return walletWrapper.getSignature(address, nonce, message)
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const getA0k1verseNFTs = function (address, ticketHash, amount) {
|
|
496
|
+
if (walletWrapper.getA0k1verseNFTs instanceof Function) {
|
|
497
|
+
return walletWrapper.getA0k1verseNFTs(address, ticketHash, amount)
|
|
498
|
+
}
|
|
499
|
+
return new Promise((success, reject) =>
|
|
500
|
+
reject(exception('Core', 'Method not supported by ' + selectedBlockchain, '', ERRORS.METHOD_NOT_SUPPORTED_BY_BLOCKCHAIN))
|
|
501
|
+
)
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
const hasAccountChanged = function () {
|
|
505
|
+
if (walletWrapper.hasAccountChanged instanceof Function) {
|
|
506
|
+
return walletWrapper.hasAccountChanged()
|
|
507
|
+
}
|
|
508
|
+
return new Promise((success, reject) =>
|
|
509
|
+
reject(exception('Core', 'Method not supported by ' + selectedBlockchain, '', ERRORS.METHOD_NOT_SUPPORTED_BY_BLOCKCHAIN))
|
|
510
|
+
)
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
checkAvailableWallets()
|
|
514
|
+
return {
|
|
515
|
+
isSupported,
|
|
516
|
+
enable,
|
|
517
|
+
getAuthenticatedUserAddress,
|
|
518
|
+
getAddress,
|
|
519
|
+
getNonceFromAddress,
|
|
520
|
+
getSignature,
|
|
521
|
+
authAddress,
|
|
522
|
+
connectAddress,
|
|
523
|
+
setBlockchain,
|
|
524
|
+
getA0k1verseNFTs,
|
|
525
|
+
hasAccountChanged,
|
|
526
|
+
ERRORS,
|
|
527
|
+
}
|
|
528
|
+
}
|