@functionland/react-native-fula 1.55.15 → 1.55.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/LICENSE +20 -20
  2. package/android/build.gradle +114 -114
  3. package/android/gradle.properties +8 -8
  4. package/android/src/main/AndroidManifest.xml +3 -3
  5. package/android/src/main/AndroidManifestNew.xml +2 -2
  6. package/android/src/main/java/land/fx/fula/ConfigRef.java +7 -7
  7. package/android/src/main/java/land/fx/fula/Cryptography.java +62 -62
  8. package/android/src/main/java/land/fx/fula/FulaModule.java +0 -0
  9. package/android/src/main/java/land/fx/fula/FulaPackage.java +32 -32
  10. package/android/src/main/java/land/fx/fula/SharedPreferenceHelper.java +65 -65
  11. package/android/src/main/java/land/fx/fula/StaticHelper.java +13 -13
  12. package/android/src/main/java/land/fx/fula/ThreadUtils.java +42 -42
  13. package/ios/Cryptography.swift +59 -59
  14. package/ios/Fula-Bridging-Header.h +3 -3
  15. package/ios/Fula.mm +272 -272
  16. package/ios/Fula.swift +32 -21
  17. package/ios/UserDataHelper.swift +143 -143
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/interfaces/augment-api-consts.js.map +1 -1
  20. package/lib/commonjs/interfaces/augment-api-errors.js.map +1 -1
  21. package/lib/commonjs/interfaces/augment-api-events.js.map +1 -1
  22. package/lib/commonjs/interfaces/augment-api-query.js.map +1 -1
  23. package/lib/commonjs/interfaces/augment-api-rpc.js.map +1 -1
  24. package/lib/commonjs/interfaces/augment-api-runtime.js.map +1 -1
  25. package/lib/commonjs/interfaces/augment-api-tx.js.map +1 -1
  26. package/lib/commonjs/interfaces/augment-api.js.map +1 -1
  27. package/lib/commonjs/interfaces/augment-types.js.map +1 -1
  28. package/lib/commonjs/interfaces/definitions.js.map +1 -1
  29. package/lib/commonjs/interfaces/defintions.js.map +1 -1
  30. package/lib/commonjs/interfaces/fulaNativeModule.js.map +1 -1
  31. package/lib/commonjs/interfaces/index.js.map +1 -1
  32. package/lib/commonjs/interfaces/lookup.js +300 -300
  33. package/lib/commonjs/interfaces/lookup.js.map +1 -1
  34. package/lib/commonjs/interfaces/registry.js.map +1 -1
  35. package/lib/commonjs/interfaces/types-lookup.js.map +1 -1
  36. package/lib/commonjs/interfaces/types.js.map +1 -1
  37. package/lib/commonjs/protocols/blockchain.js +70 -70
  38. package/lib/commonjs/protocols/blockchain.js.map +1 -1
  39. package/lib/commonjs/protocols/chain-api.js.map +1 -1
  40. package/lib/commonjs/protocols/fula.js.map +1 -1
  41. package/lib/commonjs/protocols/fx-ai.js.map +1 -1
  42. package/lib/commonjs/protocols/fxblox.js +3 -3
  43. package/lib/commonjs/protocols/fxblox.js.map +1 -1
  44. package/lib/commonjs/types/blockchain.js.map +1 -1
  45. package/lib/commonjs/types/fxblox.js.map +1 -1
  46. package/lib/module/index.js.map +1 -1
  47. package/lib/module/interfaces/augment-api-consts.js.map +1 -1
  48. package/lib/module/interfaces/augment-api-errors.js.map +1 -1
  49. package/lib/module/interfaces/augment-api-events.js.map +1 -1
  50. package/lib/module/interfaces/augment-api-query.js.map +1 -1
  51. package/lib/module/interfaces/augment-api-rpc.js.map +1 -1
  52. package/lib/module/interfaces/augment-api-runtime.js.map +1 -1
  53. package/lib/module/interfaces/augment-api-tx.js.map +1 -1
  54. package/lib/module/interfaces/augment-api.js.map +1 -1
  55. package/lib/module/interfaces/augment-types.js.map +1 -1
  56. package/lib/module/interfaces/definitions.js.map +1 -1
  57. package/lib/module/interfaces/defintions.js.map +1 -1
  58. package/lib/module/interfaces/fulaNativeModule.js.map +1 -1
  59. package/lib/module/interfaces/index.js.map +1 -1
  60. package/lib/module/interfaces/lookup.js +300 -300
  61. package/lib/module/interfaces/lookup.js.map +1 -1
  62. package/lib/module/interfaces/registry.js.map +1 -1
  63. package/lib/module/interfaces/types-lookup.js.map +1 -1
  64. package/lib/module/interfaces/types.js.map +1 -1
  65. package/lib/module/protocols/blockchain.js +70 -70
  66. package/lib/module/protocols/blockchain.js.map +1 -1
  67. package/lib/module/protocols/chain-api.js.map +1 -1
  68. package/lib/module/protocols/fula.js.map +1 -1
  69. package/lib/module/protocols/fx-ai.js.map +1 -1
  70. package/lib/module/protocols/fxblox.js +3 -3
  71. package/lib/module/protocols/fxblox.js.map +1 -1
  72. package/lib/module/types/blockchain.js.map +1 -1
  73. package/lib/module/types/fxblox.js.map +1 -1
  74. package/package.json +177 -176
  75. package/src/index.tsx +4 -4
  76. package/src/interfaces/augment-api-consts.ts +273 -273
  77. package/src/interfaces/augment-api-errors.ts +474 -474
  78. package/src/interfaces/augment-api-events.ts +448 -448
  79. package/src/interfaces/augment-api-query.ts +466 -466
  80. package/src/interfaces/augment-api-rpc.ts +617 -617
  81. package/src/interfaces/augment-api-runtime.ts +223 -223
  82. package/src/interfaces/augment-api-tx.ts +709 -709
  83. package/src/interfaces/augment-api.ts +9 -9
  84. package/src/interfaces/augment-types.ts +1322 -1322
  85. package/src/interfaces/definitions.ts +1 -1
  86. package/src/interfaces/defintions.ts +1 -1
  87. package/src/interfaces/index.ts +3 -3
  88. package/src/interfaces/lookup.ts +2011 -2011
  89. package/src/interfaces/registry.ts +163 -163
  90. package/src/interfaces/types-lookup.ts +2165 -2165
  91. package/src/interfaces/types.ts +2 -2
  92. package/src/protocols/blockchain.ts +716 -716
  93. package/src/protocols/fxblox.ts +442 -442
