@coinflowlabs/angular 0.0.4 → 0.0.5-sandbox2

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 (42) 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 +130 -0
  9. package/esm2022/lib/common/CoinflowTypes.mjs +13 -0
  10. package/esm2022/lib/common/CoinflowUtils.mjs +181 -0
  11. package/esm2022/lib/common/SolanaPeerDeps.mjs +9 -0
  12. package/esm2022/lib/common/index.mjs +4 -0
  13. package/esm2022/public-api.mjs +10 -0
  14. package/fesm2022/coinflowlabs-angular.mjs +504 -0
  15. package/fesm2022/coinflowlabs-angular.mjs.map +1 -0
  16. package/index.d.ts +5 -0
  17. package/lib/coinflow-iframe.component.d.ts +17 -0
  18. package/lib/coinflow-purchase-history.component.d.ts +5 -0
  19. package/lib/coinflow-purchase-protection.component.d.ts +5 -0
  20. package/lib/coinflow-purchase.component.d.ts +10 -0
  21. package/lib/coinflow-withdraw-history.component.d.ts +5 -0
  22. package/lib/coinflow-withdraw.component.d.ts +10 -0
  23. package/lib/common/CoinflowLibMessageHandlers.d.ts +21 -0
  24. package/lib/common/CoinflowTypes.d.ts +286 -0
  25. package/lib/common/CoinflowUtils.d.ts +21 -0
  26. package/lib/common/SolanaPeerDeps.d.ts +4 -0
  27. package/package.json +16 -8
  28. package/{src/public-api.ts → public-api.d.ts} +0 -4
  29. package/ng-package.json +0 -7
  30. package/src/lib/coinflow-iframe.component.ts +0 -63
  31. package/src/lib/coinflow-purchase-history.component.ts +0 -9
  32. package/src/lib/coinflow-purchase-protection.component.ts +0 -9
  33. package/src/lib/coinflow-purchase.component.ts +0 -37
  34. package/src/lib/coinflow-withdraw-history.component.ts +0 -9
  35. package/src/lib/coinflow-withdraw.component.ts +0 -36
  36. package/src/lib/common/CoinflowLibMessageHandlers.ts +0 -188
  37. package/src/lib/common/CoinflowTypes.ts +0 -403
  38. package/src/lib/common/CoinflowUtils.ts +0 -269
  39. package/tsconfig.lib.json +0 -14
  40. package/tsconfig.lib.prod.json +0 -10
  41. package/tsconfig.spec.json +0 -14
  42. /package/{src/lib/common/index.ts → lib/common/index.d.ts} +0 -0
