@coinflowlabs/angular 0.0.1 → 0.0.3

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 (41) hide show
  1. package/esm2022/coinflowlabs-angular.mjs +5 -0
  2. package/esm2022/lib/coinflow-iframe.component.mjs +67 -0
  3. package/esm2022/lib/coinflow-purchase-history.component.mjs +16 -0
  4. package/esm2022/lib/coinflow-purchase-protection.component.mjs +16 -0
  5. package/esm2022/lib/coinflow-purchase.component.mjs +32 -0
  6. package/esm2022/lib/coinflow-withdraw-history.component.mjs +16 -0
  7. package/esm2022/lib/coinflow-withdraw.component.mjs +32 -0
  8. package/esm2022/lib/common/CoinflowLibMessageHandlers.mjs +127 -0
  9. package/esm2022/lib/common/CoinflowTypes.mjs +13 -0
  10. package/esm2022/lib/common/CoinflowUtils.mjs +173 -0
  11. package/esm2022/lib/common/index.mjs +4 -0
  12. package/esm2022/public-api.mjs +10 -0
  13. package/fesm2022/coinflowlabs-angular.mjs +486 -0
  14. package/fesm2022/coinflowlabs-angular.mjs.map +1 -0
  15. package/index.d.ts +5 -0
  16. package/lib/coinflow-iframe.component.d.ts +17 -0
  17. package/lib/coinflow-purchase-history.component.d.ts +5 -0
  18. package/lib/coinflow-purchase-protection.component.d.ts +5 -0
  19. package/lib/coinflow-purchase.component.d.ts +10 -0
  20. package/lib/coinflow-withdraw-history.component.d.ts +5 -0
  21. package/lib/coinflow-withdraw.component.d.ts +10 -0
  22. package/lib/common/CoinflowLibMessageHandlers.d.ts +21 -0
  23. package/lib/common/CoinflowTypes.d.ts +287 -0
  24. package/lib/common/CoinflowUtils.d.ts +21 -0
  25. package/package.json +19 -8
  26. package/{src/public-api.ts → public-api.d.ts} +0 -4
  27. package/_update-notifier-last-checked +0 -0
  28. package/ng-package.json +0 -7
  29. package/src/lib/coinflow-iframe.component.ts +0 -63
  30. package/src/lib/coinflow-purchase-history.component.ts +0 -9
  31. package/src/lib/coinflow-purchase-protection.component.ts +0 -9
  32. package/src/lib/coinflow-purchase.component.ts +0 -37
  33. package/src/lib/coinflow-withdraw-history.component.ts +0 -9
  34. package/src/lib/coinflow-withdraw.component.ts +0 -36
  35. package/src/lib/common/CoinflowLibMessageHandlers.ts +0 -188
  36. package/src/lib/common/CoinflowTypes.ts +0 -398
  37. package/src/lib/common/CoinflowUtils.ts +0 -267
  38. package/tsconfig.lib.json +0 -14
  39. package/tsconfig.lib.prod.json +0 -10
  40. package/tsconfig.spec.json +0 -14
  41. /package/{src/lib/common/index.ts → lib/common/index.d.ts} +0 -0
@@ -1,267 +0,0 @@
1
- import {
2
- CoinflowBlockchain,
3
- CoinflowEnvs,
4
- CoinflowIFrameProps,
5
- CoinflowPurchaseProps,
6
- } from './CoinflowTypes';
7
- import {Transaction, VersionedTransaction} from '@solana/web3.js';
8
- import 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) {
222
- const {transaction} = props;
223
- if (transaction instanceof Transaction) {
224
- return base58.encode(
225
- transaction.serialize({
226
- requireAllSignatures: false,
227
- verifySignatures: false,
228
- })
229
- );
230
- }
231
-
232
- if (transaction instanceof VersionedTransaction) {
233
- return base58.encode(transaction.serialize());
234
- }
235
-
236
- return btoa(JSON.stringify(transaction));
237
- }
238
-
239
- if ('action' in props) {
240
- return btoa(JSON.stringify(props.action));
241
- }
242
-
243
- return undefined;
244
- }
245
-
246
- static byBlockchain<T>(
247
- blockchain: CoinflowBlockchain,
248
- args: {solana: T; near: T; eth?: T; polygon: T; base: T}
249
- ): T {
250
- switch (blockchain) {
251
- case 'solana':
252
- return args.solana;
253
- case 'near':
254
- return args.near;
255
- case 'polygon':
256
- return args.polygon;
257
- case 'eth':
258
- if (args.eth === undefined)
259
- throw new Error('blockchain not supported for this operation!');
260
- return args.eth;
261
- case 'base':
262
- return args.base;
263
- default:
264
- throw new Error('blockchain not supported!');
265
- }
266
- }
267
- }
package/tsconfig.lib.json DELETED
@@ -1,14 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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
- }
@@ -1,14 +0,0 @@
1
- /* To learn more about this file see: https://angular.io/config/tsconfig. */
2
- {
3
- "extends": "../../tsconfig.json",
4
- "compilerOptions": {
5
- "outDir": "../../out-tsc/spec",
6
- "types": [
7
- "jasmine"
8
- ]
9
- },
10
- "include": [
11
- "**/*.spec.ts",
12
- "**/*.d.ts"
13
- ]
14
- }