@coinflowlabs/angular 0.0.3 → 0.0.4

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 (40) hide show
  1. package/ng-package.json +7 -0
  2. package/package.json +9 -17
  3. package/src/lib/coinflow-iframe.component.ts +63 -0
  4. package/src/lib/coinflow-purchase-history.component.ts +9 -0
  5. package/src/lib/coinflow-purchase-protection.component.ts +9 -0
  6. package/src/lib/coinflow-purchase.component.ts +37 -0
  7. package/src/lib/coinflow-withdraw-history.component.ts +9 -0
  8. package/src/lib/coinflow-withdraw.component.ts +36 -0
  9. package/src/lib/common/CoinflowLibMessageHandlers.ts +188 -0
  10. package/src/lib/common/CoinflowTypes.ts +403 -0
  11. package/src/lib/common/CoinflowUtils.ts +269 -0
  12. package/{public-api.d.ts → src/public-api.ts} +4 -0
  13. package/tsconfig.lib.json +14 -0
  14. package/tsconfig.lib.prod.json +10 -0
  15. package/tsconfig.spec.json +14 -0
  16. package/esm2022/coinflowlabs-angular.mjs +0 -5
  17. package/esm2022/lib/coinflow-iframe.component.mjs +0 -67
  18. package/esm2022/lib/coinflow-purchase-history.component.mjs +0 -16
  19. package/esm2022/lib/coinflow-purchase-protection.component.mjs +0 -16
  20. package/esm2022/lib/coinflow-purchase.component.mjs +0 -32
  21. package/esm2022/lib/coinflow-withdraw-history.component.mjs +0 -16
  22. package/esm2022/lib/coinflow-withdraw.component.mjs +0 -32
  23. package/esm2022/lib/common/CoinflowLibMessageHandlers.mjs +0 -127
  24. package/esm2022/lib/common/CoinflowTypes.mjs +0 -13
  25. package/esm2022/lib/common/CoinflowUtils.mjs +0 -173
  26. package/esm2022/lib/common/index.mjs +0 -4
  27. package/esm2022/public-api.mjs +0 -10
  28. package/fesm2022/coinflowlabs-angular.mjs +0 -486
  29. package/fesm2022/coinflowlabs-angular.mjs.map +0 -1
  30. package/index.d.ts +0 -5
  31. package/lib/coinflow-iframe.component.d.ts +0 -17
  32. package/lib/coinflow-purchase-history.component.d.ts +0 -5
  33. package/lib/coinflow-purchase-protection.component.d.ts +0 -5
  34. package/lib/coinflow-purchase.component.d.ts +0 -10
  35. package/lib/coinflow-withdraw-history.component.d.ts +0 -5
  36. package/lib/coinflow-withdraw.component.d.ts +0 -10
  37. package/lib/common/CoinflowLibMessageHandlers.d.ts +0 -21
  38. package/lib/common/CoinflowTypes.d.ts +0 -287
  39. package/lib/common/CoinflowUtils.d.ts +0 -21
  40. /package/{lib/common/index.d.ts → src/lib/common/index.ts} +0 -0