@@ -0,0 +1,5 @@
1
+ import * as i0 from "@angular/core";
2
+ export declare class CoinflowPurchaseProtectionComponent {
3
+ static ɵfac: i0.ɵɵFactoryDeclaration<CoinflowPurchaseProtectionComponent, never>;
4
+ static ɵcmp: i0.ɵɵComponentDeclaration<CoinflowPurchaseProtectionComponent, "lib-coinflow-purchase-protection", never, {}, {}, never, never, true, never>;
5
+ }
@@ -0,0 +1,10 @@
1
+ import { CoinflowIFrameProps, CoinflowPurchaseProps, IFrameMessageHandlers } from './common';
2
+ import * as i0 from "@angular/core";
3
+ export declare class CoinflowPurchaseComponent {
4
+ purchaseProps: CoinflowPurchaseProps;
5
+ iframeProps?: CoinflowIFrameProps;
6
+ messageHandlers?: IFrameMessageHandlers;
7
+ ngOnInit(): void;
8
+ static ɵfac: i0.ɵɵFactoryDeclaration<CoinflowPurchaseComponent, never>;
9
+ static ɵcmp: i0.ɵɵComponentDeclaration<CoinflowPurchaseComponent, "lib-coinflow-purchase", never, { "purchaseProps": { "alias": "purchaseProps"; "required": false; }; }, {}, never, never, true, never>;
10
+ }
@@ -0,0 +1,5 @@
1
+ import * as i0 from "@angular/core";
2
+ export declare class CoinflowWithdrawHistoryComponent {
3
+ static ɵfac: i0.ɵɵFactoryDeclaration<CoinflowWithdrawHistoryComponent, never>;
4
+ static ɵcmp: i0.ɵɵComponentDeclaration<CoinflowWithdrawHistoryComponent, "lib-coinflow-withdraw-history", never, {}, {}, never, never, true, never>;
5
+ }
@@ -0,0 +1,10 @@
1
+ import { CoinflowIFrameProps, CoinflowWithdrawProps, IFrameMessageHandlers } from './common';
2
+ import * as i0 from "@angular/core";
3
+ export declare class CoinflowWithdrawComponent {
4
+ withdrawProps: CoinflowWithdrawProps;
5
+ iframeProps?: CoinflowIFrameProps;
6
+ messageHandlers?: IFrameMessageHandlers;
7
+ ngOnInit(): void;
8
+ static ɵfac: i0.ɵɵFactoryDeclaration<CoinflowWithdrawComponent, never>;
9
+ static ɵcmp: i0.ɵɵComponentDeclaration<CoinflowWithdrawComponent, "lib-coinflow-withdraw", never, { "withdrawProps": { "alias": "withdrawProps"; "required": false; }; }, {}, never, never, true, never>;
10
+ }
@@ -0,0 +1,21 @@
1
+ import { CoinflowPurchaseProps } from './CoinflowTypes';
2
+ export type WalletCall = {
3
+ method: IFrameMessageMethods;
4
+ data: string;
5
+ };
6
+ export interface IFrameMessageHandlers {
7
+ handleSendTransaction: (transaction: string) => Promise<string>;
8
+ handleSignMessage?: (message: string) => Promise<string>;
9
+ handleSignTransaction?: (transaction: string) => Promise<string>;
10
+ handleHeightChange?: (height: string) => void;
11
+ }
12
+ declare enum IFrameMessageMethods {
13
+ SignMessage = "signMessage",
14
+ SignTransaction = "signTransaction",
15
+ SendTransaction = "sendTransaction",
16
+ HeightChange = "heightChange"
17
+ }
18
+ export declare function getWalletPubkey({ wallet, }: Pick<CoinflowPurchaseProps, 'wallet'>): string | null | undefined;
19
+ export declare function handleIFrameMessage(rawMessage: string, handlers: IFrameMessageHandlers): Promise<string> | void;
20
+ export declare function getHandlers({ wallet, blockchain, }: Pick<CoinflowPurchaseProps, 'wallet' | 'blockchain'>): Omit<IFrameMessageHandlers, 'handleHeightChange'>;
21
+ export {};
@@ -0,0 +1,286 @@
1
+ import type { Connection, VersionedTransaction, PublicKey, Signer, Transaction } from '@solana/web3.js';
2
+ export declare enum SettlementType {
3
+ Credits = "Credits",
4
+ USDC = "USDC",
5
+ Bank = "Bank"
6
+ }
7
+ export declare enum MerchantStyle {
8
+ Rounded = "rounded",
9
+ Sharp = "sharp",
10
+ Pill = "pill"
11
+ }
12
+ export type MerchantTheme = {
13
+ primary?: string;
14
+ background?: string;
15
+ backgroundAccent?: string;
16
+ backgroundAccent2?: string;
17
+ textColor?: string;
18
+ textColorAccent?: string;
19
+ textColorAction?: string;
20
+ font?: string;
21
+ style?: MerchantStyle;
22
+ };
23
+ export interface CustomerInfo {
24
+ name?: string;
25
+ verificationId?: string;
26
+ displayName?: string;
27
+ address?: string;
28
+ city?: string;
29
+ state?: string;
30
+ zip?: string;
31
+ country?: string;
32
+ ip?: string;
33
+ lat?: string;
34
+ lng?: string;
35
+ }
36
+ /** Coinflow Types **/
37
+ export type CoinflowBlockchain = 'solana' | 'near' | 'eth' | 'polygon' | 'base';
38
+ export type CoinflowEnvs = 'prod' | 'staging' | 'sandbox' | 'local';
39
+ export interface CoinflowTypes {
40
+ merchantId: string;
41
+ env?: CoinflowEnvs;
42
+ loaderBackground?: string;
43
+ blockchain: CoinflowBlockchain;
44
+ handleHeightChange?: (height: string) => void;
45
+ theme?: MerchantTheme;
46
+ }
47
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
48
+ export type OnSuccessMethod = (params: string) => void | Promise<void>;
49
+ /** Wallets **/
50
+ export interface SolanaWallet {
51
+ publicKey: PublicKey | null;
52
+ signTransaction?: <T extends Transaction | VersionedTransaction>(transaction: T) => Promise<T>;
53
+ sendTransaction: <T extends Transaction | VersionedTransaction>(transaction: T) => Promise<string>;
54
+ signMessage?: (message: Uint8Array) => Promise<Uint8Array>;
55
+ }
56
+ export interface NearWallet {
57
+ accountId: string;
58
+ signAndSendTransaction: (transaction: unknown) => Promise<{
59
+ transaction: {
60
+ hash: string;
61
+ };
62
+ }>;
63
+ }
64
+ type AccessList = Array<{
65
+ address: string;
66
+ storageKeys: Array<string>;
67
+ }>;
68
+ type AccessListish = AccessList | Array<[string, Array<string>]> | Record<string, Array<string>>;
69
+ export type EthWallet = {
70
+ address: string | null | undefined;
71
+ sendTransaction: (transaction: {
72
+ to: string;
73
+ from?: string;
74
+ nonce?: Bytes | bigint | string | number;
75
+ gasLimit?: Bytes | bigint | string | number;
76
+ gasPrice?: Bytes | bigint | string | number;
77
+ data?: BytesLike;
78
+ value?: Bytes | bigint | string | number;
79
+ chainId?: number;
80
+ type?: number;
81
+ accessList?: AccessListish;
82
+ maxPriorityFeePerGas?: Bytes | bigint | string | number;
83
+ maxFeePerGas?: Bytes | bigint | string | number;
84
+ customData?: Record<string, any>;
85
+ ccipReadEnabled?: boolean;
86
+ }) => Promise<{
87
+ hash: string;
88
+ }>;
89
+ signMessage: (message: string) => Promise<string>;
90
+ };
91
+ /** History **/
92
+ export interface CoinflowSolanaHistoryProps extends CoinflowTypes {
93
+ wallet: SolanaWallet;
94
+ connection: Connection;
95
+ blockchain: 'solana';
96
+ }
97
+ export interface CoinflowNearHistoryProps extends CoinflowTypes {
98
+ wallet: NearWallet;
99
+ blockchain: 'near';
100
+ }
101
+ export interface CoinflowEvmHistoryProps extends CoinflowTypes {
102
+ wallet: EthWallet;
103
+ }
104
+ export interface CoinflowEthHistoryProps extends CoinflowEvmHistoryProps {
105
+ blockchain: 'eth';
106
+ }
107
+ export interface CoinflowPolygonHistoryProps extends CoinflowEvmHistoryProps {
108
+ blockchain: 'polygon';
109
+ }
110
+ export interface CoinflowBaseHistoryProps extends CoinflowEvmHistoryProps {
111
+ blockchain: 'base';
112
+ }
113
+ export type CoinflowHistoryProps = CoinflowSolanaHistoryProps | CoinflowNearHistoryProps | CoinflowPolygonHistoryProps | CoinflowEthHistoryProps | CoinflowBaseHistoryProps;
114
+ /** Transactions **/
115
+ export type NearFtTransferCallAction = {
116
+ methodName: 'ft_transfer_call';
117
+ args: object;
118
+ gas: string;
119
+ deposit: string;
120
+ };
121
+ type Bytes = ArrayLike<number>;
122
+ type BytesLike = Bytes | string;
123
+ /** Purchase **/
124
+ export type ChargebackProtectionData = ChargebackProtectionItem[];
125
+ export interface ChargebackProtectionItem {
126
+ /**
127
+ * The name of the product
128
+ */
129
+ productName: string;
130
+ /**
131
+ * 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
132
+ */
133
+ productType: 'inGameProduct' | 'gameOfSkill' | 'dataStorage' | 'computingResources' | 'sportsTicket' | 'eSportsTicket' | 'musicTicket' | 'conferenceTicket' | 'virtualSportsTicket' | 'virtualESportsTicket' | 'virtualMusicTicket' | 'virtualConferenceTicket' | 'alcohol' | 'DLC' | 'subscription' | 'fundACause' | 'realEstate' | 'computingContract' | 'digitalArt' | 'topUp' | 'ownershipContract';
134
+ /**
135
+ * The item's list price
136
+ */
137
+ /**
138
+ * The number of units sold
139
+ */
140
+ quantity: number;
141
+ /**
142
+ * Any additional data that the store can provide on the product, e.g. description, link to image, etc.
143
+ */
144
+ rawProductData?: {
145
+ [key: string]: any;
146
+ };
147
+ }
148
+ export interface CoinflowCommonPurchaseProps extends CoinflowTypes {
149
+ amount?: number;
150
+ onSuccess?: OnSuccessMethod;
151
+ webhookInfo?: object;
152
+ email?: string;
153
+ chargebackProtectionData?: ChargebackProtectionData;
154
+ planCode?: string;
155
+ disableApplePay?: boolean;
156
+ disableGooglePay?: boolean;
157
+ customerInfo?: CustomerInfo;
158
+ settlementType?: SettlementType;
159
+ authOnly?: boolean;
160
+ deviceId?: string;
161
+ }
162
+ export interface CoinflowSolanaPurchaseProps extends CoinflowCommonPurchaseProps {
163
+ wallet: SolanaWallet;
164
+ transaction?: Transaction | VersionedTransaction;
165
+ partialSigners?: Signer[];
166
+ debugTx?: boolean;
167
+ connection: Connection;
168
+ blockchain: 'solana';
169
+ token?: PublicKey | string;
170
+ supportsVersionedTransactions?: boolean;
171
+ rent?: {
172
+ lamports: string | number;
173
+ };
174
+ nativeSolToConvert?: {
175
+ lamports: string | number;
176
+ };
177
+ }
178
+ export interface CoinflowNearPurchaseProps extends CoinflowCommonPurchaseProps {
179
+ wallet: NearWallet;
180
+ blockchain: 'near';
181
+ action?: NearFtTransferCallAction;
182
+ nearDeposit?: string;
183
+ }
184
+ export interface CoinflowEvmPurchaseProps extends CoinflowCommonPurchaseProps {
185
+ transaction?: EvmTransactionData;
186
+ token?: string;
187
+ wallet: EthWallet;
188
+ }
189
+ export interface CoinflowPolygonPurchaseProps extends CoinflowEvmPurchaseProps {
190
+ blockchain: 'polygon';
191
+ }
192
+ export interface CoinflowEthPurchaseProps extends CoinflowEvmPurchaseProps {
193
+ blockchain: 'eth';
194
+ }
195
+ export interface CoinflowBasePurchaseProps extends CoinflowEvmPurchaseProps {
196
+ blockchain: 'base';
197
+ }
198
+ export type CoinflowPurchaseProps = CoinflowSolanaPurchaseProps | CoinflowNearPurchaseProps | CoinflowPolygonPurchaseProps | CoinflowEthPurchaseProps | CoinflowBasePurchaseProps;
199
+ /** Withdraw **/
200
+ export interface CoinflowCommonWithdrawProps extends CoinflowTypes {
201
+ onSuccess?: OnSuccessMethod;
202
+ tokens?: string[];
203
+ lockDefaultToken?: boolean;
204
+ amount?: number;
205
+ email?: string;
206
+ bankAccountLinkRedirect?: string;
207
+ additionalWallets?: {
208
+ wallet: string;
209
+ blockchain: 'solana' | 'eth' | 'near' | 'polygon';
210
+ }[];
211
+ supportsVersionedTransactions?: boolean;
212
+ lockAmount?: boolean;
213
+ transactionSigner?: string;
214
+ }
215
+ export interface CoinflowSolanaWithdrawProps extends CoinflowCommonWithdrawProps {
216
+ wallet: SolanaWallet;
217
+ connection: Connection;
218
+ blockchain: 'solana';
219
+ }
220
+ export interface CoinflowNearWithdrawProps extends CoinflowCommonWithdrawProps {
221
+ wallet: NearWallet;
222
+ blockchain: 'near';
223
+ }
224
+ export interface CoinflowEvmWithdrawProps extends CoinflowCommonWithdrawProps {
225
+ wallet: EthWallet;
226
+ usePermit?: boolean;
227
+ }
228
+ export interface CoinflowEthWithdrawProps extends CoinflowEvmWithdrawProps {
229
+ blockchain: 'eth';
230
+ usePermit?: boolean;
231
+ }
232
+ export interface CoinflowPolygonWithdrawProps extends CoinflowEvmWithdrawProps {
233
+ blockchain: 'polygon';
234
+ }
235
+ export interface CoinflowBaseWithdrawProps extends CoinflowEvmWithdrawProps {
236
+ blockchain: 'base';
237
+ }
238
+ export type CoinflowWithdrawProps = CoinflowSolanaWithdrawProps | CoinflowNearWithdrawProps | CoinflowEthWithdrawProps | CoinflowPolygonWithdrawProps | CoinflowBaseWithdrawProps;
239
+ export interface CommonEvmRedeem {
240
+ waitForHash?: boolean;
241
+ }
242
+ export interface NormalRedeem extends CommonEvmRedeem {
243
+ transaction: {
244
+ to: string;
245
+ data: string;
246
+ };
247
+ }
248
+ export interface KnownTokenIdRedeem extends NormalRedeem {
249
+ nftContract: string;
250
+ nftId: string;
251
+ }
252
+ export interface SafeMintRedeem extends NormalRedeem {
253
+ type: 'safeMint';
254
+ nftContract?: string;
255
+ }
256
+ export interface ReturnedTokenIdRedeem extends NormalRedeem {
257
+ type: 'returned';
258
+ nftContract?: string;
259
+ }
260
+ type ReservoirNftIdItem = Omit<KnownTokenIdRedeem, keyof NormalRedeem>;
261
+ interface ReservoirOrderIdItem {
262
+ orderId: string;
263
+ }
264
+ type ReservoirItem = ReservoirNftIdItem | ReservoirOrderIdItem;
265
+ type ReservoirItems = ReservoirItem | ReservoirItem[];
266
+ export interface ReservoirRedeem extends CommonEvmRedeem {
267
+ type: 'reservoir';
268
+ items: ReservoirItems;
269
+ }
270
+ export type EvmTransactionData = SafeMintRedeem | ReturnedTokenIdRedeem | ReservoirRedeem | KnownTokenIdRedeem | NormalRedeem;
271
+ export interface CoinflowIFrameProps extends Omit<CoinflowTypes, 'merchantId'>, Pick<CoinflowCommonPurchaseProps, 'chargebackProtectionData' | 'webhookInfo' | 'amount' | 'customerInfo' | 'settlementType' | 'email' | 'planCode' | 'deviceId'>, Pick<CoinflowCommonWithdrawProps, 'bankAccountLinkRedirect' | 'additionalWallets' | 'transactionSigner' | 'lockAmount' | 'lockDefaultToken'>, Pick<CoinflowEvmPurchaseProps, 'authOnly'>, Pick<CoinflowSolanaPurchaseProps, 'rent' | 'nativeSolToConvert' | 'token'> {
272
+ walletPubkey: string | null | undefined;
273
+ route: string;
274
+ routePrefix?: string;
275
+ transaction?: string;
276
+ tokens?: string[] | PublicKey[];
277
+ supportsVersionedTransactions?: boolean;
278
+ nearDeposit?: string;
279
+ merchantCss?: string;
280
+ color?: 'white' | 'black';
281
+ disableApplePay?: boolean;
282
+ disableGooglePay?: boolean;
283
+ theme?: MerchantTheme;
284
+ usePermit?: boolean;
285
+ }
286
+ export {};
@@ -0,0 +1,21 @@
1
+ import { CoinflowBlockchain, CoinflowEnvs, CoinflowIFrameProps, CoinflowPurchaseProps } from './CoinflowTypes';
2
+ export declare class CoinflowUtils {
3
+ env: CoinflowEnvs;
4
+ url: string;
5
+ constructor(env?: CoinflowEnvs);
6
+ getNSurePartnerId(merchantId: string): Promise<string | undefined>;
7
+ getCreditBalance(publicKey: string, merchantId: string, blockchain: 'solana' | 'near'): Promise<{
8
+ cents: number;
9
+ }>;
10
+ static getCoinflowBaseUrl(env?: CoinflowEnvs): string;
11
+ static getCoinflowApiUrl(env?: CoinflowEnvs): string;
12
+ static getCoinflowUrl({ walletPubkey, route, routePrefix, env, amount, transaction, blockchain, supportsVersionedTransactions, webhookInfo, email, loaderBackground, handleHeightChange, bankAccountLinkRedirect, additionalWallets, nearDeposit, chargebackProtectionData, merchantCss, color, rent, lockDefaultToken, token, tokens, planCode, disableApplePay, disableGooglePay, customerInfo, settlementType, lockAmount, nativeSolToConvert, theme, usePermit, transactionSigner, authOnly, deviceId, }: CoinflowIFrameProps): string;
13
+ static getTransaction(props: CoinflowPurchaseProps): string | undefined;
14
+ static byBlockchain<T>(blockchain: CoinflowBlockchain, args: {
15
+ solana: T;
16
+ near: T;
17
+ eth?: T;
18
+ polygon: T;
19
+ base: T;
20
+ }): T;
21
+ }
@@ -0,0 +1,4 @@
1
+ /// <reference types="@solana/web3.js" />
2
+ declare let web3: typeof import('@solana/web3.js') | undefined;
3
+ declare let base58: typeof import('bs58') | undefined;
4
+ export { web3, base58 };
package/package.json CHANGED
@@ -1,11 +1,6 @@
1
1
  {
2
2
  "name": "@coinflowlabs/angular",
3
- "version": "0.0.4",
4
- "scripts": {
5
- "clean": "rimraf ../../dist && rimraf ./src/lib/common",
6
- "build": "npm run codegen && ng build coinflowlabs",
7
- "codegen": "cp -r ../../../lib-common/src/ ./src/lib/common/"
8
- },
3
+ "version": "0.0.5-sandbox2",
9
4
  "peerDependencies": {
10
5
  "@angular/common": "^17.3.0",
11
6
  "@angular/core": "^17.3.0",
@@ -27,5 +22,18 @@
27
22
  "optional": true
28
23
  }
29
24
  },
