react-native-candle 0.1.42 → 0.1.44
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/ReactNativeCandle.podspec +1 -1
- package/ios/Sources/CandleActionViewModel.swift +4 -7
- package/ios/Sources/CandleLinkSheetWrapperView.swift +40 -59
- package/ios/Sources/CandleLinkViewModel.swift +21 -31
- package/ios/Sources/CandleTradeExecutionSheetWrapper.swift +14 -23
- package/ios/Sources/HostingViewController.swift +26 -26
- package/ios/Sources/RNCandle.swift +159 -1307
- package/ios/Sources/Types.swift +847 -0
- package/ios/Sources/UIApplication++.swift +5 -9
- package/lib/commonjs/context.js +17 -0
- package/lib/commonjs/context.js.map +1 -0
- package/lib/commonjs/index.js +17 -407
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/provider.js +117 -0
- package/lib/commonjs/provider.js.map +1 -0
- package/lib/commonjs/types.js +271 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/context.js +12 -0
- package/lib/module/context.js.map +1 -0
- package/lib/module/index.js +2 -408
- package/lib/module/index.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/module/provider.js +111 -0
- package/lib/module/provider.js.map +1 -0
- package/lib/module/types.js +256 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/commonjs/src/context.d.ts +47 -0
- package/lib/typescript/commonjs/src/context.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +4 -166
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/provider.d.ts +8 -0
- package/lib/typescript/commonjs/src/provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/RNCandle.nitro.d.ts +22 -24
- package/lib/typescript/commonjs/src/specs/RNCandle.nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types.d.ts +125 -0
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
- package/lib/typescript/module/src/context.d.ts +47 -0
- package/lib/typescript/module/src/context.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +4 -166
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/provider.d.ts +8 -0
- package/lib/typescript/module/src/provider.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/RNCandle.nitro.d.ts +22 -24
- package/lib/typescript/module/src/specs/RNCandle.nitro.d.ts.map +1 -1
- package/lib/typescript/module/src/types.d.ts +125 -0
- package/lib/typescript/module/src/types.d.ts.map +1 -0
- package/nitrogen/generated/.gitattributes +1 -1
- package/nitrogen/generated/ios/ReactNativeCandle-Swift-Cxx-Bridge.cpp +15 -31
- package/nitrogen/generated/ios/ReactNativeCandle-Swift-Cxx-Bridge.hpp +379 -242
- package/nitrogen/generated/ios/ReactNativeCandle-Swift-Cxx-Umbrella.hpp +23 -22
- package/nitrogen/generated/ios/ReactNativeCandleAutolinking.mm +1 -1
- package/nitrogen/generated/ios/ReactNativeCandleAutolinking.swift +2 -4
- package/nitrogen/generated/ios/c++/HybridRNCandleSpecSwift.hpp +36 -42
- package/nitrogen/generated/ios/swift/ActiveLinkedAccountDetails.swift +6 -3
- package/nitrogen/generated/ios/swift/AssetAccount.swift +6 -3
- package/nitrogen/generated/ios/swift/AssetAccountKind.swift +4 -4
- package/nitrogen/generated/ios/swift/AssetAccountRef.swift +5 -5
- package/nitrogen/generated/ios/swift/{AssetAccountQuery.swift → AssetAccountsQuery.swift} +7 -6
- package/nitrogen/generated/ios/swift/Counterparty.swift +8 -3
- package/nitrogen/generated/ios/swift/CounterpartyKind.swift +42 -0
- package/nitrogen/generated/ios/swift/FiatAccount.swift +4 -2
- package/nitrogen/generated/ios/swift/FiatAsset.swift +2 -1
- package/nitrogen/generated/ios/swift/FiatAssetQuoteRequest.swift +4 -2
- package/nitrogen/generated/ios/swift/FiatAssetRef.swift +2 -1
- package/nitrogen/generated/ios/swift/Func_void_LinkedAccount.swift +5 -5
- package/nitrogen/generated/ios/swift/HybridRNCandleSpec.swift +7 -7
- package/nitrogen/generated/ios/swift/HybridRNCandleSpec_cxx.swift +40 -65
- package/nitrogen/generated/ios/swift/LinkedAccountDetails.swift +15 -3
- package/nitrogen/generated/ios/swift/{StatePayload.swift → LinkedAccountState.swift} +6 -6
- package/nitrogen/generated/ios/swift/LinkedAccountStatusRef.swift +4 -3
- package/nitrogen/generated/ios/swift/MarketAccount.swift +5 -5
- package/nitrogen/generated/ios/swift/MarketAssetKind.swift +38 -0
- package/nitrogen/generated/ios/swift/MarketAssetQuoteRequest.swift +11 -8
- package/nitrogen/generated/ios/swift/MarketTradeAsset.swift +7 -7
- package/nitrogen/generated/ios/swift/MarketTradeAssetRef.swift +5 -5
- package/nitrogen/generated/ios/swift/MerchantCounterparty.swift +2 -1
- package/nitrogen/generated/ios/swift/TradeAsset.swift +10 -5
- package/nitrogen/generated/ios/swift/TradeAssetKind.swift +54 -0
- package/nitrogen/generated/ios/swift/TradeAssetQuoteRequest.swift +15 -4
- package/nitrogen/generated/ios/swift/TradeAssetRef.swift +11 -5
- package/nitrogen/generated/ios/swift/TradeExecutionResult.swift +4 -2
- package/nitrogen/generated/ios/swift/{TradeQuoteRequest.swift → TradeQuotesRequest.swift} +7 -6
- package/nitrogen/generated/ios/swift/{TradeQuery.swift → TradesQuery.swift} +29 -45
- package/nitrogen/generated/ios/swift/TransportAssetQuoteRequest.swift +12 -6
- package/nitrogen/generated/shared/c++/ACHAccountKind.hpp +7 -9
- package/nitrogen/generated/shared/c++/ACHDetails.hpp +7 -9
- package/nitrogen/generated/shared/c++/ActiveLinkedAccountDetails.hpp +4 -6
- package/nitrogen/generated/shared/c++/Address.hpp +4 -6
- package/nitrogen/generated/shared/c++/AssetAccount.hpp +14 -16
- package/nitrogen/generated/shared/c++/AssetAccountKind.hpp +15 -17
- package/nitrogen/generated/shared/c++/AssetAccountRef.hpp +12 -12
- package/nitrogen/generated/shared/c++/{AssetAccountQuery.hpp → AssetAccountsQuery.hpp} +14 -16
- package/nitrogen/generated/shared/c++/AssetAccountsResponse.hpp +11 -13
- package/nitrogen/generated/shared/c++/Coordinates.hpp +4 -6
- package/nitrogen/generated/shared/c++/Counterparty.hpp +14 -16
- package/nitrogen/generated/shared/c++/CounterpartyKind.hpp +80 -0
- package/nitrogen/generated/shared/c++/FiatAccount.hpp +16 -18
- package/nitrogen/generated/shared/c++/FiatAsset.hpp +7 -9
- package/nitrogen/generated/shared/c++/FiatAssetQuoteRequest.hpp +4 -6
- package/nitrogen/generated/shared/c++/FiatAssetRef.hpp +4 -6
- package/nitrogen/generated/shared/c++/FiatMarketAccountKind.hpp +13 -15
- package/nitrogen/generated/shared/c++/HybridRNCandleSpec.cpp +1 -2
- package/nitrogen/generated/shared/c++/HybridRNCandleSpec.hpp +17 -27
- package/nitrogen/generated/shared/c++/InactiveLinkedAccountDetails.hpp +4 -6
- package/nitrogen/generated/shared/c++/LinkedAccount.hpp +10 -12
- package/nitrogen/generated/shared/c++/LinkedAccountDetails.hpp +14 -16
- package/nitrogen/generated/shared/c++/LinkedAccountRef.hpp +4 -6
- package/nitrogen/generated/shared/c++/{StatePayload.hpp → LinkedAccountState.hpp} +15 -17
- package/nitrogen/generated/shared/c++/LinkedAccountStatusRef.hpp +15 -17
- package/nitrogen/generated/shared/c++/MarketAccount.hpp +18 -17
- package/nitrogen/generated/shared/c++/MarketAssetKind.hpp +76 -0
- package/nitrogen/generated/shared/c++/MarketAssetQuoteRequest.hpp +12 -12
- package/nitrogen/generated/shared/c++/MarketTradeAsset.hpp +15 -14
- package/nitrogen/generated/shared/c++/MarketTradeAssetRef.hpp +12 -12
- package/nitrogen/generated/shared/c++/MerchantCounterparty.hpp +8 -10
- package/nitrogen/generated/shared/c++/MerchantLocation.hpp +4 -6
- package/nitrogen/generated/shared/c++/NothingAsset.hpp +4 -6
- package/nitrogen/generated/shared/c++/NothingAssetQuoteRequest.hpp +4 -6
- package/nitrogen/generated/shared/c++/NothingAssetRef.hpp +4 -6
- package/nitrogen/generated/shared/c++/OtherAsset.hpp +4 -6
- package/nitrogen/generated/shared/c++/OtherAssetRef.hpp +4 -6
- package/nitrogen/generated/shared/c++/PresentationBackground.hpp +7 -9
- package/nitrogen/generated/shared/c++/PresentationStyle.hpp +7 -9
- package/nitrogen/generated/shared/c++/Service.hpp +163 -165
- package/nitrogen/generated/shared/c++/ServiceCounterparty.hpp +7 -9
- package/nitrogen/generated/shared/c++/Trade.hpp +16 -18
- package/nitrogen/generated/shared/c++/TradeAsset.hpp +20 -22
- package/nitrogen/generated/shared/c++/TradeAssetKind.hpp +92 -0
- package/nitrogen/generated/shared/c++/TradeAssetQuoteRequest.hpp +17 -19
- package/nitrogen/generated/shared/c++/TradeAssetRef.hpp +20 -22
- package/nitrogen/generated/shared/c++/TradeExecutionResult.hpp +8 -10
- package/nitrogen/generated/shared/c++/TradeQuote.hpp +10 -12
- package/nitrogen/generated/shared/c++/{TradeQuoteRequest.hpp → TradeQuotesRequest.hpp} +17 -19
- package/nitrogen/generated/shared/c++/TradeQuotesResponse.hpp +11 -13
- package/nitrogen/generated/shared/c++/TradeRef.hpp +10 -12
- package/nitrogen/generated/shared/c++/TradeState.hpp +9 -11
- package/nitrogen/generated/shared/c++/TradesQuery.hpp +89 -0
- package/nitrogen/generated/shared/c++/TradesResponse.hpp +11 -13
- package/nitrogen/generated/shared/c++/TransportAccount.hpp +10 -12
- package/nitrogen/generated/shared/c++/TransportAccountKind.hpp +9 -11
- package/nitrogen/generated/shared/c++/TransportAsset.hpp +19 -21
- package/nitrogen/generated/shared/c++/TransportAssetQuoteRequest.hpp +16 -18
- package/nitrogen/generated/shared/c++/TransportAssetRef.hpp +4 -6
- package/nitrogen/generated/shared/c++/UnavailableLinkedAccountDetails.hpp +4 -6
- package/nitrogen/generated/shared/c++/UserCounterparty.hpp +4 -6
- package/nitrogen/generated/shared/c++/WireDetails.hpp +4 -6
- package/package.json +9 -11
- package/src/context.ts +86 -0
- package/src/index.ts +4 -634
- package/src/provider.tsx +152 -0
- package/src/specs/RNCandle.nitro.ts +38 -29
- package/src/types.ts +462 -0
- package/nitrogen/generated/ios/swift/AppUser.swift +0 -75
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +0 -44
- package/nitrogen/generated/ios/swift/Func_void_std__vector_std__shared_ptr_AnyMap__.swift +0 -47
- package/nitrogen/generated/ios/swift/ToolCall.swift +0 -44
- package/nitrogen/generated/shared/c++/AppUser.hpp +0 -78
- package/nitrogen/generated/shared/c++/ToolCall.hpp +0 -73
- package/nitrogen/generated/shared/c++/TradeQuery.hpp +0 -86
package/src/index.ts
CHANGED
|
@@ -1,634 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Address,
|
|
6
|
-
AppUser,
|
|
7
|
-
AssetAccountQuery,
|
|
8
|
-
AssetAccountRef,
|
|
9
|
-
Coordinates,
|
|
10
|
-
FiatAsset,
|
|
11
|
-
FiatAssetQuoteRequest,
|
|
12
|
-
FiatAssetRef,
|
|
13
|
-
FiatMarketAccountKind,
|
|
14
|
-
AssetAccount as InternalAssetAccount,
|
|
15
|
-
Counterparty as InternalCounterparty,
|
|
16
|
-
TradeAsset as InternalTradeAsset,
|
|
17
|
-
TradeAssetRef as InternalTradeAssetRef,
|
|
18
|
-
TradeQuery as InternalTradeQuery,
|
|
19
|
-
TradeQuote as InternalTradeQuote,
|
|
20
|
-
LinkedAccount,
|
|
21
|
-
LinkedAccountRef,
|
|
22
|
-
LinkedAccountStatusRef,
|
|
23
|
-
MarketAssetQuoteRequest,
|
|
24
|
-
MarketTradeAsset,
|
|
25
|
-
MarketTradeAssetRef,
|
|
26
|
-
MerchantCounterparty,
|
|
27
|
-
NothingAsset,
|
|
28
|
-
NothingAssetQuoteRequest,
|
|
29
|
-
NothingAssetRef,
|
|
30
|
-
OtherAsset,
|
|
31
|
-
OtherAssetRef,
|
|
32
|
-
PresentationBackground,
|
|
33
|
-
PresentationStyle,
|
|
34
|
-
RNCandle,
|
|
35
|
-
Service,
|
|
36
|
-
ServiceCounterparty,
|
|
37
|
-
TradeAssetQuoteRequest,
|
|
38
|
-
TradeState,
|
|
39
|
-
TransportAccountKind,
|
|
40
|
-
TransportAsset,
|
|
41
|
-
TransportAssetQuoteRequest,
|
|
42
|
-
TransportAssetRef,
|
|
43
|
-
UserCounterparty,
|
|
44
|
-
WireDetails,
|
|
45
|
-
} from "./specs/RNCandle.nitro";
|
|
46
|
-
|
|
47
|
-
export class CandleClient {
|
|
48
|
-
private candle: RNCandle;
|
|
49
|
-
|
|
50
|
-
constructor(appUser: AppUser, accessGroup?: string) {
|
|
51
|
-
const CandleHybridObject =
|
|
52
|
-
NitroModules.createHybridObject<RNCandle>("RNCandle");
|
|
53
|
-
this.candle = CandleHybridObject;
|
|
54
|
-
this.candle.initialize(appUser, accessGroup);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public presentCandleTradeExecutionSheet<
|
|
58
|
-
GainedAssetKind extends AssetKind,
|
|
59
|
-
LostAssetKind extends AssetKind
|
|
60
|
-
>(input: {
|
|
61
|
-
tradeQuote: TradeQuote<GainedAssetKind, LostAssetKind>;
|
|
62
|
-
presentationBackground?: PresentationBackground;
|
|
63
|
-
completion?: (
|
|
64
|
-
result:
|
|
65
|
-
| (Trade & {
|
|
66
|
-
kind: "success";
|
|
67
|
-
gained: { assetKind: GainedAssetKind };
|
|
68
|
-
lost: { assetKind: LostAssetKind };
|
|
69
|
-
})
|
|
70
|
-
| { kind: "failure"; error: Error }
|
|
71
|
-
) => void;
|
|
72
|
-
}): void {
|
|
73
|
-
const quote = this.convertTradeQuote(input.tradeQuote);
|
|
74
|
-
this.candle.candleTradeExecutionSheet(
|
|
75
|
-
quote,
|
|
76
|
-
input.presentationBackground ?? "default",
|
|
77
|
-
(result) => {
|
|
78
|
-
if (input.completion === undefined) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (result.trade !== undefined) {
|
|
82
|
-
input.completion({
|
|
83
|
-
kind: "success",
|
|
84
|
-
...result.trade,
|
|
85
|
-
counterparty: this.convertToCounterparty(result.trade.counterparty),
|
|
86
|
-
lost: this.assertTradeAsset({
|
|
87
|
-
tradeAsset: this.convertTradeAsset(result.trade.lost),
|
|
88
|
-
expectedAssetKind: input.tradeQuote.lost.assetKind,
|
|
89
|
-
}),
|
|
90
|
-
gained: this.assertTradeAsset({
|
|
91
|
-
tradeAsset: this.convertTradeAsset(result.trade.gained),
|
|
92
|
-
expectedAssetKind: input.tradeQuote.gained.assetKind,
|
|
93
|
-
}),
|
|
94
|
-
});
|
|
95
|
-
} else {
|
|
96
|
-
if (result.error === undefined) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
"Internal Candle Error: corrupted trade execution result."
|
|
99
|
-
);
|
|
100
|
-
} else {
|
|
101
|
-
const error = new Error(result.error);
|
|
102
|
-
input.completion({ kind: "failure", error });
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public presentCandleLinkSheet({
|
|
110
|
-
services = undefined,
|
|
111
|
-
cornerRadius = 24,
|
|
112
|
-
customerName,
|
|
113
|
-
showDynamicLoading = true,
|
|
114
|
-
presentationBackground = "default",
|
|
115
|
-
presentationStyle = "fullScreen",
|
|
116
|
-
onSuccess,
|
|
117
|
-
}: {
|
|
118
|
-
services?: Service[];
|
|
119
|
-
cornerRadius?: number;
|
|
120
|
-
customerName?: string;
|
|
121
|
-
showSandbox?: boolean;
|
|
122
|
-
showDynamicLoading?: boolean;
|
|
123
|
-
presentationBackground?: PresentationBackground;
|
|
124
|
-
presentationStyle?: PresentationStyle;
|
|
125
|
-
onSuccess: (account: LinkedAccount) => void;
|
|
126
|
-
}): void {
|
|
127
|
-
this.candle.candleLinkSheet(
|
|
128
|
-
true,
|
|
129
|
-
services,
|
|
130
|
-
cornerRadius,
|
|
131
|
-
customerName,
|
|
132
|
-
showDynamicLoading,
|
|
133
|
-
presentationBackground,
|
|
134
|
-
presentationStyle,
|
|
135
|
-
onSuccess
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
public async getLinkedAccounts(): Promise<LinkedAccountDetail[]> {
|
|
140
|
-
const accounts = await this.candle.getLinkedAccounts();
|
|
141
|
-
return accounts.map((account) => {
|
|
142
|
-
if (account.details.activeLinkedAccountDetails !== undefined) {
|
|
143
|
-
return {
|
|
144
|
-
...account,
|
|
145
|
-
details: {
|
|
146
|
-
...account.details.activeLinkedAccountDetails,
|
|
147
|
-
state: "active",
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
} else if (account.details.inactiveLinkedAccountDetails !== undefined) {
|
|
151
|
-
return {
|
|
152
|
-
...account,
|
|
153
|
-
details: {
|
|
154
|
-
...account.details.inactiveLinkedAccountDetails,
|
|
155
|
-
state: "inactive",
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
} else if (
|
|
159
|
-
account.details.unavailableLinkedAccountDetails !== undefined
|
|
160
|
-
) {
|
|
161
|
-
return {
|
|
162
|
-
...account,
|
|
163
|
-
details: {
|
|
164
|
-
...account.details.unavailableLinkedAccountDetails,
|
|
165
|
-
state: "unavailable",
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
} else {
|
|
169
|
-
throw new Error("Internal Candle Error: corrupted linked account.");
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
public async getLinkedAccount(ref: LinkedAccountRef): Promise<LinkedAccount> {
|
|
175
|
-
return this.candle.getLinkedAccount(ref);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
public async unlinkAccount(path: LinkedAccountRef): Promise<void> {
|
|
179
|
-
await this.candle.unlinkAccount(path);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
public async deleteUser(): Promise<void> {
|
|
183
|
-
await this.candle.deleteUser();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
public async getAvailableTools(): Promise<Array<Record<string, any>>> {
|
|
187
|
-
return this.candle.getAvailableTools();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
public async executeTool(tool: {
|
|
191
|
-
name: string;
|
|
192
|
-
arguments: string;
|
|
193
|
-
}): Promise<string> {
|
|
194
|
-
return this.candle.executeTool(tool);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
public async getAssetAccounts(query: AssetAccountQuery = {}): Promise<{
|
|
198
|
-
assetAccounts: AssetAccount[];
|
|
199
|
-
linkedAccounts: LinkedAccountStatusRef[];
|
|
200
|
-
}> {
|
|
201
|
-
const { assetAccounts, linkedAccounts } =
|
|
202
|
-
await this.candle.getAssetAccounts(query);
|
|
203
|
-
return {
|
|
204
|
-
assetAccounts: assetAccounts.map((account) =>
|
|
205
|
-
this.convertToAssetAccount(account)
|
|
206
|
-
),
|
|
207
|
-
linkedAccounts,
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
public async getAssetAccount(ref: AssetAccountRef): Promise<AssetAccount> {
|
|
212
|
-
const account = await this.candle.getAssetAccount(ref);
|
|
213
|
-
return this.convertToAssetAccount(account);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
public async getTrades(query: TradeQuery = {}): Promise<{
|
|
217
|
-
trades: Trade[];
|
|
218
|
-
linkedAccounts: LinkedAccountStatusRef[];
|
|
219
|
-
}> {
|
|
220
|
-
const { trades, linkedAccounts } = await this.candle.getTrades(query);
|
|
221
|
-
return {
|
|
222
|
-
trades: trades.map(({ dateTime, counterparty, gained, lost, state }) => ({
|
|
223
|
-
dateTime,
|
|
224
|
-
state,
|
|
225
|
-
counterparty: this.convertToCounterparty(counterparty),
|
|
226
|
-
lost: this.convertTradeAsset(lost),
|
|
227
|
-
gained: this.convertTradeAsset(gained),
|
|
228
|
-
})),
|
|
229
|
-
linkedAccounts,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
public async getTrade(input: {
|
|
234
|
-
lost: TradeAssetRef;
|
|
235
|
-
gained: TradeAssetRef;
|
|
236
|
-
}): Promise<Trade> {
|
|
237
|
-
const trade = await this.candle.getTrade({
|
|
238
|
-
lost: this.convertTradeAssetRef(input.lost),
|
|
239
|
-
gained: this.convertTradeAssetRef(input.gained),
|
|
240
|
-
});
|
|
241
|
-
return {
|
|
242
|
-
dateTime: trade.dateTime,
|
|
243
|
-
state: trade.state,
|
|
244
|
-
counterparty: this.convertToCounterparty(trade.counterparty),
|
|
245
|
-
lost: this.convertTradeAsset(trade.lost),
|
|
246
|
-
gained: this.convertTradeAsset(trade.gained),
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
public async getTradeQuotes<
|
|
251
|
-
GainedAssetKind extends AssetKind,
|
|
252
|
-
LostAssetKind extends AssetKind
|
|
253
|
-
>(request: {
|
|
254
|
-
linkedAccountIDs?: string;
|
|
255
|
-
gained: { assetKind: GainedAssetKind } & AssetQuoteRequest;
|
|
256
|
-
lost: { assetKind: LostAssetKind } & AssetQuoteRequest;
|
|
257
|
-
}): Promise<{
|
|
258
|
-
tradeQuotes: TradeQuote<GainedAssetKind, LostAssetKind>[];
|
|
259
|
-
linkedAccounts: LinkedAccountStatusRef[];
|
|
260
|
-
}> {
|
|
261
|
-
let gainedRequest: TradeAssetQuoteRequest;
|
|
262
|
-
|
|
263
|
-
switch (request.gained.assetKind) {
|
|
264
|
-
case "fiat":
|
|
265
|
-
gainedRequest = { fiatAssetQuoteRequest: request.gained };
|
|
266
|
-
break;
|
|
267
|
-
case "stock":
|
|
268
|
-
case "crypto":
|
|
269
|
-
gainedRequest = { marketAssetQuoteRequest: request.gained };
|
|
270
|
-
break;
|
|
271
|
-
case "transport":
|
|
272
|
-
gainedRequest = { transportAssetQuoteRequest: request.gained };
|
|
273
|
-
break;
|
|
274
|
-
case "nothing":
|
|
275
|
-
gainedRequest = { nothingAssetQuoteRequest: request.gained };
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
let lostRequest: TradeAssetQuoteRequest;
|
|
280
|
-
|
|
281
|
-
switch (request.lost.assetKind) {
|
|
282
|
-
case "fiat":
|
|
283
|
-
lostRequest = { fiatAssetQuoteRequest: request.lost };
|
|
284
|
-
break;
|
|
285
|
-
case "stock":
|
|
286
|
-
case "crypto":
|
|
287
|
-
lostRequest = { marketAssetQuoteRequest: request.lost };
|
|
288
|
-
break;
|
|
289
|
-
case "transport":
|
|
290
|
-
lostRequest = { transportAssetQuoteRequest: request.lost };
|
|
291
|
-
break;
|
|
292
|
-
case "nothing":
|
|
293
|
-
lostRequest = { nothingAssetQuoteRequest: request.lost };
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const { linkedAccounts, tradeQuotes } = await this.candle.getTradeQuotes({
|
|
298
|
-
linkedAccountIDs: request.linkedAccountIDs,
|
|
299
|
-
gained: gainedRequest,
|
|
300
|
-
lost: lostRequest,
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
return {
|
|
304
|
-
tradeQuotes: tradeQuotes.map((quote) => {
|
|
305
|
-
return {
|
|
306
|
-
gained: this.assertTradeAsset({
|
|
307
|
-
tradeAsset: this.convertTradeAsset(quote.gained),
|
|
308
|
-
expectedAssetKind: request.gained.assetKind,
|
|
309
|
-
}),
|
|
310
|
-
lost: this.assertTradeAsset({
|
|
311
|
-
tradeAsset: this.convertTradeAsset(quote.lost),
|
|
312
|
-
expectedAssetKind: request.lost.assetKind,
|
|
313
|
-
}),
|
|
314
|
-
context: quote.context,
|
|
315
|
-
expirationDateTime: quote.expirationDateTime,
|
|
316
|
-
};
|
|
317
|
-
}),
|
|
318
|
-
linkedAccounts,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
private convertTradeAssetRef(
|
|
323
|
-
tradeAssetRef: TradeAssetRef
|
|
324
|
-
): InternalTradeAssetRef {
|
|
325
|
-
switch (tradeAssetRef.assetKind) {
|
|
326
|
-
case "fiat":
|
|
327
|
-
return {
|
|
328
|
-
fiatAssetRef: {
|
|
329
|
-
assetKind: "fiat",
|
|
330
|
-
linkedAccountID: tradeAssetRef.linkedAccountID,
|
|
331
|
-
serviceTradeID: tradeAssetRef.serviceTradeID,
|
|
332
|
-
},
|
|
333
|
-
};
|
|
334
|
-
case "stock":
|
|
335
|
-
case "crypto":
|
|
336
|
-
return {
|
|
337
|
-
marketTradeAssetRef: {
|
|
338
|
-
assetKind: tradeAssetRef.assetKind,
|
|
339
|
-
linkedAccountID: tradeAssetRef.linkedAccountID,
|
|
340
|
-
serviceTradeID: tradeAssetRef.serviceTradeID,
|
|
341
|
-
},
|
|
342
|
-
};
|
|
343
|
-
case "transport":
|
|
344
|
-
return {
|
|
345
|
-
transportAssetRef: {
|
|
346
|
-
assetKind: "transport",
|
|
347
|
-
linkedAccountID: tradeAssetRef.linkedAccountID,
|
|
348
|
-
serviceTradeID: tradeAssetRef.serviceTradeID,
|
|
349
|
-
},
|
|
350
|
-
};
|
|
351
|
-
case "other":
|
|
352
|
-
return {
|
|
353
|
-
otherAssetRef: {
|
|
354
|
-
assetKind: "other",
|
|
355
|
-
},
|
|
356
|
-
};
|
|
357
|
-
case "nothing":
|
|
358
|
-
return {
|
|
359
|
-
nothingAssetRef: {
|
|
360
|
-
assetKind: "nothing",
|
|
361
|
-
},
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
private toInternalTradeAsset(asset: TradeAsset): InternalTradeAsset {
|
|
367
|
-
switch (asset.assetKind) {
|
|
368
|
-
case "fiat":
|
|
369
|
-
return { fiatAsset: asset };
|
|
370
|
-
case "stock":
|
|
371
|
-
case "crypto":
|
|
372
|
-
return {
|
|
373
|
-
marketTradeAsset: {
|
|
374
|
-
...asset,
|
|
375
|
-
assetKind: asset.assetKind,
|
|
376
|
-
},
|
|
377
|
-
};
|
|
378
|
-
case "transport":
|
|
379
|
-
return { transportAsset: asset };
|
|
380
|
-
case "other":
|
|
381
|
-
return { otherAsset: asset };
|
|
382
|
-
case "nothing":
|
|
383
|
-
return { nothingAsset: asset };
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
private convertTradeQuote(
|
|
388
|
-
tradeQuote: TradeQuote<AssetKind, AssetKind>
|
|
389
|
-
): InternalTradeQuote {
|
|
390
|
-
const { context, gained, lost } = tradeQuote;
|
|
391
|
-
return {
|
|
392
|
-
context,
|
|
393
|
-
gained: this.toInternalTradeAsset(gained),
|
|
394
|
-
lost: this.toInternalTradeAsset(lost),
|
|
395
|
-
expirationDateTime: tradeQuote.expirationDateTime,
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
private convertTradeAsset(tradeAsset: InternalTradeAsset): TradeAsset {
|
|
400
|
-
if (tradeAsset.fiatAsset !== undefined) {
|
|
401
|
-
return {
|
|
402
|
-
...tradeAsset.fiatAsset,
|
|
403
|
-
assetKind: "fiat",
|
|
404
|
-
};
|
|
405
|
-
} else if (tradeAsset.marketTradeAsset !== undefined) {
|
|
406
|
-
this.assertMarketAssetKind(tradeAsset.marketTradeAsset.assetKind);
|
|
407
|
-
return {
|
|
408
|
-
...tradeAsset.marketTradeAsset,
|
|
409
|
-
assetKind: this.assertMarketAssetKind(
|
|
410
|
-
tradeAsset.marketTradeAsset.assetKind
|
|
411
|
-
),
|
|
412
|
-
};
|
|
413
|
-
} else if (tradeAsset.transportAsset !== undefined) {
|
|
414
|
-
return {
|
|
415
|
-
...tradeAsset.transportAsset,
|
|
416
|
-
assetKind: "transport",
|
|
417
|
-
};
|
|
418
|
-
} else if (tradeAsset.otherAsset !== undefined) {
|
|
419
|
-
return { assetKind: "other" };
|
|
420
|
-
} else if (tradeAsset.nothingAsset !== undefined) {
|
|
421
|
-
return { assetKind: "nothing" };
|
|
422
|
-
} else {
|
|
423
|
-
throw new Error("Internal Candle Error: corrupted trade asset.");
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
private assertTradeAsset<ExpectedAssetKind extends AssetKind>(input: {
|
|
428
|
-
tradeAsset: TradeAsset;
|
|
429
|
-
expectedAssetKind: ExpectedAssetKind;
|
|
430
|
-
}): TradeAsset & {
|
|
431
|
-
assetKind: ExpectedAssetKind;
|
|
432
|
-
} {
|
|
433
|
-
if (input.tradeAsset.assetKind === input.expectedAssetKind) {
|
|
434
|
-
// NOTE: This cast is due to a typescript generics limitation and should be cleaned up when possible
|
|
435
|
-
return input.tradeAsset as TradeAsset & {
|
|
436
|
-
assetKind: ExpectedAssetKind;
|
|
437
|
-
};
|
|
438
|
-
} else {
|
|
439
|
-
throw new Error("Internal Candle Error: asset kind mismatch.");
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
private convertToCounterparty(
|
|
444
|
-
counterparty: InternalCounterparty
|
|
445
|
-
): Counterparty {
|
|
446
|
-
if (counterparty.merchantCounterparty !== undefined) {
|
|
447
|
-
return {
|
|
448
|
-
...counterparty.merchantCounterparty,
|
|
449
|
-
kind: "merchant",
|
|
450
|
-
};
|
|
451
|
-
} else if (counterparty.userCounterparty !== undefined) {
|
|
452
|
-
return {
|
|
453
|
-
...counterparty.userCounterparty,
|
|
454
|
-
kind: "user",
|
|
455
|
-
};
|
|
456
|
-
} else if (counterparty.serviceCounterparty !== undefined) {
|
|
457
|
-
return {
|
|
458
|
-
...counterparty.serviceCounterparty,
|
|
459
|
-
kind: "service",
|
|
460
|
-
};
|
|
461
|
-
} else {
|
|
462
|
-
throw new Error("Unknown counterparty kind");
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
private assertFiatAssetKind(kind: string): "fiat" {
|
|
467
|
-
if (kind !== "fiat") {
|
|
468
|
-
throw new Error("Internal Candle Error: corrupted market account.");
|
|
469
|
-
} else {
|
|
470
|
-
return kind;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
private assertMarketAssetKind(kind: string): "stock" | "crypto" {
|
|
475
|
-
if (kind !== "stock" && kind !== "crypto") {
|
|
476
|
-
throw new Error("Internal Candle Error: corrupted market account.");
|
|
477
|
-
} else {
|
|
478
|
-
return kind;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
private assertTransportAssetKind(kind: string): "transport" {
|
|
483
|
-
if (kind !== "transport") {
|
|
484
|
-
throw new Error("Internal Candle Error: corrupted market account.");
|
|
485
|
-
} else {
|
|
486
|
-
return kind;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
private convertToAssetAccount(account: InternalAssetAccount): AssetAccount {
|
|
491
|
-
const { fiatAccount, marketAccount, transportAccount } = account;
|
|
492
|
-
|
|
493
|
-
if (fiatAccount !== undefined) {
|
|
494
|
-
return {
|
|
495
|
-
...fiatAccount,
|
|
496
|
-
assetKind: this.assertFiatAssetKind(fiatAccount.assetKind),
|
|
497
|
-
};
|
|
498
|
-
} else if (marketAccount !== undefined) {
|
|
499
|
-
return {
|
|
500
|
-
...marketAccount,
|
|
501
|
-
assetKind: this.assertMarketAssetKind(marketAccount.assetKind),
|
|
502
|
-
};
|
|
503
|
-
} else if (transportAccount !== undefined) {
|
|
504
|
-
return {
|
|
505
|
-
...transportAccount,
|
|
506
|
-
assetKind: this.assertTransportAssetKind(transportAccount.assetKind),
|
|
507
|
-
};
|
|
508
|
-
} else {
|
|
509
|
-
throw new Error("Internal Candle Error: corrupted asset account.");
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
type AssetKind = "nothing" | "transport" | "fiat" | "stock" | "crypto";
|
|
515
|
-
|
|
516
|
-
type AssetQuoteRequest =
|
|
517
|
-
| ({
|
|
518
|
-
assetKind: "nothing";
|
|
519
|
-
} & NothingAssetQuoteRequest)
|
|
520
|
-
| ({ assetKind: "transport" } & TransportAssetQuoteRequest)
|
|
521
|
-
| ({ assetKind: "fiat" } & FiatAssetQuoteRequest)
|
|
522
|
-
| ({ assetKind: "stock" | "crypto" } & MarketAssetQuoteRequest);
|
|
523
|
-
|
|
524
|
-
type TradeAsset =
|
|
525
|
-
| ({
|
|
526
|
-
assetKind: "nothing";
|
|
527
|
-
} & NothingAsset)
|
|
528
|
-
| ({
|
|
529
|
-
assetKind: "other";
|
|
530
|
-
} & OtherAsset)
|
|
531
|
-
| ({ assetKind: "transport" } & TransportAsset)
|
|
532
|
-
| ({ assetKind: "fiat" } & FiatAsset)
|
|
533
|
-
| ({ assetKind: "stock" | "crypto" } & MarketTradeAsset);
|
|
534
|
-
|
|
535
|
-
type Counterparty =
|
|
536
|
-
| ({ kind: "merchant" } & MerchantCounterparty)
|
|
537
|
-
| ({
|
|
538
|
-
kind: "user";
|
|
539
|
-
} & UserCounterparty)
|
|
540
|
-
| ({
|
|
541
|
-
kind: "service";
|
|
542
|
-
} & ServiceCounterparty);
|
|
543
|
-
|
|
544
|
-
type TradeQuery = {
|
|
545
|
-
gainedAssetKind?: TradeQueryAssetKind;
|
|
546
|
-
lostAssetKind?: TradeQueryAssetKind;
|
|
547
|
-
counterpartyKind?: "merchant" | "user" | "service";
|
|
548
|
-
} & InternalTradeQuery;
|
|
549
|
-
|
|
550
|
-
type TradeQuote<
|
|
551
|
-
GainedAssetKind extends AssetKind,
|
|
552
|
-
LostAssetKind extends AssetKind
|
|
553
|
-
> = {
|
|
554
|
-
gained: TradeAsset & { assetKind: GainedAssetKind };
|
|
555
|
-
lost: TradeAsset & { assetKind: LostAssetKind };
|
|
556
|
-
context: string;
|
|
557
|
-
expirationDateTime: string;
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
type TradeQueryAssetKind =
|
|
561
|
-
| "fiat"
|
|
562
|
-
| "stock"
|
|
563
|
-
| "crypto"
|
|
564
|
-
| "transport"
|
|
565
|
-
| "other"
|
|
566
|
-
| "nothing";
|
|
567
|
-
|
|
568
|
-
type AssetAccount = {
|
|
569
|
-
serviceAccountID: string;
|
|
570
|
-
nickname: string;
|
|
571
|
-
linkedAccountID: string;
|
|
572
|
-
service: Service;
|
|
573
|
-
} & (
|
|
574
|
-
| {
|
|
575
|
-
assetKind: "fiat";
|
|
576
|
-
accountKind: FiatMarketAccountKind;
|
|
577
|
-
currencyCode: string;
|
|
578
|
-
balance?: number;
|
|
579
|
-
ach?: ACHDetails;
|
|
580
|
-
wire?: WireDetails;
|
|
581
|
-
}
|
|
582
|
-
| {
|
|
583
|
-
assetKind: "stock" | "crypto";
|
|
584
|
-
accountKind: FiatMarketAccountKind;
|
|
585
|
-
}
|
|
586
|
-
| {
|
|
587
|
-
assetKind: "transport";
|
|
588
|
-
accountKind: TransportAccountKind;
|
|
589
|
-
}
|
|
590
|
-
);
|
|
591
|
-
|
|
592
|
-
type Trade = {
|
|
593
|
-
dateTime: string;
|
|
594
|
-
state: TradeState;
|
|
595
|
-
counterparty: Counterparty;
|
|
596
|
-
lost: TradeAsset;
|
|
597
|
-
gained: TradeAsset;
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
type TradeAssetRef =
|
|
601
|
-
| ({ assetKind: "transport" } & TransportAssetRef)
|
|
602
|
-
| ({ assetKind: "nothing" } & NothingAssetRef)
|
|
603
|
-
| ({ assetKind: "other" } & OtherAssetRef)
|
|
604
|
-
| ({ assetKind: "fiat" } & FiatAssetRef)
|
|
605
|
-
| ({ assetKind: "stock" | "crypto" } & MarketTradeAssetRef);
|
|
606
|
-
|
|
607
|
-
type LinkedAccountDetail =
|
|
608
|
-
| (LinkedAccount & {
|
|
609
|
-
details: { state: "active" } & ActiveLinkedAccountDetails;
|
|
610
|
-
})
|
|
611
|
-
| (LinkedAccount & {
|
|
612
|
-
details: { state: "inactive" | "unavailable" };
|
|
613
|
-
});
|
|
614
|
-
|
|
615
|
-
export type {
|
|
616
|
-
Address,
|
|
617
|
-
AppUser,
|
|
618
|
-
AssetAccount,
|
|
619
|
-
AssetAccountRef,
|
|
620
|
-
AssetKind,
|
|
621
|
-
Coordinates,
|
|
622
|
-
Counterparty,
|
|
623
|
-
LinkedAccount,
|
|
624
|
-
LinkedAccountDetail,
|
|
625
|
-
LinkedAccountRef,
|
|
626
|
-
LinkedAccountStatusRef,
|
|
627
|
-
Service,
|
|
628
|
-
Trade,
|
|
629
|
-
TradeAsset,
|
|
630
|
-
TradeAssetRef,
|
|
631
|
-
TradeQuery,
|
|
632
|
-
TradeQuote,
|
|
633
|
-
TradeState,
|
|
634
|
-
};
|
|
1
|
+
export { CandleContext, useCandle } from "./context";
|
|
2
|
+
export type { CandleContextValue } from "./context";
|
|
3
|
+
export { CandleProvider } from "./provider";
|
|
4
|
+
export type * from "./types";
|