@@ -0,0 +1,403 @@
1
+ import type {
2
+ Connection,
3
+ VersionedTransaction,
4
+ PublicKey,
5
+ Signer,
6
+ Transaction,
7
+ } from '@solana/web3.js';
8
+
9
+ export enum SettlementType {
10
+ Credits = 'Credits',
11
+ USDC = 'USDC',
12
+ Bank = 'Bank',
13
+ }
14
+
15
+ export enum MerchantStyle {
16
+ Rounded = 'rounded',
17
+ Sharp = 'sharp',
18
+ Pill = 'pill',
19
+ }
20
+
21
+ export type MerchantTheme = {
22
+ primary?: string;
23
+ background?: string;
24
+ backgroundAccent?: string;
25
+ backgroundAccent2?: string;
26
+ textColor?: string;
27
+ textColorAccent?: string;
28
+ textColorAction?: string;
29
+ font?: string;
30
+ style?: MerchantStyle;
31
+ };
32
+
33
+ export interface CustomerInfo {
34
+ name?: string;
35
+ verificationId?: string;
36
+ displayName?: string;
37
+ address?: string;
38
+ city?: string;
39
+ state?: string;
40
+ zip?: string;
41
+ country?: string;
42
+ ip?: string;
43
+ lat?: string;
44
+ lng?: string;
45
+ }
46
+
47
+ /** Coinflow Types **/
48
+ export type CoinflowBlockchain = 'solana' | 'near' | 'eth' | 'polygon' | 'base';
49
+ export type CoinflowEnvs = 'prod' | 'staging' | 'sandbox' | 'local';
50
+
51
+ export interface CoinflowTypes {
52
+ merchantId: string;
53
+ env?: CoinflowEnvs;
54
+ loaderBackground?: string;
55
+ blockchain: CoinflowBlockchain;
56
+ handleHeightChange?: (height: string) => void;
57
+ theme?: MerchantTheme;
58
+ }
59
+
60
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
61
+
62
+ export type OnSuccessMethod = (params: string) => void | Promise<void>;
63
+
64
+ /** Wallets **/
65
+ export interface SolanaWallet {
66
+ publicKey: PublicKey | null;
67
+ signTransaction?: <T extends Transaction | VersionedTransaction>(
68
+ transaction: T
69
+ ) => Promise<T>;
70
+ sendTransaction: <T extends Transaction | VersionedTransaction>(
71
+ transaction: T
72
+ ) => Promise<string>;
73
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
74
+ }
75
+
76
+ export interface NearWallet {
77
+ accountId: string;
78
+ signAndSendTransaction: (transaction: unknown) => Promise<{
79
+ transaction: {hash: string};
80
+ }>;
81
+ }
82
+
83
+ type AccessList = Array<{address: string; storageKeys: Array<string>}>;
84
+ type AccessListish =
85
+ | AccessList
86
+ | Array<[string, Array<string>]>
87
+ | Record<string, Array<string>>;
88
+
89
+ export type EthWallet = {
90
+ address: string | null | undefined;
91
+ sendTransaction: (transaction: {
92
+ to: string;
93
+ from?: string;
94
+ nonce?: Bytes | bigint | string | number;
95
+
96
+ gasLimit?: Bytes | bigint | string | number;
97
+ gasPrice?: Bytes | bigint | string | number;
98
+
99
+ data?: BytesLike;
100
+ value?: Bytes | bigint | string | number;
101
+ chainId?: number;
102
+
103
+ type?: number;
104
+ accessList?: AccessListish;
105
+
106
+ maxPriorityFeePerGas?: Bytes | bigint | string | number;
107
+ maxFeePerGas?: Bytes | bigint | string | number;
108
+
109
+ customData?: Record<string, any>;
110
+ ccipReadEnabled?: boolean;
111
+ }) => Promise<{hash: string}>;
112
+ signMessage: (message: string) => Promise<string>;
113
+ };
114
+
115
+ /** History **/
116
+ export interface CoinflowSolanaHistoryProps extends CoinflowTypes {
117
+ wallet: SolanaWallet;
118
+ connection: Connection;
119
+ blockchain: 'solana';
120
+ }
121
+
122
+ export interface CoinflowNearHistoryProps extends CoinflowTypes {
123
+ wallet: NearWallet;
124
+ blockchain: 'near';
125
+ }
126
+
127
+ export interface CoinflowEvmHistoryProps extends CoinflowTypes {
128
+ wallet: EthWallet;
129
+ }
130
+
131
+ export interface CoinflowEthHistoryProps extends CoinflowEvmHistoryProps {
132
+ blockchain: 'eth';
133
+ }
134
+
135
+ export interface CoinflowPolygonHistoryProps extends CoinflowEvmHistoryProps {
136
+ blockchain: 'polygon';
137
+ }
138
+
139
+ export interface CoinflowBaseHistoryProps extends CoinflowEvmHistoryProps {
140
+ blockchain: 'base';
141
+ }
142
+
143
+ export type CoinflowHistoryProps =
144
+ | CoinflowSolanaHistoryProps
145
+ | CoinflowNearHistoryProps
146
+ | CoinflowPolygonHistoryProps
147
+ | CoinflowEthHistoryProps
148
+ | CoinflowBaseHistoryProps;
149
+
150
+ /** Transactions **/
151
+
152
+ export type NearFtTransferCallAction = {
153
+ methodName: 'ft_transfer_call';
154
+ args: object;
155
+ gas: string;
156
+ deposit: string;
157
+ };
158
+
159
+ type Bytes = ArrayLike<number>;
160
+ type BytesLike = Bytes | string;
161
+
162
+ /** Purchase **/
163
+
164
+ export type ChargebackProtectionData = ChargebackProtectionItem[];
165
+
166
+ export interface ChargebackProtectionItem {
167
+ /**
168
+ * The name of the product
169
+ */
170
+ productName: string;
171
+ /**
172
+ * The product type. Possible values include: inGameProduct, gameOfSkill, dataStorage, computingResources, sportsTicket, eSportsTicket, musicTicket, conferenceTicket, virtualSportsTicket, virtualESportsTicket, virtualMusicTicket, virtualConferenceTicket, alcohol, DLC, subscription, fundACause, realEstate, computingContract, digitalArt, topUp
173
+ */
174
+ productType:
175
+ | 'inGameProduct'
176
+ | 'gameOfSkill'
177
+ | 'dataStorage'
178
+ | 'computingResources'
179
+ | 'sportsTicket'
180
+ | 'eSportsTicket'
181
+ | 'musicTicket'
182
+ | 'conferenceTicket'
183
+ | 'virtualSportsTicket'
184
+ | 'virtualESportsTicket'
185
+ | 'virtualMusicTicket'
186
+ | 'virtualConferenceTicket'
187
+ | 'alcohol'
188
+ | 'DLC'
189
+ | 'subscription'
190
+ | 'fundACause'
191
+ | 'realEstate'
192
+ | 'computingContract'
193
+ | 'digitalArt'
194
+ | 'topUp'
195
+ | 'ownershipContract';
196
+ /**
197
+ * The item's list price
198
+ */
199
+ /**
200
+ * The number of units sold
201
+ */
202
+ quantity: number;
203
+ /**
204
+ * Any additional data that the store can provide on the product, e.g. description, link to image, etc.
205
+ */
206
+ rawProductData?: {[key: string]: any};
207
+ }
208
+
209
+ export interface CoinflowCommonPurchaseProps extends CoinflowTypes {
210
+ amount?: number;
211
+ onSuccess?: OnSuccessMethod;
212
+ webhookInfo?: object;
213
+ email?: string;
214
+ chargebackProtectionData?: ChargebackProtectionData;
215
+ planCode?: string;
216
+ disableApplePay?: boolean;
217
+ disableGooglePay?: boolean;
218
+ customerInfo?: CustomerInfo;
219
+ settlementType?: SettlementType;
220
+ authOnly?: boolean;
221
+ deviceId?: string;
222
+ }
223
+
224
+ export interface CoinflowSolanaPurchaseProps
225
+ extends CoinflowCommonPurchaseProps {
226
+ wallet: SolanaWallet;
227
+ transaction?: Transaction | VersionedTransaction;
228
+ partialSigners?: Signer[];
229
+ debugTx?: boolean;
230
+ connection: Connection;
231
+ blockchain: 'solana';
232
+ token?: PublicKey | string;
233
+ supportsVersionedTransactions?: boolean;
234
+ rent?: {lamports: string | number};
235
+ nativeSolToConvert?: {lamports: string | number};
236
+ }
237
+
238
+ export interface CoinflowNearPurchaseProps extends CoinflowCommonPurchaseProps {
239
+ wallet: NearWallet;
240
+ blockchain: 'near';
241
+ action?: NearFtTransferCallAction;
242
+ nearDeposit?: string;
243
+ }
244
+
245
+ export interface CoinflowEvmPurchaseProps extends CoinflowCommonPurchaseProps {
246
+ transaction?: EvmTransactionData;
247
+ token?: string;
248
+ wallet: EthWallet;
249
+ }
250
+
251
+ export interface CoinflowPolygonPurchaseProps extends CoinflowEvmPurchaseProps {
252
+ blockchain: 'polygon';
253
+ }
254
+
255
+ export interface CoinflowEthPurchaseProps extends CoinflowEvmPurchaseProps {
256
+ blockchain: 'eth';
257
+ }
258
+
259
+ export interface CoinflowBasePurchaseProps extends CoinflowEvmPurchaseProps {
260
+ blockchain: 'base';
261
+ }
262
+
263
+ export type CoinflowPurchaseProps =
264
+ | CoinflowSolanaPurchaseProps
265
+ | CoinflowNearPurchaseProps
266
+ | CoinflowPolygonPurchaseProps
267
+ | CoinflowEthPurchaseProps
268
+ | CoinflowBasePurchaseProps;
269
+
270
+ /** Withdraw **/
271
+
272
+ export interface CoinflowCommonWithdrawProps extends CoinflowTypes {
273
+ onSuccess?: OnSuccessMethod;
274
+ tokens?: string[];
275
+ lockDefaultToken?: boolean;
276
+ amount?: number;
277
+ email?: string;
278
+ bankAccountLinkRedirect?: string;
279
+ additionalWallets?: {
280
+ wallet: string;
281
+ blockchain: 'solana' | 'eth' | 'near' | 'polygon';
282
+ }[];
283
+ supportsVersionedTransactions?: boolean;
284
+ lockAmount?: boolean;
285
+ transactionSigner?: string;
286
+ }
287
+
288
+ export interface CoinflowSolanaWithdrawProps
289
+ extends CoinflowCommonWithdrawProps {
290
+ wallet: SolanaWallet;
291
+ connection: Connection;
292
+ blockchain: 'solana';
293
+ }
294
+
295
+ export interface CoinflowNearWithdrawProps extends CoinflowCommonWithdrawProps {
296
+ wallet: NearWallet;
297
+ blockchain: 'near';
298
+ }
299
+
300
+ export interface CoinflowEvmWithdrawProps extends CoinflowCommonWithdrawProps {
301
+ wallet: EthWallet;
302
+ usePermit?: boolean;
303
+ }
304
+
305
+ export interface CoinflowEthWithdrawProps extends CoinflowEvmWithdrawProps {
306
+ blockchain: 'eth';
307
+ usePermit?: boolean;
308
+ }
309
+
310
+ export interface CoinflowPolygonWithdrawProps extends CoinflowEvmWithdrawProps {
311
+ blockchain: 'polygon';
312
+ }
313
+
314
+ export interface CoinflowBaseWithdrawProps extends CoinflowEvmWithdrawProps {
315
+ blockchain: 'base';
316
+ }
317
+
318
+ export type CoinflowWithdrawProps =
319
+ | CoinflowSolanaWithdrawProps
320
+ | CoinflowNearWithdrawProps
321
+ | CoinflowEthWithdrawProps
322
+ | CoinflowPolygonWithdrawProps
323
+ | CoinflowBaseWithdrawProps;
324
+
325
+ export interface CommonEvmRedeem {
326
+ waitForHash?: boolean;
327
+ }
328
+
329
+ export interface NormalRedeem extends CommonEvmRedeem {
330
+ transaction: {to: string; data: string};
331
+ }
332
+
333
+ export interface KnownTokenIdRedeem extends NormalRedeem {
334
+ nftContract: string;
335
+ nftId: string;
336
+ }
337
+
338
+ export interface SafeMintRedeem extends NormalRedeem {
339
+ type: 'safeMint';
340
+ nftContract?: string;
341
+ }
342
+
343
+ export interface ReturnedTokenIdRedeem extends NormalRedeem {
344
+ type: 'returned';
345
+ nftContract?: string;
346
+ }
347
+
348
+ type ReservoirNftIdItem = Omit<KnownTokenIdRedeem, keyof NormalRedeem>;
349
+ interface ReservoirOrderIdItem {
350
+ orderId: string;
351
+ }
352
+ type ReservoirItem = ReservoirNftIdItem | ReservoirOrderIdItem;
353
+ type ReservoirItems = ReservoirItem | ReservoirItem[];
354
+
355
+ export interface ReservoirRedeem extends CommonEvmRedeem {
356
+ type: 'reservoir';
357
+ items: ReservoirItems;
358
+ }
359
+
360
+ export type EvmTransactionData =
361
+ | SafeMintRedeem
362
+ | ReturnedTokenIdRedeem
363
+ | ReservoirRedeem
364
+ | KnownTokenIdRedeem
365
+ | NormalRedeem;
366
+
367
+ export interface CoinflowIFrameProps
368
+ extends Omit<CoinflowTypes, 'merchantId'>,
369
+ Pick<
370
+ CoinflowCommonPurchaseProps,
371
+ | 'chargebackProtectionData'
372
+ | 'webhookInfo'
373
+ | 'amount'
374
+ | 'customerInfo'
375
+ | 'settlementType'
376
+ | 'email'
377
+ | 'planCode'
378
+ | 'deviceId'
379
+ >,
380
+ Pick<
381
+ CoinflowCommonWithdrawProps,
382
+ | 'bankAccountLinkRedirect'
383
+ | 'additionalWallets'
384
+ | 'transactionSigner'
385
+ | 'lockAmount'
386
+ | 'lockDefaultToken'
387
+ >,
388
+ Pick<CoinflowEvmPurchaseProps, 'authOnly'>,
389
+ Pick<CoinflowSolanaPurchaseProps, 'rent' | 'nativeSolToConvert' | 'token'> {
390
+ walletPubkey: string | null | undefined;
391
+ route: string;
392
+ routePrefix?: string;
393
+ transaction?: string;
394
+ tokens?: string[] | PublicKey[];
395
+ supportsVersionedTransactions?: boolean;
396
+ nearDeposit?: string;
397
+ merchantCss?: string;
398
+ color?: 'white' | 'black';
399
+ disableApplePay?: boolean;
400
+ disableGooglePay?: boolean;
401
+ theme?: MerchantTheme;
402
+ usePermit?: boolean;
403
+ }
@@ -0,0 +1,269 @@
1
+ import {
2
+ CoinflowBlockchain,
3
+ CoinflowEnvs,
4
+ CoinflowIFrameProps,
5
+ CoinflowPurchaseProps,
6
+ } from './CoinflowTypes';
7
+ import * as web3 from '@solana/web3.js';
8
+ import * as base58 from 'bs58';
9
+
10
+ export class CoinflowUtils {
11
+ env: CoinflowEnvs;
12
+ url: string;
13
+
14
+ constructor(env?: CoinflowEnvs) {
15
+ this.env = env ?? 'prod';
16
+ if (this.env === 'prod') this.url = 'https://api.coinflow.cash';
17
+ else if (this.env === 'local') this.url = 'http://localhost:5000';
18
+ else this.url = `https://api-${this.env}.coinflow.cash`;
19
+ }
20
+
21
+ async getNSurePartnerId(merchantId: string): Promise<string | undefined> {
22
+ return fetch(this.url + `/merchant/view/${merchantId}`)
23
+ .then(response => response.json())
24
+ .then(
25
+ (json: {
26
+ nSurePartnerId: string | undefined;
27
+ nSureSettings: {nSurePartnerId: string | undefined};
28
+ }) => json.nSureSettings?.nSurePartnerId || json.nSurePartnerId
29
+ )
30
+ .catch(e => {
31
+ console.error(e);
32
+ return undefined;
33
+ });
34
+ }
35
+
36
+ async getCreditBalance(
37
+ publicKey: string,
38
+ merchantId: string,
39
+ blockchain: 'solana' | 'near'
40
+ ): Promise<{cents: number}> {
41
+ const response = await fetch(
42
+ this.url + `/api/customer/balances/${merchantId}`,
43
+ {
44
+ method: 'GET',
45
+ headers: {
46
+ 'x-coinflow-auth-wallet': publicKey,
47
+ 'x-coinflow-auth-blockchain': blockchain,
48
+ },
49
+ }
50
+ );
51
+ const {credits} = await response.json();
52
+ return credits;
53
+ }
54
+
55
+ static getCoinflowBaseUrl(env?: CoinflowEnvs): string {
56
+ if (!env || env === 'prod') return 'https://coinflow.cash';
57
+ if (env === 'local') return 'http://localhost:3000';
58
+
59
+ return `https://${env}.coinflow.cash`;
60
+ }
61
+
62
+ static getCoinflowApiUrl(env?: CoinflowEnvs): string {
63
+ if (!env || env === 'prod') return 'https://api.coinflow.cash';
64
+ if (env === 'local') return 'http://localhost:5000';
65
+
66
+ return `https://api-${env}.coinflow.cash`;
67
+ }
68
+
69
+ static getCoinflowUrl({
70
+ walletPubkey,
71
+ route,
72
+ routePrefix,
73
+ env,
74
+ amount,
75
+ transaction,
76
+ blockchain,
77
+ supportsVersionedTransactions,
78
+ webhookInfo,
79
+ email,
80
+ loaderBackground,
81
+ handleHeightChange,
82
+ bankAccountLinkRedirect,
83
+ additionalWallets,
84
+ nearDeposit,
85
+ chargebackProtectionData,
86
+ merchantCss,
87
+ color,
88
+ rent,
89
+ lockDefaultToken,
90
+ token,
91
+ tokens,
92
+ planCode,
93
+ disableApplePay,
94
+ disableGooglePay,
95
+ customerInfo,
96
+ settlementType,
97
+ lockAmount,
98
+ nativeSolToConvert,
99
+ theme,
100
+ usePermit,
101
+ transactionSigner,
102
+ authOnly,
103
+ deviceId,
104
+ }: CoinflowIFrameProps): string {
105
+ const prefix = routePrefix
106
+ ? `/${routePrefix}/${blockchain}`
107
+ : `/${blockchain}`;
108
+ const url = new URL(prefix + route, CoinflowUtils.getCoinflowBaseUrl(env));
109
+ url.searchParams.append('pubkey', walletPubkey!);
110
+
111
+ if (transaction) {
112
+ url.searchParams.append('transaction', transaction);
113
+ }
114
+ if (amount) {
115
+ url.searchParams.append('amount', amount.toString());
116
+ }
117
+
118
+ if (supportsVersionedTransactions) {
119
+ url.searchParams.append('supportsVersionedTransactions', 'true');
120
+ }
121
+
122
+ if (webhookInfo) {
123
+ url.searchParams.append(
124
+ 'webhookInfo',
125
+ Buffer.from(JSON.stringify(webhookInfo)).toString('base64')
126
+ );
127
+ }
128
+
129
+ if (theme) {
130
+ url.searchParams.append(
131
+ 'theme',
132
+ Buffer.from(JSON.stringify(theme)).toString('base64')
133
+ );
134
+ }
135
+
136
+ if (customerInfo) {
137
+ url.searchParams.append(
138
+ 'customerInfo',
139
+ Buffer.from(JSON.stringify(customerInfo)).toString('base64')
140
+ );
141
+ }
142
+
143
+ if (email) {
144
+ url.searchParams.append('email', email);
145
+ }
146
+
147
+ if (token) {
148
+ url.searchParams.append('token', token.toString());
149
+ }
150
+
151
+ if (tokens) {
152
+ url.searchParams.append('tokens', tokens.toString());
153
+ }
154
+
155
+ if (loaderBackground) {
156
+ url.searchParams.append('loaderBackground', loaderBackground);
157
+ }
158
+
159
+ if (handleHeightChange) {
160
+ url.searchParams.append('useHeightChange', 'true');
161
+ }
162
+
163
+ if (bankAccountLinkRedirect) {
164
+ url.searchParams.append(
165
+ 'bankAccountLinkRedirect',
166
+ bankAccountLinkRedirect
167
+ );
168
+ }
169
+
170
+ if (additionalWallets)
171
+ url.searchParams.append(
172
+ 'additionalWallets',
173
+ JSON.stringify(additionalWallets)
174
+ );
175
+
176
+ if (nearDeposit) url.searchParams.append('nearDeposit', nearDeposit);
177
+
178
+ if (chargebackProtectionData)
179
+ url.searchParams.append(
180
+ 'chargebackProtectionData',
181
+ JSON.stringify(chargebackProtectionData)
182
+ );
183
+ if (deviceId) {
184
+ url.searchParams.append('deviceId', deviceId);
185
+ } else {
186
+ if (typeof window !== 'undefined') {
187
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
188
+ // @ts-ignore
189
+ const deviceId = window?.nSureSDK?.getDeviceId();
190
+ if (deviceId) url.searchParams.append('deviceId', deviceId);
191
+ }
192
+ }
193
+
194
+ if (merchantCss) url.searchParams.append('merchantCss', merchantCss);
195
+ if (color) url.searchParams.append('color', color);
196
+ if (rent) url.searchParams.append('rent', rent.lamports.toString());
197
+ if (nativeSolToConvert)
198
+ url.searchParams.append(
199
+ 'nativeSolToConvert',
200
+ nativeSolToConvert.lamports.toString()
201
+ );
202
+ if (lockDefaultToken) url.searchParams.append('lockDefaultToken', 'true');
203
+ if (planCode) url.searchParams.append('planCode', planCode);
204
+
205
+ if (disableApplePay) url.searchParams.append('disableApplePay', 'true');
206
+ if (disableGooglePay) url.searchParams.append('disableGooglePay', 'true');
207
+ if (settlementType)
208
+ url.searchParams.append('settlementType', settlementType);
209
+
210
+ if (lockAmount) url.searchParams.append('lockAmount', 'true');
211
+
212
+ if (usePermit === false) url.searchParams.append('usePermit', 'false');
213
+ if (transactionSigner)
214
+ url.searchParams.append('transactionSigner', transactionSigner);
215
+ if (authOnly === true) url.searchParams.append('authOnly', 'true');
216
+
217
+ return url.toString();
218
+ }
219
+
220
+ static getTransaction(props: CoinflowPurchaseProps): string | undefined {
221
+ if ('transaction' in props && props.transaction !== undefined) {
222
+ const {transaction} = props;
223
+ if (web3 && transaction instanceof web3.Transaction) {
224
+ if (!base58) throw new Error('bs58 dependency is required for Solana');
225
+ return base58.encode(
226
+ transaction.serialize({
227
+ requireAllSignatures: false,
228
+ verifySignatures: false,
229
+ })
230
+ );
231
+ }
232
+
233
+ if (web3 && transaction instanceof web3.VersionedTransaction) {
234
+ if (!base58) throw new Error('bs58 dependency is required for Solana');
235
+ return base58.encode(transaction.serialize());
236
+ }
237
+
238
+ return btoa(JSON.stringify(transaction));
239
+ }
240
+
241
+ if ('action' in props && props.action !== undefined) {
242
+ return btoa(JSON.stringify(props.action));
243
+ }
244
+
245
+ return undefined;
246
+ }
247
+
248
+ static byBlockchain<T>(
249
+ blockchain: CoinflowBlockchain,
250
+ args: {solana: T; near: T; eth?: T; polygon: T; base: T}
251
+ ): T {
252
+ switch (blockchain) {
253
+ case 'solana':
254
+ return args.solana;
255
+ case 'near':
256
+ return args.near;
257
+ case 'polygon':
258
+ return args.polygon;
259
+ case 'eth':
260
+ if (args.eth === undefined)
261
+ throw new Error('blockchain not supported for this operation!');
262
+ return args.eth;
263
+ case 'base':
264
+ return args.base;
265
+ default:
266
+ throw new Error('blockchain not supported!');
267
+ }
268
+ }
269
+ }
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Public API Surface of coinflowlabs
3
+ */
4
+
1
5
  export * from './lib/coinflow-iframe.component';
2
6
  export * from './lib/coinflow-purchase.component';
3
7
  export * from './lib/coinflow-purchase-history.component';
@@ -0,0 +1,14 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "outDir": "../../out-tsc/lib",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "inlineSources": true,
9
+ "types": []
10
+ },
11
+ "exclude": [
12
+ "**/*.spec.ts"
13
+ ]
14
+ }
@@ -0,0 +1,10 @@
1
+ /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
+ {
3
+ "extends": "./tsconfig.lib.json",
4
+ "compilerOptions": {
5
+ "declarationMap": false
6
+ },
7
+ "angularCompilerOptions": {
8
+ "compilationMode": "partial"
9
+ }
10
+ }