react-native-candle 0.1.19 → 0.1.20

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 (45) hide show
  1. package/ReactNativeCandle.podspec +1 -1
  2. package/ios/Sources/RNCandle.swift +143 -54
  3. package/lib/commonjs/index.js +63 -2
  4. package/lib/commonjs/index.js.map +1 -1
  5. package/lib/module/index.js +63 -2
  6. package/lib/module/index.js.map +1 -1
  7. package/lib/typescript/commonjs/src/index.d.ts +27 -8
  8. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  9. package/lib/typescript/commonjs/src/specs/RNCandle.nitro.d.ts +44 -1
  10. package/lib/typescript/commonjs/src/specs/RNCandle.nitro.d.ts.map +1 -1
  11. package/lib/typescript/module/src/index.d.ts +27 -8
  12. package/lib/typescript/module/src/index.d.ts.map +1 -1
  13. package/lib/typescript/module/src/specs/RNCandle.nitro.d.ts +44 -1
  14. package/lib/typescript/module/src/specs/RNCandle.nitro.d.ts.map +1 -1
  15. package/nitrogen/generated/ios/ReactNativeCandle-Swift-Cxx-Bridge.cpp +16 -8
  16. package/nitrogen/generated/ios/ReactNativeCandle-Swift-Cxx-Bridge.hpp +167 -43
  17. package/nitrogen/generated/ios/ReactNativeCandle-Swift-Cxx-Umbrella.hpp +27 -0
  18. package/nitrogen/generated/ios/c++/HybridRNCandleSpecSwift.hpp +53 -2
  19. package/nitrogen/generated/ios/swift/AssetAccountRef.swift +55 -0
  20. package/nitrogen/generated/ios/swift/FiatAssetRef.swift +75 -0
  21. package/nitrogen/generated/ios/swift/Func_void_AssetAccount.swift +44 -0
  22. package/nitrogen/generated/ios/swift/Func_void_LinkedAccount.swift +5 -5
  23. package/nitrogen/generated/ios/swift/HybridRNCandleSpec.swift +4 -1
  24. package/nitrogen/generated/ios/swift/HybridRNCandleSpec_cxx.swift +63 -3
  25. package/nitrogen/generated/ios/swift/LinkedAccountRef.swift +33 -0
  26. package/nitrogen/generated/ios/swift/MarketTradeAssetRef.swift +55 -0
  27. package/nitrogen/generated/ios/swift/NothingAssetRef.swift +33 -0
  28. package/nitrogen/generated/ios/swift/OtherAssetRef.swift +33 -0
  29. package/nitrogen/generated/ios/swift/TradeAssetRef.swift +176 -0
  30. package/nitrogen/generated/ios/swift/TradeRef.swift +44 -0
  31. package/nitrogen/generated/ios/swift/TransportAssetRef.swift +55 -0
  32. package/nitrogen/generated/shared/c++/AssetAccountRef.hpp +77 -0
  33. package/nitrogen/generated/shared/c++/FiatAssetRef.hpp +78 -0
  34. package/nitrogen/generated/shared/c++/HybridRNCandleSpec.cpp +3 -0
  35. package/nitrogen/generated/shared/c++/HybridRNCandleSpec.hpp +13 -1
  36. package/nitrogen/generated/shared/c++/LinkedAccountRef.hpp +69 -0
  37. package/nitrogen/generated/shared/c++/MarketTradeAssetRef.hpp +77 -0
  38. package/nitrogen/generated/shared/c++/NothingAssetRef.hpp +69 -0
  39. package/nitrogen/generated/shared/c++/OtherAssetRef.hpp +69 -0
  40. package/nitrogen/generated/shared/c++/TradeAssetRef.hpp +99 -0
  41. package/nitrogen/generated/shared/c++/TradeRef.hpp +74 -0
  42. package/nitrogen/generated/shared/c++/TransportAssetRef.hpp +77 -0
  43. package/package.json +1 -1
  44. package/src/index.ts +111 -13
  45. package/src/specs/RNCandle.nitro.ts +53 -1