30
- "sideEffects": false
31
- }
25
+ "sideEffects": false,
26
+ "module": "fesm2022/coinflowlabs-angular.mjs",
27
+ "typings": "index.d.ts",
28
+ "exports": {
29
+ "./package.json": {
30
+ "default": "./package.json"
31
+ },
32
+ ".": {
33
+ "types": "./index.d.ts",
34
+ "esm2022": "./esm2022/coinflowlabs-angular.mjs",
35
+ "esm": "./esm2022/coinflowlabs-angular.mjs",
36
+ "default": "./fesm2022/coinflowlabs-angular.mjs"
37
+ }
38
+ }
39
+ }
@@ -1,7 +1,3 @@
1
- /*
2
- * Public API Surface of coinflowlabs
3
- */
4
-
5
1
  export * from './lib/coinflow-iframe.component';
6
2
  export * from './lib/coinflow-purchase.component';
7
3
  export * from './lib/coinflow-purchase-history.component';
package/ng-package.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
- "dest": "../../dist/coinflowlabs",
4
- "lib": {
5
- "entryFile": "src/public-api.ts"
6
- }
7
- }
@@ -1,63 +0,0 @@
1
- import {
2
- Component,
3
- ElementRef,
4
- HostListener,
5
- Input,
6
- ViewChild,
7
- } from '@angular/core';
8
- import {
9
- CoinflowIFrameProps,
10
- CoinflowUtils,
11
- IFrameMessageHandlers,
12
- handleIFrameMessage,
13
- } from './common';
14
- import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';
15
-
16
- @Component({
17
- selector: 'lib-coinflow-iframe',
18
- standalone: true,
19
- imports: [],
20
- template: ` <iframe
21
- width="100%"
22
- height="100%"
23
- #iframe
24
- scrolling="{{ iframeProps?.handleHeightChange ? 'no' : 'yes' }}"
25
- allow="payment;camera"
26
- title="withdraw"
27
- frameBorder="0"
28
- [src]="dynamicUrl"
29
- ></iframe>`,
30
- })
31
- export class CoinflowIFrameComponent {
32
- @Input() iframeProps!: CoinflowIFrameProps;
33
- @Input() messageHandlers!: IFrameMessageHandlers;
34
-
35
- dynamicUrl?: SafeResourceUrl;
36
- @ViewChild('iframe') iframe?: ElementRef<HTMLIFrameElement>;
37
-
38
- constructor(private sanitizer: DomSanitizer) {}
39
-
40
- ngOnInit() {
41
- const coinflowUrl = CoinflowUtils.getCoinflowUrl(this.iframeProps);
42
- this.dynamicUrl =
43
- this.sanitizer.bypassSecurityTrustResourceUrl(coinflowUrl);
44
- }
45
-
46
- @HostListener('window:message', ['$event']) onPostMessage(event: any) {
47
- if (
48
- !event.origin.includes(
49
- CoinflowUtils.getCoinflowBaseUrl(this.iframeProps.env)
50
- )
51
- )
52
- return;
53
-
54
- const promise = handleIFrameMessage(event.data, this.messageHandlers);
55
- if (!promise) return;
56
- promise.then(this.sendMessage.bind(this));
57
- }
58
-
59
- sendMessage(message: string) {
60
- if (!this.iframe || !this.iframe.nativeElement) return;
61
- this.iframe.nativeElement.contentWindow!.postMessage(message, '*');
62
- }
63
- }
@@ -1,9 +0,0 @@
1
- import {Component} from '@angular/core';
2
-
3
- @Component({
4
- selector: 'lib-coinflow-purchase-history',
5
- standalone: true,
6
- imports: [],
7
- template: ' <p>coinflow-purchase-history works!</p> ',
8
- })
9
- export class CoinflowPurchaseHistoryComponent {}
@@ -1,9 +0,0 @@
1
- import {Component} from '@angular/core';
2
-
3
- @Component({
4
- selector: 'lib-coinflow-purchase-protection',
5
- standalone: true,
6
- imports: [],
7
- template: ' <p>coinflow-purchase-protection works!</p> ',
8
- })
9
- export class CoinflowPurchaseProtectionComponent {}
@@ -1,37 +0,0 @@
1
- import {Component, Input} from '@angular/core';
2
- import {CoinflowIFrameComponent} from './coinflow-iframe.component';
3
- import {
4
- CoinflowIFrameProps,
5
- CoinflowPurchaseProps,
6
- IFrameMessageHandlers,
7
- getHandlers,
8
- getWalletPubkey,
9
- CoinflowUtils,
10
- } from './common';
11
-
12
- @Component({
13
- selector: 'lib-coinflow-purchase',
14
- standalone: true,
15
- imports: [CoinflowIFrameComponent],
16
- template:
17
- ' <lib-coinflow-iframe ng-if="iframeProps && messageHandlers" [iframeProps]="iframeProps!" [messageHandlers]="messageHandlers!"></lib-coinflow-iframe> ',
18
- })
19
- export class CoinflowPurchaseComponent {
20
- @Input() purchaseProps!: CoinflowPurchaseProps;
21
- iframeProps?: CoinflowIFrameProps;
22
- messageHandlers?: IFrameMessageHandlers;
23
-
24
- ngOnInit() {
25
- const walletPubkey = getWalletPubkey(this.purchaseProps);
26
- this.messageHandlers = getHandlers(this.purchaseProps);
27
- this.messageHandlers.handleHeightChange =
28
- this.purchaseProps.handleHeightChange;
29
-
30
- this.iframeProps = {
31
- ...this.purchaseProps,
32
- walletPubkey,
33
- route: `/purchase/${this.purchaseProps?.merchantId}`,
34
- transaction: CoinflowUtils.getTransaction(this.purchaseProps),
35
- };
36
- }
37
- }
@@ -1,9 +0,0 @@
1
- import {Component} from '@angular/core';
2
-
3
- @Component({
4
- selector: 'lib-coinflow-withdraw-history',
5
- standalone: true,
6
- imports: [],
7
- template: ' <p>coinflow-withdraw-history works!</p> ',
8
- })
9
- export class CoinflowWithdrawHistoryComponent {}
@@ -1,36 +0,0 @@
1
- import {Component, Input} from '@angular/core';
2
- import {
3
- CoinflowIFrameProps,
4
- CoinflowWithdrawProps,
5
- IFrameMessageHandlers,
6
- getHandlers,
7
- getWalletPubkey,
8
- } from './common';
9
- import {CoinflowIFrameComponent} from './coinflow-iframe.component';
10
-
11
- @Component({
12
- selector: 'lib-coinflow-withdraw',
13
- standalone: true,
14
- imports: [CoinflowIFrameComponent],
15
- template:
16
- ' <lib-coinflow-iframe ng-if="iframeProps && messageHandlers" [iframeProps]="iframeProps!" [messageHandlers]="messageHandlers!"></lib-coinflow-iframe> ',
17
- })
18
- export class CoinflowWithdrawComponent {
19
- @Input() withdrawProps!: CoinflowWithdrawProps;
20
- iframeProps?: CoinflowIFrameProps;
21
- messageHandlers?: IFrameMessageHandlers;
22
-
23
- ngOnInit() {
24
- const walletPubkey = getWalletPubkey(this.withdrawProps);
25
- this.messageHandlers = getHandlers(this.withdrawProps);
26
- this.messageHandlers.handleHeightChange =
27
- this.withdrawProps.handleHeightChange;
28
-
29
- this.iframeProps = {
30
- ...this.withdrawProps,
31
- walletPubkey,
32
- route: `/withdraw/${this.withdrawProps?.merchantId}`,
33
- transaction: undefined,
34
- };
35
- }
36
- }