@@ -1,716 +1,716 @@
1
- import Fula from '../interfaces/fulaNativeModule';
2
- import type * as BType from '../types/blockchain';
3
- import { ApiPromise } from '@polkadot/api';
4
- /*
5
- createAccount: This function takes a seed argument, which is used to create an account. The seed must start with "/". The function returns a promise of an object that contains the seed and the account that was created.
6
- */
7
- export const createAccount = (
8
- seed: string //seed that is used to create the account. It must start with "/"
9
- ): Promise<BType.SeededResponse> => {
10
- console.log('createAccount in react-native started', seed);
11
- let res1 = Fula.createAccount(seed)
12
- .then((res) => {
13
- try {
14
- let jsonRes: BType.SeededResponse = JSON.parse(res);
15
- return jsonRes;
16
- } catch (e) {
17
- try {
18
- return JSON.parse(res);
19
- } catch (e2) {
20
- return res;
21
- }
22
- }
23
- })
24
- .catch((err) => {
25
- return err;
26
- });
27
- return res1;
28
- };
29
-
30
- /*
31
- checkAccountExists: This function takes an account argument, and returns a promise of an object that contains the account and a boolean exists flag. If exists is true, it means the account exists, otherwise, the account does not exist
32
- */
33
- export const checkAccountExists = (
34
- account: string
35
- ): Promise<BType.AccountExistsResponse> => {
36
- console.log('checkAccountExists in react-native started', account);
37
- let res1 = Fula.checkAccountExists(account)
38
- .then((res) => {
39
- try {
40
- let jsonRes: BType.AccountExistsResponse = JSON.parse(res);
41
- return jsonRes;
42
- } catch (e) {
43
- try {
44
- return JSON.parse(res);
45
- } catch (e2) {
46
- return res;
47
- }
48
- }
49
- })
50
- .catch((err) => {
51
- return err;
52
- });
53
- return res1;
54
- };
55
-
56
- /*
57
- accountFund: This function takes an account argument, and returns a promise of an object that contains the account and a boolean exists flag. If exists is true, it means the account exists, otherwise, the account does not exist
58
- */
59
- export const accountFund = (
60
- account: string
61
- ): Promise<BType.AccountFundResponse> => {
62
- console.log('accountFund in react-native started', account);
63
- let res1 = Fula.accountFund(account)
64
- .then((res) => {
65
- try {
66
- let jsonRes: BType.AccountFundResponse = JSON.parse(res);
67
- return jsonRes;
68
- } catch (e) {
69
- try {
70
- return JSON.parse(res);
71
- } catch (e2) {
72
- return res;
73
- }
74
- }
75
- })
76
- .catch((err) => {
77
- return err;
78
- });
79
- return res1;
80
- };
81
-
82
- /*
83
- createPool: This function takes two arguments: seed and poolName. The seed is used to identify the account that is creating the pool, and the poolName is the name of the pool being created. The function returns a promise of an object that contains the owner of the pool and the poolID of the created pool.
84
- */
85
- export const createPool = (
86
- seed: string,
87
- poolName: string
88
- ): Promise<BType.PoolCreateResponse> => {
89
- console.log('createPool in react-native started', seed, poolName);
90
- let res1 = Fula.createPool(seed, poolName)
91
- .then((res) => {
92
- try {
93
- let jsonRes: BType.PoolCreateResponse = JSON.parse(res);
94
- return jsonRes;
95
- } catch (e) {
96
- try {
97
- return JSON.parse(res);
98
- } catch (e2) {
99
- return res;
100
- }
101
- }
102
- })
103
- .catch((err) => {
104
- return err;
105
- });
106
- return res1;
107
- };
108
-
109
- /*
110
- listPools: This function takes no arguments and returns a promise of an object that contains a list of pools. Each pool in the list contains the poolID, owner, poolName, parent, and participants of the pool
111
- */
112
- export const listPools = (): Promise<BType.PoolListResponse> => {
113
- console.log('listPools in react-native started');
114
- let res1 = Fula.listPools()
115
- .then((res) => {
116
- try {
117
- let jsonRes: BType.PoolListResponse = JSON.parse(res);
118
- return jsonRes;
119
- } catch (e) {
120
- try {
121
- return JSON.parse(res);
122
- } catch (e2) {
123
- return res;
124
- }
125
- }
126
- })
127
- .catch((err) => {
128
- return err;
129
- });
130
- return res1;
131
- };
132
-
133
- /*
134
- joinPool: This function takes two arguments: seed and poolID. The seed is used to identify the account that is joining the pool, and the poolID is the ID of the pool the account is joining. The function returns a promise of an object that contains the account joining the pool and the poolID of the joined pool.
135
- */
136
-
137
- export const joinPool = (poolID: number): Promise<BType.PoolJoinResponse> => {
138
- console.log('joinPool in react-native started', poolID);
139
- let res1 = Fula.joinPool(poolID.toString())
140
- .then((res) => {
141
- try {
142
- let jsonRes: BType.PoolJoinResponse = JSON.parse(res);
143
- return jsonRes;
144
- } catch (e) {
145
- try {
146
- return JSON.parse(res);
147
- } catch (e2) {
148
- console.error('Error parsing res in joining pool:', e);
149
- return res; // Rethrow the error to maintain the rejection state
150
- }
151
- }
152
- })
153
- .catch((err) => {
154
- console.error('Error joining pool:', err);
155
- throw err; // Rethrow the error to maintain the rejection state
156
- });
157
- return res1;
158
- };
159
-
160
- /*
161
- leavePool: This function takes two arguments: seed and poolID. The seed is used to identify the account that is leaving the pool, and the poolID is the ID of the pool the account is leaving. The function returns a promise of an object that contains the `
162
- */
163
-
164
- export const leavePool = (poolID: number): Promise<BType.PoolLeaveResponse> => {
165
- console.log('leavePool in react-native started', poolID);
166
- let res1 = Fula.leavePool(poolID.toString())
167
- .then((res) => {
168
- try {
169
- let jsonRes: BType.PoolLeaveResponse = JSON.parse(res);
170
- return jsonRes;
171
- } catch (e) {
172
- try {
173
- return JSON.parse(res);
174
- } catch (e2) {
175
- return res;
176
- }
177
- }
178
- })
179
- .catch((err) => {
180
- return err;
181
- });
182
- return res1;
183
- };
184
-
185
- /*
186
- joinPoolWithChain: This function takes two arguments: poolID and chainName. The poolID is the ID of the pool to join, and the chainName specifies the blockchain network to use for the operation. The function returns a promise of an object that contains the account and poolID.
187
- */
188
- export const joinPoolWithChain = (poolID: number, chainName: string): Promise<BType.PoolJoinResponse> => {
189
- console.log('joinPoolWithChain in react-native started', poolID, chainName);
190
-
191
- // Validate inputs
192
- if (typeof poolID !== 'number' || poolID <= 0) {
193
- return Promise.reject(new Error('Pool ID must be a positive number'));
194
- }
195
-
196
- if (typeof chainName !== 'string' || chainName.trim().length === 0) {
197
- return Promise.reject(new Error('Chain name must be a non-empty string'));
198
- }
199
-
200
- let res1 = Fula.joinPoolWithChain(poolID.toString(), chainName.trim())
201
- .then((res) => {
202
- try {
203
- let jsonRes: BType.PoolJoinResponse = JSON.parse(res);
204
- return jsonRes;
205
- } catch (e) {
206
- try {
207
- return JSON.parse(res);
208
- } catch (e2) {
209
- console.error('Error parsing res in joining pool with chain:', e);
210
- return res; // Return raw response if parsing fails
211
- }
212
- }
213
- })
214
- .catch((err) => {
215
- console.error('Error joining pool with chain:', err);
216
- throw err; // Rethrow the error to maintain the rejection state
217
- });
218
- return res1;
219
- };
220
-
221
- /*
222
- leavePoolWithChain: This function takes two arguments: poolID and chainName. The poolID is the ID of the pool to leave, and the chainName specifies the blockchain network to use for the operation. The function returns a promise of an object that contains the account and poolID.
223
- */
224
- export const leavePoolWithChain = (poolID: number, chainName: string): Promise<BType.PoolLeaveResponse> => {
225
- console.log('leavePoolWithChain in react-native started', poolID, chainName);
226
-
227
- // Validate inputs
228
- if (typeof poolID !== 'number' || poolID <= 0) {
229
- return Promise.reject(new Error('Pool ID must be a positive number'));
230
- }
231
-
232
- if (typeof chainName !== 'string' || chainName.trim().length === 0) {
233
- return Promise.reject(new Error('Chain name must be a non-empty string'));
234
- }
235
-
236
- let res1 = Fula.leavePoolWithChain(poolID.toString(), chainName.trim())
237
- .then((res) => {
238
- try {
239
- let jsonRes: BType.PoolLeaveResponse = JSON.parse(res);
240
- return jsonRes;
241
- } catch (e) {
242
- try {
243
- return JSON.parse(res);
244
- } catch (e2) {
245
- console.error('Error parsing res in leaving pool with chain:', e);
246
- return res; // Return raw response if parsing fails
247
- }
248
- }
249
- })
250
- .catch((err) => {
251
- console.error('Error leaving pool with chain:', err);
252
- throw err; // Rethrow the error to maintain the rejection state
253
- });
254
- return res1;
255
- };
256
-
257
- export const cancelPoolJoin = (
258
- poolID: number
259
- ): Promise<BType.PoolCancelJoinResponse> => {
260
- console.log('cancelPoolJoin in react-native started', poolID);
261
- let res1 = Fula.cancelPoolJoin(poolID.toString())
262
- .then((res) => {
263
- try {
264
- let jsonRes: BType.PoolCancelJoinResponse = JSON.parse(res);
265
- return jsonRes;
266
- } catch (e) {
267
- try {
268
- return JSON.parse(res);
269
- } catch (e2) {
270
- return res;
271
- }
272
- }
273
- })
274
- .catch((err) => {
275
- return err;
276
- });
277
- return res1;
278
- };
279
- export const listPoolJoinRequests = (
280
- poolID: string
281
- ): Promise<BType.PoolRequestsResponse> => {
282
- console.log('listPoolJoinRequests in react-native started', poolID);
283
- let res1 = Fula.listPoolJoinRequests(poolID)
284
- .then((res) => {
285
- try {
286
- let jsonRes: BType.PoolRequestsResponse = JSON.parse(res);
287
- return jsonRes;
288
- } catch (e) {
289
- try {
290
- return JSON.parse(res);
291
- } catch (e2) {
292
- return res;
293
- }
294
- }
295
- })
296
- .catch((err) => {
297
- return err;
298
- });
299
- return res1;
300
- };
301
-
302
- /*
303
- seed is used to authorize the request.
304
- poolID is the ID of the pool in which the account is requesting to join.
305
- account is the account that is requesting to join the pool.
306
- accept is a boolean value that indicates whether to accept or reject the join request.
307
- It returns a promise of BType.PoolVoteResponse which includes the account and poolID
308
- */
309
- export const votePoolJoinRequest = (
310
- seed: string,
311
- poolID: number,
312
- account: string,
313
- accept: boolean
314
- ): Promise<BType.PoolVoteResponse> => {
315
- console.log(
316
- 'votePoolJoinRequest in react-native started',
317
- seed,
318
- poolID,
319
- account,
320
- accept
321
- );
322
- let res1 = Fula.votePoolJoinRequest(seed, poolID, account, accept)
323
- .then((res) => {
324
- try {
325
- let jsonRes: BType.PoolVoteResponse = JSON.parse(res);
326
- return jsonRes;
327
- } catch (e) {
328
- try {
329
- return JSON.parse(res);
330
- } catch (e2) {
331
- return res;
332
- }
333
- }
334
- })
335
- .catch((err) => {
336
- return err;
337
- });
338
- return res1;
339
- };
340
-
341
- /*
342
- It takes four arguments:
343
-
344
- seed is used to authorize the request.
345
- poolID is the ID of the pool in which the replication request is made.
346
- replicationFactor is the number of copies of the content to be stored.
347
- cid is the content identifier of the content to be replicated.
348
- It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
349
- */
350
- export const batchUploadManifest = (
351
- api: ApiPromise | undefined, //this is just for compatibility with chainAPI inputs and is not used
352
- seed: string, //this is just for compatibility with chainAPI inputs and is not used
353
- cids_i: string[],
354
- poolId_i: string | number,
355
- replicationFactor_i: string | number
356
- ): Promise<BType.ManifestBatchUploadResponse> => {
357
- console.log(
358
- 'newReplicationRequest in react-native started',
359
- api,
360
- seed,
361
- poolId_i,
362
- replicationFactor_i,
363
- cids_i
364
- );
365
- if (typeof poolId_i === 'number') {
366
- poolId_i = poolId_i.toString();
367
- }
368
- if (typeof replicationFactor_i === 'number') {
369
- replicationFactor_i = replicationFactor_i.toString();
370
- }
371
- let res1 = Fula.batchUploadManifest(cids_i, poolId_i, replicationFactor_i)
372
- .then((res) => {
373
- try {
374
- let jsonRes: BType.ManifestBatchUploadResponse = JSON.parse(res);
375
- return jsonRes;
376
- } catch (e) {
377
- try {
378
- return JSON.parse(res);
379
- } catch (e2) {
380
- return res;
381
- }
382
- }
383
- })
384
- .catch((err) => {
385
- return err;
386
- });
387
- return res1;
388
- };
389
-
390
- export const replicateInPool = (
391
- cids_i: string[],
392
- account_i: string,
393
- poolId_i: string | number
394
- ): Promise<string[]> => {
395
- console.log(
396
- 'replicateInPool in react-native started',
397
- poolId_i,
398
- account_i,
399
- cids_i
400
- );
401
- if (typeof poolId_i === 'number') {
402
- poolId_i = poolId_i.toString();
403
- }
404
-
405
- let res1 = Fula.replicateInPool(cids_i, account_i, poolId_i)
406
- .then((res) => {
407
- try {
408
- let jsonRes: string[] = JSON.parse(res);
409
- return jsonRes;
410
- } catch (e) {
411
- try {
412
- return JSON.parse(res);
413
- } catch (e2) {
414
- return res;
415
- }
416
- }
417
- })
418
- .catch((err) => {
419
- return err;
420
- });
421
- return res1;
422
- };
423
-
424
- /*
425
- It takes four arguments:
426
-
427
- seed is used to authorize the request.
428
- poolID is the ID of the pool in which the replication request is made.
429
- uploader is the account of the user making the request
430
- cid is the content identifier of the content to be stored.
431
- It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
432
- */
433
- export const newStoreRequest = (
434
- seed: string,
435
- poolID: number,
436
- uploader: string,
437
- cid: string
438
- ): Promise<BType.ManifestUploadResponse> => {
439
- console.log(
440
- 'newStoreRequest in react-native started',
441
- seed,
442
- poolID,
443
- uploader,
444
- cid
445
- );
446
- let res1 = Fula.newStoreRequest(seed, poolID, uploader, cid)
447
- .then((res) => {
448
- try {
449
- let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
450
- return jsonRes;
451
- } catch (e) {
452
- try {
453
- return JSON.parse(res);
454
- } catch (e2) {
455
- return res;
456
- }
457
- }
458
- })
459
- .catch((err) => {
460
- return err;
461
- });
462
- return res1;
463
- };
464
-
465
- /*
466
- It takes one argument:
467
-
468
- poolID is the ID of the pool for which the replication requests are listed
469
- It returns a promise of BType.ManifestUploadResponse[] which is an array of the replication requests, including the uploader, storage, ManifestMetadata, and poolID
470
- */
471
- export const listAvailableReplicationRequests = (
472
- poolID: string
473
- ): Promise<BType.ManifestUploadResponse[]> => {
474
- console.log(
475
- 'listAvailableReplicationRequests in react-native started',
476
- poolID
477
- );
478
- let res1 = Fula.listAvailableReplicationRequests(poolID)
479
- .then((res) => {
480
- try {
481
- let jsonRes: BType.ManifestUploadResponse[] = JSON.parse(res);
482
- return jsonRes;
483
- } catch (e) {
484
- try {
485
- return JSON.parse(res);
486
- } catch (e2) {
487
- return res;
488
- }
489
- }
490
- })
491
- .catch((err) => {
492
- return err;
493
- });
494
- return res1;
495
- };
496
-
497
- /*
498
- It takes three arguments:
499
-
500
- seed is the seed of the account that is removing the replication request
501
- poolID is the ID of the pool for which the replication request is being removed
502
- cid is the content ID of the replication request being removed
503
- It returns a promise of BType.ManifestUploadResponse which is the removed replication request, including the uploader, storage, ManifestMetadata, and poolID
504
- */
505
- export const removeReplicationRequest = (
506
- seed: string,
507
- poolID: number,
508
- cid: string
509
- ): Promise<BType.ManifestUploadResponse> => {
510
- console.log(
511
- 'removeReplicationRequest in react-native started',
512
- seed,
513
- poolID,
514
- cid
515
- );
516
- let res1 = Fula.removeReplicationRequest(seed, poolID, cid)
517
- .then((res) => {
518
- try {
519
- let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
520
- return jsonRes;
521
- } catch (e) {
522
- try {
523
- return JSON.parse(res);
524
- } catch (e2) {
525
- return res;
526
- }
527
- }
528
- })
529
- .catch((err) => {
530
- return err;
531
- });
532
- return res1;
533
- };
534
-
535
- /*
536
- It takes four arguments:
537
-
538
- seed is the seed of the account that is removing the storer
539
- storer is the address of the storer that is being removed
540
- poolID is the ID of the pool for which the storer is being removed
541
- cid is the content ID of the replication request for which the storer is being removed
542
- It returns a promise of BType.ManifestUploadResponse which is the replication request, including the uploader, storage, ManifestMetadata, and poolID after the storer has been removed.
543
- */
544
- export const removeStorer = (
545
- seed: string,
546
- storer: string,
547
- poolID: number,
548
- cid: string
549
- ): Promise<BType.ManifestUploadResponse> => {
550
- console.log(
551
- 'removeStorer in react-native started',
552
- seed,
553
- storer,
554
- poolID,
555
- cid
556
- );
557
- let res1 = Fula.removeStorer(seed, storer, poolID, cid)
558
- .then((res) => {
559
- try {
560
- let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
561
- return jsonRes;
562
- } catch (e) {
563
- try {
564
- return JSON.parse(res);
565
- } catch (e2) {
566
- return res;
567
- }
568
- }
569
- })
570
- .catch((err) => {
571
- return err;
572
- });
573
- return res1;
574
- };
575
-
576
- /*
577
- It takes four arguments:
578
-
579
- seed is the seed of the account that is removing the stored replication
580
- uploader is the address of the uploader that is being removed
581
- poolID is the ID of the pool for which the stored replication is being removed
582
- cid is the content ID of the replication request for which the stored replication is being removed
583
- It returns a promise of BType.ManifestUploadResponse which is the replication request, including the uploader, storage, ManifestMetadata, and poolID after the stored replication has been removed.
584
- */
585
- export const removeStoredReplication = (
586
- seed: string,
587
- uploader: string,
588
- poolID: number,
589
- cid: string
590
- ): Promise<BType.ManifestUploadResponse> => {
591
- console.log(
592
- 'removeStoredReplication in react-native started',
593
- seed,
594
- uploader,
595
- poolID,
596
- cid
597
- );
598
- let res1 = Fula.removeStoredReplication(seed, uploader, poolID, cid)
599
- .then((res) => {
600
- try {
601
- let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
602
- return jsonRes;
603
- } catch (e) {
604
- try {
605
- return JSON.parse(res);
606
- } catch (e2) {
607
- return res;
608
- }
609
- }
610
- })
611
- .catch((err) => {
612
- return err;
613
- });
614
- return res1;
615
- };
616
-
617
- /*
618
- bloxFreeSpace: This function takes no arguments and returns a promise of an object that contains the blox free space information.
619
- */
620
- export const bloxFreeSpace = (): Promise<BType.BloxFreeSpaceResponse> => {
621
- console.log('bloxFreeSpace in react-native started');
622
- let res1 = Fula.bloxFreeSpace()
623
- .then((res) => {
624
- try {
625
- let jsonRes: BType.BloxFreeSpaceResponse = JSON.parse(res);
626
- return jsonRes;
627
- } catch (e) {
628
- try {
629
- return JSON.parse(res);
630
- } catch (e2) {
631
- return res;
632
- }
633
- }
634
- })
635
- .catch((err) => {
636
- return err;
637
- });
638
- return res1;
639
- };
640
-
641
- export const getAccount = (): Promise<BType.GetAccountResponse> => {
642
- console.log('getAccount in react-native started');
643
- let res = Fula.getAccount()
644
- .then((res1) => {
645
- try {
646
- let jsonRes: BType.GetAccountResponse = JSON.parse(res1);
647
- return jsonRes;
648
- } catch (e) {
649
- try {
650
- return JSON.parse(res1);
651
- } catch (e1) {
652
- console.error('Error parsing res in get account:', e1);
653
- throw e1; // Rethrow the error to maintain the rejection state
654
- }
655
- }
656
- })
657
- .catch((err) => {
658
- console.error('Error getting account:', err);
659
- throw err; // Rethrow the error to maintain the rejection state
660
- });
661
- return res;
662
- };
663
-
664
- export const assetsBalance = (
665
- account: string,
666
- assetId: string,
667
- classId: string
668
- ): Promise<BType.AssetsBalanceResponse> => {
669
- console.log('assetsBalance in react-native started');
670
- let res = Fula.assetsBalance(account, assetId, classId)
671
- .then((res1) => {
672
- try {
673
- let jsonRes: BType.AssetsBalanceResponse = JSON.parse(res1);
674
- return jsonRes;
675
- } catch (e) {
676
- try {
677
- return JSON.parse(res1);
678
- } catch (e1) {
679
- console.error('Error parsing res in get asset balance:', e1);
680
- throw e1; // Rethrow the error to maintain the rejection state
681
- }
682
- }
683
- })
684
- .catch((err) => {
685
- console.error('Error getting asset balance:', err);
686
- throw err; // Rethrow the error to maintain the rejection state
687
- });
688
- return res;
689
- };
690
-
691
- export const transferToFula = (
692
- amount: string,
693
- wallet: string,
694
- chain: string
695
- ): Promise<BType.TransferToFulaResponse> => {
696
- console.log('transferToFula in react-native started');
697
- let res = Fula.transferToFula(amount, wallet, chain)
698
- .then((res1) => {
699
- try {
700
- let jsonRes: BType.TransferToFulaResponse = JSON.parse(res1);
701
- return jsonRes;
702
- } catch (e) {
703
- try {
704
- return JSON.parse(res1);
705
- } catch (e1) {
706
- console.error('Error parsing res in transferToFula:', e1);
707
- throw e1; // Rethrow the error to maintain the rejection state
708
- }
709
- }
710
- })
711
- .catch((err) => {
712
- console.error('Error getting transferToFula:', err);
713
- throw err; // Rethrow the error to maintain the rejection state
714
- });
715
- return res;
716
- };
1
+ import Fula from '../interfaces/fulaNativeModule';
2
+ import type * as BType from '../types/blockchain';
3
+ import { ApiPromise } from '@polkadot/api';
4
+ /*
5
+ createAccount: This function takes a seed argument, which is used to create an account. The seed must start with "/". The function returns a promise of an object that contains the seed and the account that was created.
6
+ */
7
+ export const createAccount = (
8
+ seed: string //seed that is used to create the account. It must start with "/"
9
+ ): Promise<BType.SeededResponse> => {
10
+ console.log('createAccount in react-native started', seed);
11
+ let res1 = Fula.createAccount(seed)
12
+ .then((res) => {
13
+ try {
14
+ let jsonRes: BType.SeededResponse = JSON.parse(res);
15
+ return jsonRes;
16
+ } catch (e) {
17
+ try {
18
+ return JSON.parse(res);
19
+ } catch (e2) {
20
+ return res;
21
+ }
22
+ }
23
+ })
24
+ .catch((err) => {
25
+ return err;
26
+ });
27
+ return res1;
28
+ };
29
+
30
+ /*
31
+ checkAccountExists: This function takes an account argument, and returns a promise of an object that contains the account and a boolean exists flag. If exists is true, it means the account exists, otherwise, the account does not exist
32
+ */
33
+ export const checkAccountExists = (
34
+ account: string
35
+ ): Promise<BType.AccountExistsResponse> => {
36
+ console.log('checkAccountExists in react-native started', account);
37
+ let res1 = Fula.checkAccountExists(account)
38
+ .then((res) => {
39
+ try {
40
+ let jsonRes: BType.AccountExistsResponse = JSON.parse(res);
41
+ return jsonRes;
42
+ } catch (e) {
43
+ try {
44
+ return JSON.parse(res);
45
+ } catch (e2) {
46
+ return res;
47
+ }
48
+ }
49
+ })
50
+ .catch((err) => {
51
+ return err;
52
+ });
53
+ return res1;
54
+ };
55
+
56
+ /*
57
+ accountFund: This function takes an account argument, and returns a promise of an object that contains the account and a boolean exists flag. If exists is true, it means the account exists, otherwise, the account does not exist
58
+ */
59
+ export const accountFund = (
60
+ account: string
61
+ ): Promise<BType.AccountFundResponse> => {
62
+ console.log('accountFund in react-native started', account);
63
+ let res1 = Fula.accountFund(account)
64
+ .then((res) => {
65
+ try {
66
+ let jsonRes: BType.AccountFundResponse = JSON.parse(res);
67
+ return jsonRes;
68
+ } catch (e) {
69
+ try {
70
+ return JSON.parse(res);
71
+ } catch (e2) {
72
+ return res;
73
+ }
74
+ }
75
+ })
76
+ .catch((err) => {
77
+ return err;
78
+ });
79
+ return res1;
80
+ };
81
+
82
+ /*
83
+ createPool: This function takes two arguments: seed and poolName. The seed is used to identify the account that is creating the pool, and the poolName is the name of the pool being created. The function returns a promise of an object that contains the owner of the pool and the poolID of the created pool.
84
+ */
85
+ export const createPool = (
86
+ seed: string,
87
+ poolName: string
88
+ ): Promise<BType.PoolCreateResponse> => {
89
+ console.log('createPool in react-native started', seed, poolName);
90
+ let res1 = Fula.createPool(seed, poolName)
91
+ .then((res) => {
92
+ try {
93
+ let jsonRes: BType.PoolCreateResponse = JSON.parse(res);
94
+ return jsonRes;
95
+ } catch (e) {
96
+ try {
97
+ return JSON.parse(res);
98
+ } catch (e2) {
99
+ return res;
100
+ }
101
+ }
102
+ })
103
+ .catch((err) => {
104
+ return err;
105
+ });
106
+ return res1;
107
+ };
108
+
109
+ /*
110
+ listPools: This function takes no arguments and returns a promise of an object that contains a list of pools. Each pool in the list contains the poolID, owner, poolName, parent, and participants of the pool
111
+ */
112
+ export const listPools = (): Promise<BType.PoolListResponse> => {
113
+ console.log('listPools in react-native started');
114
+ let res1 = Fula.listPools()
115
+ .then((res) => {
116
+ try {
117
+ let jsonRes: BType.PoolListResponse = JSON.parse(res);
118
+ return jsonRes;
119
+ } catch (e) {
120
+ try {
121
+ return JSON.parse(res);
122
+ } catch (e2) {
123
+ return res;
124
+ }
125
+ }
126
+ })
127
+ .catch((err) => {
128
+ return err;
129
+ });
130
+ return res1;
131
+ };
132
+
133
+ /*
134
+ joinPool: This function takes two arguments: seed and poolID. The seed is used to identify the account that is joining the pool, and the poolID is the ID of the pool the account is joining. The function returns a promise of an object that contains the account joining the pool and the poolID of the joined pool.
135
+ */
136
+
137
+ export const joinPool = (poolID: number): Promise<BType.PoolJoinResponse> => {
138
+ console.log('joinPool in react-native started', poolID);
139
+ let res1 = Fula.joinPool(poolID.toString())
140
+ .then((res) => {
141
+ try {
142
+ let jsonRes: BType.PoolJoinResponse = JSON.parse(res);
143
+ return jsonRes;
144
+ } catch (e) {
145
+ try {
146
+ return JSON.parse(res);
147
+ } catch (e2) {
148
+ console.error('Error parsing res in joining pool:', e);
149
+ return res; // Rethrow the error to maintain the rejection state
150
+ }
151
+ }
152
+ })
153
+ .catch((err) => {
154
+ console.error('Error joining pool:', err);
155
+ throw err; // Rethrow the error to maintain the rejection state
156
+ });
157
+ return res1;
158
+ };
159
+
160
+ /*
161
+ leavePool: This function takes two arguments: seed and poolID. The seed is used to identify the account that is leaving the pool, and the poolID is the ID of the pool the account is leaving. The function returns a promise of an object that contains the `
162
+ */
163
+
164
+ export const leavePool = (poolID: number): Promise<BType.PoolLeaveResponse> => {
165
+ console.log('leavePool in react-native started', poolID);
166
+ let res1 = Fula.leavePool(poolID.toString())
167
+ .then((res) => {
168
+ try {
169
+ let jsonRes: BType.PoolLeaveResponse = JSON.parse(res);
170
+ return jsonRes;
171
+ } catch (e) {
172
+ try {
173
+ return JSON.parse(res);
174
+ } catch (e2) {
175
+ return res;
176
+ }
177
+ }
178
+ })
179
+ .catch((err) => {
180
+ return err;
181
+ });
182
+ return res1;
183
+ };
184
+
185
+ /*
186
+ joinPoolWithChain: This function takes two arguments: poolID and chainName. The poolID is the ID of the pool to join, and the chainName specifies the blockchain network to use for the operation. The function returns a promise of an object that contains the account and poolID.
187
+ */
188
+ export const joinPoolWithChain = (poolID: number, chainName: string): Promise<BType.PoolJoinResponse> => {
189
+ console.log('joinPoolWithChain in react-native started', poolID, chainName);
190
+
191
+ // Validate inputs
192
+ if (typeof poolID !== 'number' || poolID <= 0) {
193
+ return Promise.reject(new Error('Pool ID must be a positive number'));
194
+ }
195
+
196
+ if (typeof chainName !== 'string' || chainName.trim().length === 0) {
197
+ return Promise.reject(new Error('Chain name must be a non-empty string'));
198
+ }
199
+
200
+ let res1 = Fula.joinPoolWithChain(poolID.toString(), chainName.trim())
201
+ .then((res) => {
202
+ try {
203
+ let jsonRes: BType.PoolJoinResponse = JSON.parse(res);
204
+ return jsonRes;
205
+ } catch (e) {
206
+ try {
207
+ return JSON.parse(res);
208
+ } catch (e2) {
209
+ console.error('Error parsing res in joining pool with chain:', e);
210
+ return res; // Return raw response if parsing fails
211
+ }
212
+ }
213
+ })
214
+ .catch((err) => {
215
+ console.error('Error joining pool with chain:', err);
216
+ throw err; // Rethrow the error to maintain the rejection state
217
+ });
218
+ return res1;
219
+ };
220
+
221
+ /*
222
+ leavePoolWithChain: This function takes two arguments: poolID and chainName. The poolID is the ID of the pool to leave, and the chainName specifies the blockchain network to use for the operation. The function returns a promise of an object that contains the account and poolID.
223
+ */
224
+ export const leavePoolWithChain = (poolID: number, chainName: string): Promise<BType.PoolLeaveResponse> => {
225
+ console.log('leavePoolWithChain in react-native started', poolID, chainName);
226
+
227
+ // Validate inputs
228
+ if (typeof poolID !== 'number' || poolID <= 0) {
229
+ return Promise.reject(new Error('Pool ID must be a positive number'));
230
+ }
231
+
232
+ if (typeof chainName !== 'string' || chainName.trim().length === 0) {
233
+ return Promise.reject(new Error('Chain name must be a non-empty string'));
234
+ }
235
+
236
+ let res1 = Fula.leavePoolWithChain(poolID.toString(), chainName.trim())
237
+ .then((res) => {
238
+ try {
239
+ let jsonRes: BType.PoolLeaveResponse = JSON.parse(res);
240
+ return jsonRes;
241
+ } catch (e) {
242
+ try {
243
+ return JSON.parse(res);
244
+ } catch (e2) {
245
+ console.error('Error parsing res in leaving pool with chain:', e);
246
+ return res; // Return raw response if parsing fails
247
+ }
248
+ }
249
+ })
250
+ .catch((err) => {
251
+ console.error('Error leaving pool with chain:', err);
252
+ throw err; // Rethrow the error to maintain the rejection state
253
+ });
254
+ return res1;
255
+ };
256
+
257
+ export const cancelPoolJoin = (
258
+ poolID: number
259
+ ): Promise<BType.PoolCancelJoinResponse> => {
260
+ console.log('cancelPoolJoin in react-native started', poolID);
261
+ let res1 = Fula.cancelPoolJoin(poolID.toString())
262
+ .then((res) => {
263
+ try {
264
+ let jsonRes: BType.PoolCancelJoinResponse = JSON.parse(res);
265
+ return jsonRes;
266
+ } catch (e) {
267
+ try {
268
+ return JSON.parse(res);
269
+ } catch (e2) {
270
+ return res;
271
+ }
272
+ }
273
+ })
274
+ .catch((err) => {
275
+ return err;
276
+ });
277
+ return res1;
278
+ };
279
+ export const listPoolJoinRequests = (
280
+ poolID: string
281
+ ): Promise<BType.PoolRequestsResponse> => {
282
+ console.log('listPoolJoinRequests in react-native started', poolID);
283
+ let res1 = Fula.listPoolJoinRequests(poolID)
284
+ .then((res) => {
285
+ try {
286
+ let jsonRes: BType.PoolRequestsResponse = JSON.parse(res);
287
+ return jsonRes;
288
+ } catch (e) {
289
+ try {
290
+ return JSON.parse(res);
291
+ } catch (e2) {
292
+ return res;
293
+ }
294
+ }
295
+ })
296
+ .catch((err) => {
297
+ return err;
298
+ });
299
+ return res1;
300
+ };
301
+
302
+ /*
303
+ seed is used to authorize the request.
304
+ poolID is the ID of the pool in which the account is requesting to join.
305
+ account is the account that is requesting to join the pool.
306
+ accept is a boolean value that indicates whether to accept or reject the join request.
307
+ It returns a promise of BType.PoolVoteResponse which includes the account and poolID
308
+ */
309
+ export const votePoolJoinRequest = (
310
+ seed: string,
311
+ poolID: number,
312
+ account: string,
313
+ accept: boolean
314
+ ): Promise<BType.PoolVoteResponse> => {
315
+ console.log(
316
+ 'votePoolJoinRequest in react-native started',
317
+ seed,
318
+ poolID,
319
+ account,
320
+ accept
321
+ );
322
+ let res1 = Fula.votePoolJoinRequest(seed, poolID, account, accept)
323
+ .then((res) => {
324
+ try {
325
+ let jsonRes: BType.PoolVoteResponse = JSON.parse(res);
326
+ return jsonRes;
327
+ } catch (e) {
328
+ try {
329
+ return JSON.parse(res);
330
+ } catch (e2) {
331
+ return res;
332
+ }
333
+ }
334
+ })
335
+ .catch((err) => {
336
+ return err;
337
+ });
338
+ return res1;
339
+ };
340
+
341
+ /*
342
+ It takes four arguments:
343
+
344
+ seed is used to authorize the request.
345
+ poolID is the ID of the pool in which the replication request is made.
346
+ replicationFactor is the number of copies of the content to be stored.
347
+ cid is the content identifier of the content to be replicated.
348
+ It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
349
+ */
350
+ export const batchUploadManifest = (
351
+ api: ApiPromise | undefined, //this is just for compatibility with chainAPI inputs and is not used
352
+ seed: string, //this is just for compatibility with chainAPI inputs and is not used
353
+ cids_i: string[],
354
+ poolId_i: string | number,
355
+ replicationFactor_i: string | number
356
+ ): Promise<BType.ManifestBatchUploadResponse> => {
357
+ console.log(
358
+ 'newReplicationRequest in react-native started',
359
+ api,
360
+ seed,
361
+ poolId_i,
362
+ replicationFactor_i,
363
+ cids_i
364
+ );
365
+ if (typeof poolId_i === 'number') {
366
+ poolId_i = poolId_i.toString();
367
+ }
368
+ if (typeof replicationFactor_i === 'number') {
369
+ replicationFactor_i = replicationFactor_i.toString();
370
+ }
371
+ let res1 = Fula.batchUploadManifest(cids_i, poolId_i, replicationFactor_i)
372
+ .then((res) => {
373
+ try {
374
+ let jsonRes: BType.ManifestBatchUploadResponse = JSON.parse(res);
375
+ return jsonRes;
376
+ } catch (e) {
377
+ try {
378
+ return JSON.parse(res);
379
+ } catch (e2) {
380
+ return res;
381
+ }
382
+ }
383
+ })
384
+ .catch((err) => {
385
+ return err;
386
+ });
387
+ return res1;
388
+ };
389
+
390
+ export const replicateInPool = (
391
+ cids_i: string[],
392
+ account_i: string,
393
+ poolId_i: string | number
394
+ ): Promise<string[]> => {
395
+ console.log(
396
+ 'replicateInPool in react-native started',
397
+ poolId_i,
398
+ account_i,
399
+ cids_i
400
+ );
401
+ if (typeof poolId_i === 'number') {
402
+ poolId_i = poolId_i.toString();
403
+ }
404
+
405
+ let res1 = Fula.replicateInPool(cids_i, account_i, poolId_i)
406
+ .then((res) => {
407
+ try {
408
+ let jsonRes: string[] = JSON.parse(res);
409
+ return jsonRes;
410
+ } catch (e) {
411
+ try {
412
+ return JSON.parse(res);
413
+ } catch (e2) {
414
+ return res;
415
+ }
416
+ }
417
+ })
418
+ .catch((err) => {
419
+ return err;
420
+ });
421
+ return res1;
422
+ };
423
+
424
+ /*
425
+ It takes four arguments:
426
+
427
+ seed is used to authorize the request.
428
+ poolID is the ID of the pool in which the replication request is made.
429
+ uploader is the account of the user making the request
430
+ cid is the content identifier of the content to be stored.
431
+ It returns a promise of BType.ManifestUploadResponse which includes the uploader, storage, ManifestMetadata, and poolID
432
+ */
433
+ export const newStoreRequest = (
434
+ seed: string,
435
+ poolID: number,
436
+ uploader: string,
437
+ cid: string
438
+ ): Promise<BType.ManifestUploadResponse> => {
439
+ console.log(
440
+ 'newStoreRequest in react-native started',
441
+ seed,
442
+ poolID,
443
+ uploader,
444
+ cid
445
+ );
446
+ let res1 = Fula.newStoreRequest(seed, poolID, uploader, cid)
447
+ .then((res) => {
448
+ try {
449
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
450
+ return jsonRes;
451
+ } catch (e) {
452
+ try {
453
+ return JSON.parse(res);
454
+ } catch (e2) {
455
+ return res;
456
+ }
457
+ }
458
+ })
459
+ .catch((err) => {
460
+ return err;
461
+ });
462
+ return res1;
463
+ };
464
+
465
+ /*
466
+ It takes one argument:
467
+
468
+ poolID is the ID of the pool for which the replication requests are listed
469
+ It returns a promise of BType.ManifestUploadResponse[] which is an array of the replication requests, including the uploader, storage, ManifestMetadata, and poolID
470
+ */
471
+ export const listAvailableReplicationRequests = (
472
+ poolID: string
473
+ ): Promise<BType.ManifestUploadResponse[]> => {
474
+ console.log(
475
+ 'listAvailableReplicationRequests in react-native started',
476
+ poolID
477
+ );
478
+ let res1 = Fula.listAvailableReplicationRequests(poolID)
479
+ .then((res) => {
480
+ try {
481
+ let jsonRes: BType.ManifestUploadResponse[] = JSON.parse(res);
482
+ return jsonRes;
483
+ } catch (e) {
484
+ try {
485
+ return JSON.parse(res);
486
+ } catch (e2) {
487
+ return res;
488
+ }
489
+ }
490
+ })
491
+ .catch((err) => {
492
+ return err;
493
+ });
494
+ return res1;
495
+ };
496
+
497
+ /*
498
+ It takes three arguments:
499
+
500
+ seed is the seed of the account that is removing the replication request
501
+ poolID is the ID of the pool for which the replication request is being removed
502
+ cid is the content ID of the replication request being removed
503
+ It returns a promise of BType.ManifestUploadResponse which is the removed replication request, including the uploader, storage, ManifestMetadata, and poolID
504
+ */
505
+ export const removeReplicationRequest = (
506
+ seed: string,
507
+ poolID: number,
508
+ cid: string
509
+ ): Promise<BType.ManifestUploadResponse> => {
510
+ console.log(
511
+ 'removeReplicationRequest in react-native started',
512
+ seed,
513
+ poolID,
514
+ cid
515
+ );
516
+ let res1 = Fula.removeReplicationRequest(seed, poolID, cid)
517
+ .then((res) => {
518
+ try {
519
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
520
+ return jsonRes;
521
+ } catch (e) {
522
+ try {
523
+ return JSON.parse(res);
524
+ } catch (e2) {
525
+ return res;
526
+ }
527
+ }
528
+ })
529
+ .catch((err) => {
530
+ return err;
531
+ });
532
+ return res1;
533
+ };
534
+
535
+ /*
536
+ It takes four arguments:
537
+
538
+ seed is the seed of the account that is removing the storer
539
+ storer is the address of the storer that is being removed
540
+ poolID is the ID of the pool for which the storer is being removed
541
+ cid is the content ID of the replication request for which the storer is being removed
542
+ It returns a promise of BType.ManifestUploadResponse which is the replication request, including the uploader, storage, ManifestMetadata, and poolID after the storer has been removed.
543
+ */
544
+ export const removeStorer = (
545
+ seed: string,
546
+ storer: string,
547
+ poolID: number,
548
+ cid: string
549
+ ): Promise<BType.ManifestUploadResponse> => {
550
+ console.log(
551
+ 'removeStorer in react-native started',
552
+ seed,
553
+ storer,
554
+ poolID,
555
+ cid
556
+ );
557
+ let res1 = Fula.removeStorer(seed, storer, poolID, cid)
558
+ .then((res) => {
559
+ try {
560
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
561
+ return jsonRes;
562
+ } catch (e) {
563
+ try {
564
+ return JSON.parse(res);
565
+ } catch (e2) {
566
+ return res;
567
+ }
568
+ }
569
+ })
570
+ .catch((err) => {
571
+ return err;
572
+ });
573
+ return res1;
574
+ };
575
+
576
+ /*
577
+ It takes four arguments:
578
+
579
+ seed is the seed of the account that is removing the stored replication
580
+ uploader is the address of the uploader that is being removed
581
+ poolID is the ID of the pool for which the stored replication is being removed
582
+ cid is the content ID of the replication request for which the stored replication is being removed
583
+ It returns a promise of BType.ManifestUploadResponse which is the replication request, including the uploader, storage, ManifestMetadata, and poolID after the stored replication has been removed.
584
+ */
585
+ export const removeStoredReplication = (
586
+ seed: string,
587
+ uploader: string,
588
+ poolID: number,
589
+ cid: string
590
+ ): Promise<BType.ManifestUploadResponse> => {
591
+ console.log(
592
+ 'removeStoredReplication in react-native started',
593
+ seed,
594
+ uploader,
595
+ poolID,
596
+ cid
597
+ );
598
+ let res1 = Fula.removeStoredReplication(seed, uploader, poolID, cid)
599
+ .then((res) => {
600
+ try {
601
+ let jsonRes: BType.ManifestUploadResponse = JSON.parse(res);
602
+ return jsonRes;
603
+ } catch (e) {
604
+ try {
605
+ return JSON.parse(res);
606
+ } catch (e2) {
607
+ return res;
608
+ }
609
+ }
610
+ })
611
+ .catch((err) => {
612
+ return err;
613
+ });
614
+ return res1;
615
+ };
616
+
617
+ /*
618
+ bloxFreeSpace: This function takes no arguments and returns a promise of an object that contains the blox free space information.
619
+ */
620
+ export const bloxFreeSpace = (): Promise<BType.BloxFreeSpaceResponse> => {
621
+ console.log('bloxFreeSpace in react-native started');
622
+ let res1 = Fula.bloxFreeSpace()
623
+ .then((res) => {
624
+ try {
625
+ let jsonRes: BType.BloxFreeSpaceResponse = JSON.parse(res);
626
+ return jsonRes;
627
+ } catch (e) {
628
+ try {
629
+ return JSON.parse(res);
630
+ } catch (e2) {
631
+ return res;
632
+ }
633
+ }
634
+ })
635
+ .catch((err) => {
636
+ return err;
637
+ });
638
+ return res1;
639
+ };
640
+
641
+ export const getAccount = (): Promise<BType.GetAccountResponse> => {
642
+ console.log('getAccount in react-native started');
643
+ let res = Fula.getAccount()
644
+ .then((res1) => {
645
+ try {
646
+ let jsonRes: BType.GetAccountResponse = JSON.parse(res1);
647
+ return jsonRes;
648
+ } catch (e) {
649
+ try {
650
+ return JSON.parse(res1);
651
+ } catch (e1) {
652
+ console.error('Error parsing res in get account:', e1);
653
+ throw e1; // Rethrow the error to maintain the rejection state
654
+ }
655
+ }
656
+ })
657
+ .catch((err) => {
658
+ console.error('Error getting account:', err);
659
+ throw err; // Rethrow the error to maintain the rejection state
660
+ });
661
+ return res;
662
+ };
663
+
664
+ export const assetsBalance = (
665
+ account: string,
666
+ assetId: string,
667
+ classId: string
668
+ ): Promise<BType.AssetsBalanceResponse> => {
669
+ console.log('assetsBalance in react-native started');
670
+ let res = Fula.assetsBalance(account, assetId, classId)
671
+ .then((res1) => {
672
+ try {
673
+ let jsonRes: BType.AssetsBalanceResponse = JSON.parse(res1);
674
+ return jsonRes;
675
+ } catch (e) {
676
+ try {
677
+ return JSON.parse(res1);
678
+ } catch (e1) {
679
+ console.error('Error parsing res in get asset balance:', e1);
680
+ throw e1; // Rethrow the error to maintain the rejection state
681
+ }
682
+ }
683
+ })
684
+ .catch((err) => {
685
+ console.error('Error getting asset balance:', err);
686
+ throw err; // Rethrow the error to maintain the rejection state
687
+ });
688
+ return res;
689
+ };
690
+
691
+ export const transferToFula = (
692
+ amount: string,
693
+ wallet: string,
694
+ chain: string
695
+ ): Promise<BType.TransferToFulaResponse> => {
696
+ console.log('transferToFula in react-native started');
697
+ let res = Fula.transferToFula(amount, wallet, chain)
698
+ .then((res1) => {
699
+ try {
700
+ let jsonRes: BType.TransferToFulaResponse = JSON.parse(res1);
701
+ return jsonRes;
702
+ } catch (e) {
703
+ try {
704
+ return JSON.parse(res1);
705
+ } catch (e1) {
706
+ console.error('Error parsing res in transferToFula:', e1);
707
+ throw e1; // Rethrow the error to maintain the rejection state
708
+ }
709
+ }
710
+ })
711
+ .catch((err) => {
712
+ console.error('Error getting transferToFula:', err);
713
+ throw err; // Rethrow the error to maintain the rejection state
714
+ });
715
+ return res;
716
+ };