@@ -0,0 +1,74 @@
1
+ ///
2
+ /// TradeRef.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+
21
+ // Forward declaration of `TradeAssetRef` to properly resolve imports.
22
+ namespace margelo::nitro::rncandle { struct TradeAssetRef; }
23
+
24
+ #include "TradeAssetRef.hpp"
25
+
26
+ namespace margelo::nitro::rncandle {
27
+
28
+ /**
29
+ * A struct which can be represented as a JavaScript object (TradeRef).
30
+ */
31
+ struct TradeRef {
32
+ public:
33
+ TradeAssetRef lost SWIFT_PRIVATE;
34
+ TradeAssetRef gained SWIFT_PRIVATE;
35
+
36
+ public:
37
+ TradeRef() = default;
38
+ explicit TradeRef(TradeAssetRef lost, TradeAssetRef gained): lost(lost), gained(gained) {}
39
+ };
40
+
41
+ } // namespace margelo::nitro::rncandle
42
+
43
+ namespace margelo::nitro {
44
+
45
+ using namespace margelo::nitro::rncandle;
46
+
47
+ // C++ TradeRef <> JS TradeRef (object)
48
+ template <>
49
+ struct JSIConverter<TradeRef> final {
50
+ static inline TradeRef fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
51
+ jsi::Object obj = arg.asObject(runtime);
52
+ return TradeRef(
53
+ JSIConverter<TradeAssetRef>::fromJSI(runtime, obj.getProperty(runtime, "lost")),
54
+ JSIConverter<TradeAssetRef>::fromJSI(runtime, obj.getProperty(runtime, "gained"))
55
+ );
56
+ }
57
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const TradeRef& arg) {
58
+ jsi::Object obj(runtime);
59
+ obj.setProperty(runtime, "lost", JSIConverter<TradeAssetRef>::toJSI(runtime, arg.lost));
60
+ obj.setProperty(runtime, "gained", JSIConverter<TradeAssetRef>::toJSI(runtime, arg.gained));
61
+ return obj;
62
+ }
63
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
64
+ if (!value.isObject()) {
65
+ return false;
66
+ }
67
+ jsi::Object obj = value.getObject(runtime);
68
+ if (!JSIConverter<TradeAssetRef>::canConvert(runtime, obj.getProperty(runtime, "lost"))) return false;
69
+ if (!JSIConverter<TradeAssetRef>::canConvert(runtime, obj.getProperty(runtime, "gained"))) return false;
70
+ return true;
71
+ }
72
+ };
73
+
74
+ } // namespace margelo::nitro
@@ -0,0 +1,77 @@
1
+ ///
2
+ /// TransportAssetRef.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+
21
+
22
+
23
+ #include <string>
24
+
25
+ namespace margelo::nitro::rncandle {
26
+
27
+ /**
28
+ * A struct which can be represented as a JavaScript object (TransportAssetRef).
29
+ */
30
+ struct TransportAssetRef {
31
+ public:
32
+ std::string assetKind SWIFT_PRIVATE;
33
+ std::string serviceTradeID SWIFT_PRIVATE;
34
+ std::string linkedAccountID SWIFT_PRIVATE;
35
+
36
+ public:
37
+ TransportAssetRef() = default;
38
+ explicit TransportAssetRef(std::string assetKind, std::string serviceTradeID, std::string linkedAccountID): assetKind(assetKind), serviceTradeID(serviceTradeID), linkedAccountID(linkedAccountID) {}
39
+ };
40
+
41
+ } // namespace margelo::nitro::rncandle
42
+
43
+ namespace margelo::nitro {
44
+
45
+ using namespace margelo::nitro::rncandle;
46
+
47
+ // C++ TransportAssetRef <> JS TransportAssetRef (object)
48
+ template <>
49
+ struct JSIConverter<TransportAssetRef> final {
50
+ static inline TransportAssetRef fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
51
+ jsi::Object obj = arg.asObject(runtime);
52
+ return TransportAssetRef(
53
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "assetKind")),
54
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "serviceTradeID")),
55
+ JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "linkedAccountID"))
56
+ );
57
+ }
58
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const TransportAssetRef& arg) {
59
+ jsi::Object obj(runtime);
60
+ obj.setProperty(runtime, "assetKind", JSIConverter<std::string>::toJSI(runtime, arg.assetKind));
61
+ obj.setProperty(runtime, "serviceTradeID", JSIConverter<std::string>::toJSI(runtime, arg.serviceTradeID));
62
+ obj.setProperty(runtime, "linkedAccountID", JSIConverter<std::string>::toJSI(runtime, arg.linkedAccountID));
63
+ return obj;
64
+ }
65
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
66
+ if (!value.isObject()) {
67
+ return false;
68
+ }
69
+ jsi::Object obj = value.getObject(runtime);
70
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "assetKind"))) return false;
71
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "serviceTradeID"))) return false;
72
+ if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "linkedAccountID"))) return false;
73
+ return true;
74
+ }
75
+ };
76
+
77
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-candle",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "Candle SDK for React Native",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { NitroModules } from "react-native-nitro-modules";
2
2
  import type {
3
3
  AppUser,
4
- AssetAccount as NitroAssetAccount,
4
+ AssetAccount as InternalAssetAccount,
5
5
  AssetAccountQuery,
6
6
  FiatAsset,
7
7
  FiatAssetQuoteRequest,
@@ -17,7 +17,7 @@ import type {
17
17
  Service,
18
18
  TradeAsset as InternalTradeAsset,
19
19
  TradeAssetQuoteRequest,
20
- TradeQuery,
20
+ TradeQuery as InternalTradeQuery,
21
21
  TransportAsset,
22
22
  TransportAssetQuoteRequest,
23
23
  LegalAccountKind,
@@ -30,6 +30,14 @@ import type {
30
30
  Counterparty as InternalCounterparty,
31
31
  ActiveLinkedAccountDetails,
32
32
  ExecuteTradeRequest,
33
+ AssetAccountRef,
34
+ LinkedAccountRef,
35
+ NothingAssetRef,
36
+ TransportAssetRef,
37
+ OtherAssetRef,
38
+ FiatAssetRef,
39
+ MarketTradeAssetRef,
40
+ TradeAssetRef as InternalTradeAssetRef,
33
41
  } from "./specs/RNCandle.nitro";
34
42
 
35
43
  export class CandleClient {
@@ -106,8 +114,12 @@ export class CandleClient {
106
114
  });
107
115
  }
108
116
 
109
- public async unlinkAccount(linkedAccountID: string): Promise<void> {
110
- await this.candle.unlinkAccount(linkedAccountID);
117
+ public async getLinkedAccount(ref: LinkedAccountRef): Promise<LinkedAccount> {
118
+ return this.candle.getLinkedAccount(ref);
119
+ }
120
+
121
+ public async unlinkAccount(path: LinkedAccountRef): Promise<void> {
122
+ await this.candle.unlinkAccount(path);
111
123
  }
112
124
 
113
125
  public async deleteUser(): Promise<void> {
@@ -143,13 +155,12 @@ export class CandleClient {
143
155
  return accounts.map((account) => this.convertToAssetAccount(account));
144
156
  }
145
157
 
146
- public async getTrades(
147
- query: {
148
- gainedAssetKind?: TradeQueryAssetKind;
149
- lostAssetKind?: TradeQueryAssetKind;
150
- counterpartyKind?: "merchant" | "user" | "service";
151
- } & TradeQuery = {}
152
- ): Promise<Trade[]> {
158
+ public async getAssetAccount(ref: AssetAccountRef): Promise<AssetAccount> {
159
+ const account = await this.candle.getAssetAccount(ref);
160
+ return this.convertToAssetAccount(account);
161
+ }
162
+
163
+ public async getTrades(query: TradeQuery = {}): Promise<Trade[]> {
153
164
  const trades = await this.candle.getTrades(query);
154
165
  return trades.map(({ dateTime, counterparty, gained, lost, state }) => ({
155
166
  dateTime,
@@ -160,6 +171,23 @@ export class CandleClient {
160
171
  }));
161
172
  }
162
173
 
174
+ public async getTrade(input: {
175
+ lost: TradeAssetRef;
176
+ gained: TradeAssetRef;
177
+ }): Promise<Trade> {
178
+ const trade = await this.candle.getTrade({
179
+ lost: this.convertTradeAssetRef(input.lost),
180
+ gained: this.convertTradeAssetRef(input.gained),
181
+ });
182
+ return {
183
+ dateTime: trade.dateTime,
184
+ state: trade.state,
185
+ counterparty: this.convertToCounterparty(trade.counterparty),
186
+ lost: this.convertTradeAsset(trade.lost),
187
+ gained: this.convertTradeAsset(trade.gained),
188
+ };
189
+ }
190
+
163
191
  public async getTradeQuotes(request: {
164
192
  linkedAccountIDs?: string;
165
193
  gained:
@@ -206,6 +234,50 @@ export class CandleClient {
206
234
  });
207
235
  }
208
236
 
237
+ private convertTradeAssetRef(
238
+ tradeAssetRef: TradeAssetRef
239
+ ): InternalTradeAssetRef {
240
+ switch (tradeAssetRef.assetKind) {
241
+ case "fiat":
242
+ return {
243
+ fiatAssetRef: {
244
+ assetKind: "fiat",
245
+ linkedAccountID: tradeAssetRef.linkedAccountID,
246
+ serviceTradeID: tradeAssetRef.serviceTradeID,
247
+ },
248
+ };
249
+ case "stock":
250
+ case "crypto":
251
+ return {
252
+ marketTradeAssetRef: {
253
+ assetKind: tradeAssetRef.assetKind,
254
+ linkedAccountID: tradeAssetRef.linkedAccountID,
255
+ serviceTradeID: tradeAssetRef.serviceTradeID,
256
+ },
257
+ };
258
+ case "transport":
259
+ return {
260
+ transportAssetRef: {
261
+ assetKind: "transport",
262
+ linkedAccountID: tradeAssetRef.linkedAccountID,
263
+ serviceTradeID: tradeAssetRef.serviceTradeID,
264
+ },
265
+ };
266
+ case "other":
267
+ return {
268
+ otherAssetRef: {
269
+ assetKind: "other",
270
+ },
271
+ };
272
+ case "nothing":
273
+ return {
274
+ nothingAssetRef: {
275
+ assetKind: "nothing",
276
+ },
277
+ };
278
+ }
279
+ }
280
+
209
281
  private convertTradeAsset(tradeAsset: InternalTradeAsset): TradeAsset {
210
282
  if (tradeAsset.fiatAsset !== undefined) {
211
283
  return {
@@ -254,7 +326,7 @@ export class CandleClient {
254
326
  }
255
327
  }
256
328
 
257
- private convertToAssetAccount(account: NitroAssetAccount): AssetAccount {
329
+ private convertToAssetAccount(account: InternalAssetAccount): AssetAccount {
258
330
  const { legalAccountKind, nickname } = account;
259
331
  const { fiatAccountDetails, marketAccountDetails } = account.details;
260
332
 
@@ -302,6 +374,12 @@ type Counterparty =
302
374
  kind: "service";
303
375
  } & ServiceCounterparty);
304
376
 
377
+ type TradeQuery = {
378
+ gainedAssetKind?: TradeQueryAssetKind;
379
+ lostAssetKind?: TradeQueryAssetKind;
380
+ counterpartyKind?: "merchant" | "user" | "service";
381
+ } & InternalTradeQuery;
382
+
305
383
  type TradeQueryAssetKind =
306
384
  | "fiat"
307
385
  | "stock"
@@ -340,4 +418,24 @@ type Trade = {
340
418
  gained: TradeAsset;
341
419
  };
342
420
 
343
- export type { LinkedAccount, AppUser, Service, TradeState, TradeAsset, Trade };
421
+ type TradeAssetRef =
422
+ | ({ assetKind: "transport" } & TransportAssetRef)
423
+ | ({ assetKind: "nothing" } & NothingAssetRef)
424
+ | ({ assetKind: "other" } & OtherAssetRef)
425
+ | ({ assetKind: "fiat" } & FiatAssetRef)
426
+ | ({ assetKind: "stock" | "crypto" } & MarketTradeAssetRef);
427
+
428
+ export type {
429
+ LinkedAccountRef,
430
+ AssetAccountRef,
431
+ TradeAssetRef,
432
+ LinkedAccount,
433
+ AppUser,
434
+ Service,
435
+ TradeState,
436
+ TradeAsset,
437
+ Trade,
438
+ TradeQuery,
439
+ Counterparty,
440
+ AssetAccount,
441
+ };
@@ -344,6 +344,55 @@ export type ToolCall = {
344
344
  arguments: string;
345
345
  };
346
346
 
347
+ export type LinkedAccountRef = {
348
+ linkedAccountID: string;
349
+ };
350
+
351
+ export type AssetAccountRef = {
352
+ linkedAccountID: string;
353
+ assetKind: string; // "fiat" | "stock" | "crypto"
354
+ serviceAccountID: string;
355
+ };
356
+
357
+ export type FiatAssetRef = {
358
+ assetKind: string; // fiat
359
+ serviceTradeID?: string;
360
+ linkedAccountID: string;
361
+ };
362
+
363
+ export type MarketTradeAssetRef = {
364
+ assetKind: string; // "stock" | "crypto"
365
+ serviceTradeID: string;
366
+ linkedAccountID: string;
367
+ };
368
+
369
+ export type TransportAssetRef = {
370
+ assetKind: string; // "transport"
371
+ serviceTradeID: string;
372
+ linkedAccountID: string;
373
+ };
374
+
375
+ export type OtherAssetRef = {
376
+ assetKind: string; // "other"
377
+ };
378
+
379
+ export type NothingAssetRef = {
380
+ assetKind: string; // "nothing"
381
+ };
382
+
383
+ export type TradeAssetRef = {
384
+ fiatAssetRef?: FiatAssetRef;
385
+ marketTradeAssetRef?: MarketTradeAssetRef;
386
+ transportAssetRef?: TransportAssetRef;
387
+ otherAssetRef?: OtherAssetRef;
388
+ nothingAssetRef?: NothingAssetRef;
389
+ };
390
+
391
+ export type TradeRef = {
392
+ lost: TradeAssetRef;
393
+ gained: TradeAssetRef;
394
+ };
395
+
347
396
  export interface RNCandle extends HybridObject<{ ios: "swift" }> {
348
397
  candleLinkSheet(
349
398
  isPresented: boolean,
@@ -357,9 +406,12 @@ export interface RNCandle extends HybridObject<{ ios: "swift" }> {
357
406
  ): void;
358
407
  initialize(appUser: AppUser): void;
359
408
  getLinkedAccounts(): Promise<LinkedAccount[]>;
360
- unlinkAccount(linkedAccountID: string): Promise<void>;
409
+ getLinkedAccount(ref: LinkedAccountRef): Promise<LinkedAccount>;
410
+ unlinkAccount(ref: LinkedAccountRef): Promise<void>;
361
411
  getAssetAccounts(query: AssetAccountQuery): Promise<AssetAccount[]>;
412
+ getAssetAccount(ref: AssetAccountRef): Promise<AssetAccount>;
362
413
  getTrades(query: TradeQuery): Promise<Trade[]>;
414
+ getTrade(ref: TradeRef): Promise<Trade>;
363
415
  getTradeQuotes(request: TradeQuoteRequest): Promise<TradeQuote[]>;
364
416
  executeTrade(request: ExecuteTradeRequest): Promise<Trade>;
365
417
  deleteUser(): Promise<void>;