@coinflowlabs/react 4.0.0 → 4.1.1

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 (131) hide show
  1. package/README.md +7 -0
  2. package/build/cjs/CoinflowApplePayButton.d.ts +3 -5
  3. package/build/cjs/CoinflowApplePayButton.js +42 -37
  4. package/build/cjs/CoinflowApplePayButton.js.map +1 -1
  5. package/build/cjs/CoinflowCardForm.d.ts +2 -2
  6. package/build/cjs/CoinflowCardForm.js +35 -38
  7. package/build/cjs/CoinflowCardForm.js.map +1 -1
  8. package/build/cjs/CoinflowGooglePayButton.d.ts +1 -1
  9. package/build/cjs/CoinflowIFrame.d.ts +7 -2
  10. package/build/cjs/CoinflowIFrame.js +65 -6
  11. package/build/cjs/CoinflowIFrame.js.map +1 -1
  12. package/build/cjs/CoinflowPurchase.d.ts +2 -3
  13. package/build/cjs/CoinflowPurchase.js +11 -66
  14. package/build/cjs/CoinflowPurchase.js.map +1 -1
  15. package/build/cjs/CoinflowPurchaseHistory.d.ts +2 -2
  16. package/build/cjs/CoinflowPurchaseHistory.js +10 -41
  17. package/build/cjs/CoinflowPurchaseHistory.js.map +1 -1
  18. package/build/cjs/CoinflowPurchaseProtection.d.ts +1 -1
  19. package/build/cjs/CoinflowPurchaseProtection.js +2 -2
  20. package/build/cjs/CoinflowPurchaseProtection.js.map +1 -1
  21. package/build/cjs/CoinflowWithdraw.d.ts +3 -3
  22. package/build/cjs/CoinflowWithdraw.js +11 -44
  23. package/build/cjs/CoinflowWithdraw.js.map +1 -1
  24. package/build/cjs/CoinflowWithdrawHistory.d.ts +3 -3
  25. package/build/cjs/CoinflowWithdrawHistory.js +10 -42
  26. package/build/cjs/CoinflowWithdrawHistory.js.map +1 -1
  27. package/build/cjs/common/CoinflowLibMessageHandlers.d.ts +21 -0
  28. package/build/cjs/common/CoinflowLibMessageHandlers.js +186 -0
  29. package/build/cjs/common/CoinflowLibMessageHandlers.js.map +1 -0
  30. package/build/cjs/{CoinflowTypes.d.ts → common/CoinflowTypes.d.ts} +56 -47
  31. package/build/cjs/{CoinflowTypes.js → common/CoinflowTypes.js} +3 -2
  32. package/build/cjs/common/CoinflowTypes.js.map +1 -0
  33. package/build/cjs/common/CoinflowUtils.d.ts +21 -0
  34. package/build/cjs/{CoinflowUtils.js → common/CoinflowUtils.js} +43 -22
  35. package/build/cjs/common/CoinflowUtils.js.map +1 -0
  36. package/build/cjs/common/SolanaPeerDeps.d.ts +5 -0
  37. package/build/cjs/common/SolanaPeerDeps.js +22 -0
  38. package/build/cjs/common/SolanaPeerDeps.js.map +1 -0
  39. package/build/cjs/common/index.d.ts +3 -0
  40. package/build/cjs/common/index.js +7 -0
  41. package/build/cjs/common/index.js.map +1 -0
  42. package/build/cjs/index.d.ts +1 -3
  43. package/build/cjs/index.js +1 -3
  44. package/build/cjs/index.js.map +1 -1
  45. package/build/esm/CoinflowApplePayButton.d.ts +3 -5
  46. package/build/esm/CoinflowApplePayButton.js +42 -35
  47. package/build/esm/CoinflowApplePayButton.js.map +1 -1
  48. package/build/esm/CoinflowCardForm.d.ts +2 -2
  49. package/build/esm/CoinflowCardForm.js +37 -40
  50. package/build/esm/CoinflowCardForm.js.map +1 -1
  51. package/build/esm/CoinflowGooglePayButton.d.ts +1 -1
  52. package/build/esm/CoinflowIFrame.d.ts +7 -2
  53. package/build/esm/CoinflowIFrame.js +66 -5
  54. package/build/esm/CoinflowIFrame.js.map +1 -1
  55. package/build/esm/CoinflowPurchase.d.ts +2 -3
  56. package/build/esm/CoinflowPurchase.js +10 -64
  57. package/build/esm/CoinflowPurchase.js.map +1 -1
  58. package/build/esm/CoinflowPurchaseHistory.d.ts +2 -2
  59. package/build/esm/CoinflowPurchaseHistory.js +10 -41
  60. package/build/esm/CoinflowPurchaseHistory.js.map +1 -1
  61. package/build/esm/CoinflowPurchaseProtection.d.ts +1 -1
  62. package/build/esm/CoinflowPurchaseProtection.js +1 -1
  63. package/build/esm/CoinflowPurchaseProtection.js.map +1 -1
  64. package/build/esm/CoinflowWithdraw.d.ts +3 -3
  65. package/build/esm/CoinflowWithdraw.js +11 -44
  66. package/build/esm/CoinflowWithdraw.js.map +1 -1
  67. package/build/esm/CoinflowWithdrawHistory.d.ts +3 -3
  68. package/build/esm/CoinflowWithdrawHistory.js +10 -42
  69. package/build/esm/CoinflowWithdrawHistory.js.map +1 -1
  70. package/build/esm/common/CoinflowLibMessageHandlers.d.ts +21 -0
  71. package/build/esm/common/CoinflowLibMessageHandlers.js +180 -0
  72. package/build/esm/common/CoinflowLibMessageHandlers.js.map +1 -0
  73. package/build/esm/{CoinflowTypes.d.ts → common/CoinflowTypes.d.ts} +56 -47
  74. package/build/esm/{CoinflowTypes.js → common/CoinflowTypes.js} +2 -3
  75. package/build/esm/common/CoinflowTypes.js.map +1 -0
  76. package/build/esm/common/CoinflowUtils.d.ts +21 -0
  77. package/build/esm/{CoinflowUtils.js → common/CoinflowUtils.js} +43 -22
  78. package/build/esm/common/CoinflowUtils.js.map +1 -0
  79. package/build/esm/common/SolanaPeerDeps.d.ts +5 -0
  80. package/build/esm/common/SolanaPeerDeps.js +17 -0
  81. package/build/esm/common/SolanaPeerDeps.js.map +1 -0
  82. package/build/esm/common/index.d.ts +3 -0
  83. package/build/esm/common/index.js +4 -0
  84. package/build/esm/common/index.js.map +1 -0
  85. package/build/esm/index.d.ts +1 -3
  86. package/build/esm/index.js +1 -3
  87. package/build/esm/index.js.map +1 -1
  88. package/build/tsconfig.tsbuildinfo +1 -1
  89. package/package.json +16 -10
  90. package/build/cjs/CoinflowTypes.js.map +0 -1
  91. package/build/cjs/CoinflowUtils.d.ts +0 -21
  92. package/build/cjs/CoinflowUtils.js.map +0 -1
  93. package/build/cjs/useHandleHeightChange.d.ts +0 -2
  94. package/build/cjs/useHandleHeightChange.js +0 -24
  95. package/build/cjs/useHandleHeightChange.js.map +0 -1
  96. package/build/cjs/wallet/EthIFrameMessageHandlers.d.ts +0 -5
  97. package/build/cjs/wallet/EthIFrameMessageHandlers.js +0 -42
  98. package/build/cjs/wallet/EthIFrameMessageHandlers.js.map +0 -1
  99. package/build/cjs/wallet/NearIFrameMessageHandlers.d.ts +0 -5
  100. package/build/cjs/wallet/NearIFrameMessageHandlers.js +0 -31
  101. package/build/cjs/wallet/NearIFrameMessageHandlers.js.map +0 -1
  102. package/build/cjs/wallet/SocketService.d.ts +0 -5
  103. package/build/cjs/wallet/SocketService.js +0 -43
  104. package/build/cjs/wallet/SocketService.js.map +0 -1
  105. package/build/cjs/wallet/SolanaIFrameMessageHandlers.d.ts +0 -19
  106. package/build/cjs/wallet/SolanaIFrameMessageHandlers.js +0 -132
  107. package/build/cjs/wallet/SolanaIFrameMessageHandlers.js.map +0 -1
  108. package/build/cjs/wallet/useIframeWallet.d.ts +0 -15
  109. package/build/cjs/wallet/useIframeWallet.js +0 -137
  110. package/build/cjs/wallet/useIframeWallet.js.map +0 -1
  111. package/build/esm/CoinflowTypes.js.map +0 -1
  112. package/build/esm/CoinflowUtils.d.ts +0 -21
  113. package/build/esm/CoinflowUtils.js.map +0 -1
  114. package/build/esm/useHandleHeightChange.d.ts +0 -2
  115. package/build/esm/useHandleHeightChange.js +0 -19
  116. package/build/esm/useHandleHeightChange.js.map +0 -1
  117. package/build/esm/wallet/EthIFrameMessageHandlers.d.ts +0 -5
  118. package/build/esm/wallet/EthIFrameMessageHandlers.js +0 -38
  119. package/build/esm/wallet/EthIFrameMessageHandlers.js.map +0 -1
  120. package/build/esm/wallet/NearIFrameMessageHandlers.d.ts +0 -5
  121. package/build/esm/wallet/NearIFrameMessageHandlers.js +0 -27
  122. package/build/esm/wallet/NearIFrameMessageHandlers.js.map +0 -1
  123. package/build/esm/wallet/SocketService.d.ts +0 -5
  124. package/build/esm/wallet/SocketService.js +0 -35
  125. package/build/esm/wallet/SocketService.js.map +0 -1
  126. package/build/esm/wallet/SolanaIFrameMessageHandlers.d.ts +0 -19
  127. package/build/esm/wallet/SolanaIFrameMessageHandlers.js +0 -128
  128. package/build/esm/wallet/SolanaIFrameMessageHandlers.js.map +0 -1
  129. package/build/esm/wallet/useIframeWallet.d.ts +0 -15
  130. package/build/esm/wallet/useIframeWallet.js +0 -131
  131. package/build/esm/wallet/useIframeWallet.js.map +0 -1
@@ -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, jwtToken, }: 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
+ }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CoinflowUtils = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var bs58_1 = tslib_1.__importDefault(require("bs58"));
5
+ var SolanaPeerDeps_1 = require("./SolanaPeerDeps");
6
6
  var CoinflowUtils = /** @class */ (function () {
7
7
  function CoinflowUtils(env) {
8
8
  this.env = env !== null && env !== void 0 ? env : 'prod';
@@ -64,7 +64,7 @@ var CoinflowUtils = /** @class */ (function () {
64
64
  };
65
65
  CoinflowUtils.getCoinflowUrl = function (_a) {
66
66
  var _b;
67
- var walletPubkey = _a.walletPubkey, route = _a.route, routePrefix = _a.routePrefix, env = _a.env, amount = _a.amount, transaction = _a.transaction, blockchain = _a.blockchain, supportsVersionedTransactions = _a.supportsVersionedTransactions, webhookInfo = _a.webhookInfo, email = _a.email, loaderBackground = _a.loaderBackground, handleHeightChange = _a.handleHeightChange, useSocket = _a.useSocket, bankAccountLinkRedirect = _a.bankAccountLinkRedirect, additionalWallets = _a.additionalWallets, nearDeposit = _a.nearDeposit, chargebackProtectionData = _a.chargebackProtectionData, merchantCss = _a.merchantCss, color = _a.color, rent = _a.rent, lockDefaultToken = _a.lockDefaultToken, token = _a.token, tokens = _a.tokens, planCode = _a.planCode, disableApplePay = _a.disableApplePay, disableGooglePay = _a.disableGooglePay, customerInfo = _a.customerInfo, settlementType = _a.settlementType, lockAmount = _a.lockAmount, nativeSolToConvert = _a.nativeSolToConvert, theme = _a.theme, transactionSigner = _a.transactionSigner;
67
+ var walletPubkey = _a.walletPubkey, route = _a.route, routePrefix = _a.routePrefix, env = _a.env, amount = _a.amount, transaction = _a.transaction, blockchain = _a.blockchain, supportsVersionedTransactions = _a.supportsVersionedTransactions, webhookInfo = _a.webhookInfo, email = _a.email, loaderBackground = _a.loaderBackground, handleHeightChange = _a.handleHeightChange, bankAccountLinkRedirect = _a.bankAccountLinkRedirect, additionalWallets = _a.additionalWallets, nearDeposit = _a.nearDeposit, chargebackProtectionData = _a.chargebackProtectionData, merchantCss = _a.merchantCss, color = _a.color, rent = _a.rent, lockDefaultToken = _a.lockDefaultToken, token = _a.token, tokens = _a.tokens, planCode = _a.planCode, disableApplePay = _a.disableApplePay, disableGooglePay = _a.disableGooglePay, customerInfo = _a.customerInfo, settlementType = _a.settlementType, lockAmount = _a.lockAmount, nativeSolToConvert = _a.nativeSolToConvert, theme = _a.theme, usePermit = _a.usePermit, transactionSigner = _a.transactionSigner, authOnly = _a.authOnly, deviceId = _a.deviceId, jwtToken = _a.jwtToken;
68
68
  var prefix = routePrefix
69
69
  ? "/".concat(routePrefix, "/").concat(blockchain)
70
70
  : "/".concat(blockchain);
@@ -103,9 +103,6 @@ var CoinflowUtils = /** @class */ (function () {
103
103
  if (handleHeightChange) {
104
104
  url.searchParams.append('useHeightChange', 'true');
105
105
  }
106
- if (useSocket) {
107
- url.searchParams.append('useSocket', 'true');
108
- }
109
106
  if (bankAccountLinkRedirect) {
110
107
  url.searchParams.append('bankAccountLinkRedirect', bankAccountLinkRedirect);
111
108
  }
@@ -115,11 +112,17 @@ var CoinflowUtils = /** @class */ (function () {
115
112
  url.searchParams.append('nearDeposit', nearDeposit);
116
113
  if (chargebackProtectionData)
117
114
  url.searchParams.append('chargebackProtectionData', JSON.stringify(chargebackProtectionData));
118
- if (typeof window !== 'undefined') {
119
- // @ts-ignore
120
- var deviceId = (_b = window === null || window === void 0 ? void 0 : window.nSureSDK) === null || _b === void 0 ? void 0 : _b.getDeviceId();
121
- if (deviceId)
122
- url.searchParams.append('deviceId', deviceId);
115
+ if (deviceId) {
116
+ url.searchParams.append('deviceId', deviceId);
117
+ }
118
+ else {
119
+ if (typeof window !== 'undefined') {
120
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
121
+ // @ts-ignore
122
+ var deviceId_1 = (_b = window === null || window === void 0 ? void 0 : window.nSureSDK) === null || _b === void 0 ? void 0 : _b.getDeviceId();
123
+ if (deviceId_1)
124
+ url.searchParams.append('deviceId', deviceId_1);
125
+ }
123
126
  }
124
127
  if (merchantCss)
125
128
  url.searchParams.append('merchantCss', merchantCss);
@@ -141,22 +144,38 @@ var CoinflowUtils = /** @class */ (function () {
141
144
  url.searchParams.append('settlementType', settlementType);
142
145
  if (lockAmount)
143
146
  url.searchParams.append('lockAmount', 'true');
147
+ if (usePermit === false)
148
+ url.searchParams.append('usePermit', 'false');
144
149
  if (transactionSigner)
145
150
  url.searchParams.append('transactionSigner', transactionSigner);
151
+ if (authOnly === true)
152
+ url.searchParams.append('authOnly', 'true');
153
+ if (jwtToken)
154
+ url.searchParams.append('jwtToken', jwtToken);
146
155
  return url.toString();
147
156
  };
148
- CoinflowUtils.serializeSolanaTransaction = function (transaction) {
149
- if (!transaction)
150
- return undefined;
151
- var serializedTx = transaction.serialize({
152
- requireAllSignatures: false,
153
- verifySignatures: false,
154
- });
155
- return bs58_1.default.encode(serializedTx);
156
- };
157
- CoinflowUtils.solanaWalletSupportsVersionedTransactions = function (wallet) {
158
- var _a, _b, _c;
159
- return !!((_c = (_b = (_a = wallet.wallet) === null || _a === void 0 ? void 0 : _a.adapter) === null || _b === void 0 ? void 0 : _b.supportedTransactionVersions) === null || _c === void 0 ? void 0 : _c.has(0));
157
+ CoinflowUtils.getTransaction = function (props) {
158
+ if ('transaction' in props && props.transaction !== undefined) {
159
+ var transaction = props.transaction;
160
+ if (SolanaPeerDeps_1.web3 && transaction instanceof SolanaPeerDeps_1.web3.Transaction) {
161
+ if (!SolanaPeerDeps_1.base58)
162
+ throw new Error('bs58 dependency is required for Solana');
163
+ return SolanaPeerDeps_1.base58.encode(transaction.serialize({
164
+ requireAllSignatures: false,
165
+ verifySignatures: false,
166
+ }));
167
+ }
168
+ if (SolanaPeerDeps_1.web3 && transaction instanceof SolanaPeerDeps_1.web3.VersionedTransaction) {
169
+ if (!SolanaPeerDeps_1.base58)
170
+ throw new Error('bs58 dependency is required for Solana');
171
+ return SolanaPeerDeps_1.base58.encode(transaction.serialize());
172
+ }
173
+ return btoa(JSON.stringify(transaction));
174
+ }
175
+ if ('action' in props && props.action !== undefined) {
176
+ return btoa(JSON.stringify(props.action));
177
+ }
178
+ return undefined;
160
179
  };
161
180
  CoinflowUtils.byBlockchain = function (blockchain, args) {
162
181
  switch (blockchain) {
@@ -170,6 +189,8 @@ var CoinflowUtils = /** @class */ (function () {
170
189
  if (args.eth === undefined)
171
190
  throw new Error('blockchain not supported for this operation!');
172
191
  return args.eth;
192
+ case 'base':
193
+ return args.base;
173
194
  default:
174
195
  throw new Error('blockchain not supported!');
175
196
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoinflowUtils.js","sourceRoot":"","sources":["../../../src/common/CoinflowUtils.ts"],"names":[],"mappings":";;;;AAMA,mDAA8C;AAE9C;IAIE,uBAAY,GAAkB;QAC5B,IAAI,CAAC,GAAG,GAAG,GAAG,aAAH,GAAG,cAAH,GAAG,GAAI,MAAM,CAAC;QACzB,IAAI,IAAI,CAAC,GAAG,KAAK,MAAM;YAAE,IAAI,CAAC,GAAG,GAAG,2BAA2B,CAAC;aAC3D,IAAI,IAAI,CAAC,GAAG,KAAK,OAAO;YAAE,IAAI,CAAC,GAAG,GAAG,uBAAuB,CAAC;;YAC7D,IAAI,CAAC,GAAG,GAAG,sBAAe,IAAI,CAAC,GAAG,mBAAgB,CAAC;IAC1D,CAAC;IAEK,yCAAiB,GAAvB,UAAwB,UAAkB;;;gBACxC,sBAAO,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,yBAAkB,UAAU,CAAE,CAAC;yBACpD,IAAI,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,IAAI,EAAE,EAAf,CAAe,CAAC;yBACjC,IAAI,CACH,UAAC,IAGA,YAAK,OAAA,CAAA,MAAA,IAAI,CAAC,aAAa,0CAAE,cAAc,KAAI,IAAI,CAAC,cAAc,CAAA,EAAA,CAChE;yBACA,KAAK,CAAC,UAAA,CAAC;wBACN,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;wBACjB,OAAO,SAAS,CAAC;oBACnB,CAAC,CAAC,EAAC;;;KACN;IAEK,wCAAgB,GAAtB,UACE,SAAiB,EACjB,UAAkB,EAClB,UAA6B;;;;;4BAEZ,qBAAM,KAAK,CAC1B,IAAI,CAAC,GAAG,GAAG,iCAA0B,UAAU,CAAE,EACjD;4BACE,MAAM,EAAE,KAAK;4BACb,OAAO,EAAE;g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IAAI,CAAC,uBAAM;oBAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;gBACvE,OAAO,uBAAM,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC,CAAC;YAChD,CAAC;YAED,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;QAC3C,CAAC;QAED,IAAI,QAAQ,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACpD,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAEM,0BAAY,GAAnB,UACE,UAA8B,EAC9B,IAAwD;QAExD,QAAQ,UAAU,EAAE,CAAC;YACnB,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,MAAM,CAAC;YACrB,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,IAAI,CAAC;YACnB,KAAK,SAAS;gBACZ,OAAO,IAAI,CAAC,OAAO,CAAC;YACtB,KAAK,KAAK;gBACR,IAAI,IAAI,CAAC,GAAG,KAAK,SAAS;oBACxB,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;gBAClE,OAAO,IAAI,CAAC,GAAG,CAAC;YAClB,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,IAAI,CAAC;YACnB;gBACE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AArQD,IAqQC;AArQY,sCAAa"}
@@ -0,0 +1,5 @@
1
+ import * as SolanaWeb3Js from '@solana/web3.js';
2
+ import base58Imported from 'bs58';
3
+ declare const web3: typeof SolanaWeb3Js | undefined;
4
+ declare const base58: typeof base58Imported | undefined;
5
+ export { web3, base58 };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ // This works in angular, but not react
3
+ // let web3: typeof import('@solana/web3.js') | undefined;
4
+ // let base58: typeof import('bs58') | undefined;
5
+ //
6
+ // try {
7
+ // web3 = require('@solana/web3.js');
8
+ // base58 = require('bs58');
9
+ // } catch (e) {}
10
+ //
11
+ // export {web3, base58};
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.base58 = exports.web3 = void 0;
14
+ var tslib_1 = require("tslib");
15
+ // This works in react, but not angular
16
+ var SolanaWeb3Js = tslib_1.__importStar(require("@solana/web3.js"));
17
+ var bs58_1 = tslib_1.__importDefault(require("bs58"));
18
+ var web3 = SolanaWeb3Js;
19
+ exports.web3 = web3;
20
+ var base58 = bs58_1.default;
21
+ exports.base58 = base58;
22
+ //# sourceMappingURL=SolanaPeerDeps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SolanaPeerDeps.js","sourceRoot":"","sources":["../../../src/common/SolanaPeerDeps.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,0DAA0D;AAC1D,iDAAiD;AACjD,EAAE;AACF,QAAQ;AACR,uCAAuC;AACvC,8BAA8B;AAC9B,iBAAiB;AACjB,EAAE;AACF,yBAAyB;;;;AAEzB,uCAAuC;AACvC,oEAAgD;AAChD,sDAAkC;AAElC,IAAM,IAAI,GAAoC,YAAY,CAAC;AAEnD,oBAAI;AADZ,IAAM,MAAM,GAAsC,cAAc,CAAC;AACnD,wBAAM"}
@@ -0,0 +1,3 @@
1
+ export * from './CoinflowTypes';
2
+ export * from './CoinflowUtils';
3
+ export * from './CoinflowLibMessageHandlers';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./CoinflowTypes"), exports);
5
+ tslib_1.__exportStar(require("./CoinflowUtils"), exports);
6
+ tslib_1.__exportStar(require("./CoinflowLibMessageHandlers"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,0DAAgC;AAChC,uEAA6C"}
@@ -1,11 +1,9 @@
1
1
  export * from './CoinflowWithdraw';
2
2
  export * from './CoinflowPurchase';
3
- export * from './CoinflowUtils';
4
- export * from './wallet/useIframeWallet';
3
+ export * from './common';
5
4
  export * from './CoinflowIFrame';
6
5
  export * from './CoinflowPurchaseHistory';
7
6
  export * from './CoinflowWithdrawHistory';
8
- export * from './CoinflowTypes';
9
7
  export * from './CoinflowPurchaseProtection';
10
8
  export * from './CoinflowCardForm';
11
9
  export * from './CoinflowApplePayButton';
@@ -3,12 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./CoinflowWithdraw"), exports);
5
5
  tslib_1.__exportStar(require("./CoinflowPurchase"), exports);
6
- tslib_1.__exportStar(require("./CoinflowUtils"), exports);
7
- tslib_1.__exportStar(require("./wallet/useIframeWallet"), exports);
6
+ tslib_1.__exportStar(require("./common"), exports);
8
7
  tslib_1.__exportStar(require("./CoinflowIFrame"), exports);
9
8
  tslib_1.__exportStar(require("./CoinflowPurchaseHistory"), exports);
10
9
  tslib_1.__exportStar(require("./CoinflowWithdrawHistory"), exports);
11
- tslib_1.__exportStar(require("./CoinflowTypes"), exports);
12
10
  tslib_1.__exportStar(require("./CoinflowPurchaseProtection"), exports);
13
11
  tslib_1.__exportStar(require("./CoinflowCardForm"), exports);
14
12
  tslib_1.__exportStar(require("./CoinflowApplePayButton"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,6DAAmC;AACnC,0DAAgC;AAChC,mEAAyC;AACzC,2DAAiC;AACjC,oEAA0C;AAC1C,oEAA0C;AAC1C,0DAAgC;AAChC,uEAA6C;AAC7C,6DAAmC;AACnC,mEAAyC;AACzC,oEAA0C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,6DAAmC;AACnC,mDAAyB;AACzB,2DAAiC;AACjC,oEAA0C;AAC1C,oEAA0C;AAC1C,uEAA6C;AAC7C,6DAAmC;AACnC,mEAAyC;AACzC,oEAA0C"}
@@ -1,12 +1,10 @@
1
- import { CoinflowPurchaseProps } from './CoinflowTypes';
2
- import React from 'react';
1
+ import { CoinflowPurchaseProps } from './common';
2
+ import React from "react";
3
3
  export declare function CoinflowApplePayButton(props: CoinflowPurchaseProps & MobileWalletButtonProps): React.JSX.Element;
4
4
  export declare function MobileWalletButton({ props, route }: {
5
5
  props: CoinflowPurchaseProps;
6
6
  route: string;
7
- }): React.JSX.Element | null;
7
+ }): React.JSX.Element;
8
8
  export interface MobileWalletButtonProps {
9
9
  color: "white" | "black";
10
10
  }
11
- export declare function useStringWalletPubkey(props: CoinflowPurchaseProps): string | null | undefined;
12
- export declare function useGetTokenHandler(props: CoinflowPurchaseProps): void;
@@ -1,47 +1,54 @@
1
1
  import { __assign } from "tslib";
2
- import { CoinflowIFrame } from './CoinflowIFrame';
3
- import React, { useEffect, useMemo, useRef } from 'react';
4
- import { useHandleHeightChange } from './useHandleHeightChange';
5
- import { getMessageHandler } from './wallet/useIframeWallet';
6
- import { CoinflowUtils } from './CoinflowUtils';
2
+ import { getWalletPubkey, getHandlers } from './common';
3
+ import { CoinflowIFrame } from "./CoinflowIFrame";
4
+ import React, { useEffect, useMemo, useRef } from "react";
7
5
  export function CoinflowApplePayButton(props) {
8
6
  return React.createElement(MobileWalletButton, { props: props, route: 'apple-pay' });
9
7
  }
10
8
  export function MobileWalletButton(_a) {
11
9
  var props = _a.props, route = _a.route;
12
- var IFrameRef = useRef(null);
13
- useHandleHeightChange(props.handleHeightChange);
14
- useGetTokenHandler(props);
15
- var walletPubkey = useStringWalletPubkey(props);
16
- if (!walletPubkey)
17
- return null;
18
- var iframeProps = __assign(__assign({}, props), { walletPubkey: walletPubkey, IFrameRef: IFrameRef, transaction: undefined, routePrefix: 'form', route: "/".concat(route, "/").concat(props.merchantId) });
19
- return React.createElement(CoinflowIFrame, __assign({}, iframeProps));
20
- }
21
- export function useStringWalletPubkey(props) {
22
- return useMemo(function () {
23
- var getWalletPubkey = CoinflowUtils.byBlockchain(props.blockchain, {
24
- solana: function () { var _a, _b; return (_b = (_a = props === null || props === void 0 ? void 0 : props.wallet) === null || _a === void 0 ? void 0 : _a.publicKey) === null || _b === void 0 ? void 0 : _b.toString(); },
25
- near: function () { return props.wallet.accountId; },
26
- eth: function () { return props.wallet.address; },
27
- polygon: function () { return props.wallet.address; },
28
- });
29
- return getWalletPubkey();
30
- }, [props]);
31
- }
32
- export function useGetTokenHandler(props) {
10
+ var iframeRef = useRef(null);
33
11
  var onSuccess = props.onSuccess;
34
12
  useEffect(function () {
35
- var handler = getMessageHandler('getToken', function (data) {
36
- if (data.startsWith('ERROR')) {
37
- console.error('Mobile Wallet Payment Error', data.replace('ERROR', ''));
38
- return;
13
+ if (!onSuccess)
14
+ return;
15
+ if (!(iframeRef === null || iframeRef === void 0 ? void 0 : iframeRef.current))
16
+ return;
17
+ iframeRef.current.listenForMessage(function (data) {
18
+ try {
19
+ var res = JSON.parse(data);
20
+ return 'method' in res && res.method === 'getToken';
39
21
  }
40
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
41
- });
42
- if (!window)
43
- throw new Error('Window not defined');
44
- window.addEventListener('message', handler);
22
+ catch (e) {
23
+ return false;
24
+ }
25
+ }).then(function (data) { return onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data); });
45
26
  }, [onSuccess]);
27
+ var iframeProps = useMemo(function () {
28
+ var walletPubkey = getWalletPubkey(props);
29
+ return __assign(__assign({}, props), { walletPubkey: walletPubkey, transaction: undefined, routePrefix: 'form', route: "/".concat(route, "/").concat(props.merchantId) });
30
+ }, [props, route]);
31
+ var messageHandlers = useMemo(function () {
32
+ return __assign(__assign({}, getHandlers(props)), { handleHeightChange: props.handleHeightChange });
33
+ }, [props]);
34
+ return React.createElement(CoinflowIFrame, __assign({ ref: iframeRef }, iframeProps, messageHandlers));
46
35
  }
36
+ // TODO
37
+ // export function useGetTokenHandler(props: CoinflowPurchaseProps) {
38
+ // const {onSuccess} = props;
39
+ //
40
+ // useEffect(() => {
41
+ // const handler = getMessageHandler('getToken', (data: string) => {
42
+ // if (data.startsWith('ERROR')) {
43
+ // console.error('Mobile Wallet Payment Error', data.replace('ERROR', ''));
44
+ // return;
45
+ // }
46
+ //
47
+ // onSuccess?.(data);
48
+ // });
49
+ //
50
+ // if (!window) throw new Error('Window not defined');
51
+ // window.addEventListener('message', handler);
52
+ // }, [onSuccess]);
53
+ // }
47
54
  //# sourceMappingURL=CoinflowApplePayButton.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CoinflowApplePayButton.js","sourceRoot":"","sources":["../../src/CoinflowApplePayButton.tsx"],"names":[],"mappings":";AAOA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,EAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACxD,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAC,iBAAiB,EAAC,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,MAAM,UAAU,sBAAsB,CAAC,KAAsD;IAC3F,OAAO,oBAAC,kBAAkB,IAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,GAAI,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,EAA6D;QAA5D,KAAK,WAAA,EAAE,KAAK,WAAA;IAC9C,IAAM,SAAS,GAAG,MAAM,CAA2B,IAAI,CAAC,CAAC;IACzD,qBAAqB,CAAC,KAAK,CAAC,kBAAkB,CAAC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React, { CSSProperties } from 'react';
2
- import { CoinflowBlockchain, CoinflowEnvs } from './CoinflowTypes';
1
+ import React, { CSSProperties } from "react";
2
+ import { CoinflowBlockchain, CoinflowEnvs } from './common';
3
3
  export type CoinflowCardTokenResponse = {
4
4
  last4: string;
5
5
  type: 'VISA' | 'MSTR' | 'AMEX' | 'DISC';
@@ -1,8 +1,6 @@
1
1
  import { __assign, __awaiter, __generator } from "tslib";
2
- import React, { forwardRef, useImperativeHandle, useMemo, useRef } from 'react';
3
- import { getMessageHandler } from './wallet/useIframeWallet';
4
- import { CoinflowIFrame } from './CoinflowIFrame';
5
- import { useHandleHeightChange } from './useHandleHeightChange';
2
+ import React, { forwardRef, useImperativeHandle, useMemo, useRef } from "react";
3
+ import { CoinflowIFrame } from "./CoinflowIFrame";
6
4
  /**
7
5
  * Allows merchants to collect card information from their customers in a PCI-compliant way and receive a token for use with the `/api/checkout/token` endpoint.
8
6
  *
@@ -23,56 +21,55 @@ import { useHandleHeightChange } from './useHandleHeightChange';
23
21
  *
24
22
  * ```
25
23
  */
26
- export var CoinflowCardForm = forwardRef(function (_a, ref) {
27
- var handleHeightChange = _a.handleHeightChange, walletPubkey = _a.walletPubkey, env = _a.env, customCss = _a.customCss, merchantId = _a.merchantId, blockchain = _a.blockchain;
28
- var IFrameRef = useRef(null);
29
- useHandleHeightChange(handleHeightChange);
24
+ export var CoinflowCardForm = forwardRef(function (props, ref) {
25
+ var iframeRef = useRef();
30
26
  useImperativeHandle(ref, function () { return ({
31
27
  getToken: function () {
32
28
  return __awaiter(this, void 0, void 0, function () {
33
- var _a;
34
- return __generator(this, function (_b) {
35
- if (!((_a = IFrameRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow))
36
- throw new Error('content window not found');
37
- IFrameRef.current.contentWindow.postMessage('getToken', '*');
38
- return [2 /*return*/, new Promise(function (resolve, reject) {
39
- var handler = getMessageHandler('getToken', function (data) {
40
- if (data.startsWith('ERROR')) {
41
- reject(new Error(data.replace('ERROR', '')));
42
- return;
29
+ var methodName, isValid, response;
30
+ return __generator(this, function (_a) {
31
+ switch (_a.label) {
32
+ case 0:
33
+ methodName = 'getToken';
34
+ if (!iframeRef.current)
35
+ throw new Error('Unable to get token');
36
+ isValid = function (data) {
37
+ try {
38
+ var res = JSON.parse(data);
39
+ return 'method' in res && res.method === methodName;
43
40
  }
44
- resolve(JSON.parse(data));
45
- });
46
- if (!window)
47
- throw new Error('Window not defined');
48
- window.addEventListener('message', handler);
49
- })];
41
+ catch (e) {
42
+ return false;
43
+ }
44
+ };
45
+ return [4 /*yield*/, iframeRef.current.sendAndReceiveMessage(methodName, isValid)];
46
+ case 1:
47
+ response = _a.sent();
48
+ return [2 /*return*/, JSON.parse(response).data];
49
+ }
50
50
  });
51
51
  });
52
52
  }
53
53
  }); });
54
54
  var merchantCss = useMemo(function () {
55
- if (!customCss)
55
+ if (!props.customCss)
56
56
  return undefined;
57
- var cssStr = Object.entries(customCss).reduce(function (acc, _a) {
57
+ var cssStr = Object.entries(props.customCss).reduce(function (acc, _a) {
58
58
  var key = _a[0], value = _a[1];
59
59
  return acc + "".concat(key, " {").concat(CSSPropertiesToComponent(value), "}\n");
60
60
  }, '');
61
61
  return Buffer.from(cssStr).toString('base64');
62
- }, [customCss]);
63
- if (!walletPubkey)
64
- return null;
65
- var iFrameProps = {
66
- walletPubkey: walletPubkey,
67
- blockchain: blockchain,
68
- route: "/checkout-form/".concat(merchantId),
69
- env: env,
70
- IFrameRef: IFrameRef,
71
- routePrefix: 'form',
72
- merchantCss: merchantCss,
73
- handleHeightChange: handleHeightChange,
74
- };
75
- return React.createElement(CoinflowIFrame, __assign({}, iFrameProps));
62
+ }, [props.customCss]);
63
+ var iframeProps = useMemo(function () {
64
+ return __assign(__assign({}, props), { walletPubkey: props.walletPubkey, route: "/checkout-form/".concat(props.merchantId), routePrefix: 'form', merchantCss: merchantCss, transaction: undefined });
65
+ }, [merchantCss, props]);
66
+ var messageHandlers = useMemo(function () {
67
+ return {
68
+ handleSendTransaction: function () { throw new Error('Not Supported'); },
69
+ handleHeightChange: props.handleHeightChange
70
+ };
71
+ }, [props]);
72
+ return React.createElement(CoinflowIFrame, __assign({ ref: iframeRef }, iframeProps, messageHandlers));
76
73
  });
77
74
  function CSSPropertiesToComponent(dict) {
78
75
  var str = '';
@@ -1 +1 @@
1
- {"version":3,"file":"CoinflowCardForm.js","sourceRoot":"","sources":["../../src/CoinflowCardForm.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAgB,UAAU,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC7F,OAAO,EAAC,iBAAiB,EAAC,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAC;AAkB9D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,IAAM,gBAAgB,GAAG,UAAU,CAAC,UAAC,EAAiG,EAAE,GAAG;QAArG,kBAAkB,wBAAA,EAAE,YAAY,kBAAA,EAAE,GAAG,SAAA,EAAE,SAAS,eAAA,EAAE,UAAU,gBAAA,EAAE,UAAU,gBAAA;IACnH,IAAM,SAAS,GAAG,MAAM,CAA2B,IAAI,CAAC,CAAC;IAEzD,qBAAqB,CAAC,kBAAkB,CAAC,CAAC;IAE1C,mBAAmB,CAAC,GAAG,EAAE,cAAM,OAAA,CAAC;QACxB,QAAQ;;;;oBACZ,IAAI,CAAC,CAAA,MAAA,SAAS,CAAC,OAAO,0CAAE,aAAa,CAAA;wBAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;oBAEnF,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;oBAC7D,sBAAO,IAAI,OAAO,CAA4B,UAAC,OAAO,EAAE,MAAM;4BAC5D,IAAM,OAAO,GAAG,iBAA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GAAG,EAAE,KAAK;KAUpB;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,4 +1,4 @@
1
- import { CoinflowPurchaseProps } from './CoinflowTypes';
1
+ import { CoinflowPurchaseProps } from './common';
2
2
  import React from 'react';
3
3
  import { MobileWalletButtonProps } from './CoinflowApplePayButton';
4
4
  export declare function CoinflowGooglePayButton(props: CoinflowPurchaseProps & MobileWalletButtonProps): React.JSX.Element;
@@ -1,3 +1,8 @@
1
1
  import React from 'react';
2
- import { CoinflowIFrameProps } from './CoinflowTypes';
3
- export declare function CoinflowIFrame(props: CoinflowIFrameProps): React.JSX.Element;
2
+ import { CoinflowIFrameProps, IFrameMessageHandlers } from './common';
3
+ export type SendAndReceiveMessage = (message: string, isResponseValid: (response: string) => boolean) => Promise<string>;
4
+ export type CoinflowIFrameExposedFunctions = {
5
+ sendAndReceiveMessage: SendAndReceiveMessage;
6
+ listenForMessage: (isResponseValid: (response: string) => boolean) => Promise<string>;
7
+ };
8
+ export declare const CoinflowIFrame: React.ForwardRefExoticComponent<CoinflowIFrameProps & IFrameMessageHandlers & React.RefAttributes<unknown>>;
@@ -1,10 +1,71 @@
1
- import React, { useMemo } from 'react';
2
- import { CoinflowUtils } from './CoinflowUtils';
3
- export function CoinflowIFrame(props) {
1
+ import { __awaiter, __generator } from "tslib";
2
+ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, } from 'react';
3
+ import { CoinflowUtils, handleIFrameMessage, } from './common';
4
+ export var CoinflowIFrame = forwardRef(function (props, ref) {
5
+ var IFrameRef = useRef(null);
4
6
  var url = useMemo(function () {
5
7
  return CoinflowUtils.getCoinflowUrl(props);
6
8
  }, [props]);
7
- var handleHeightChange = props.handleHeightChange, IFrameRef = props.IFrameRef;
9
+ var sendMessage = useCallback(function (message) {
10
+ var _a;
11
+ if (!((_a = IFrameRef === null || IFrameRef === void 0 ? void 0 : IFrameRef.current) === null || _a === void 0 ? void 0 : _a.contentWindow))
12
+ throw new Error('Iframe not defined');
13
+ IFrameRef.current.contentWindow.postMessage(message, '*');
14
+ }, []);
15
+ useImperativeHandle(ref, function () { return ({
16
+ listenForMessage: function (isResponseValid) {
17
+ return __awaiter(this, void 0, void 0, function () {
18
+ var handler;
19
+ return __generator(this, function (_a) {
20
+ return [2 /*return*/, new Promise(function (resolve, reject) {
21
+ handler = function (_a) {
22
+ var data = _a.data, origin = _a.origin;
23
+ if (!origin.includes(CoinflowUtils.getCoinflowBaseUrl(props.env)))
24
+ return;
25
+ if (data.startsWith('ERROR')) {
26
+ reject(new Error(data.replace('ERROR', '')));
27
+ return;
28
+ }
29
+ if (!isResponseValid(data))
30
+ return;
31
+ resolve(data);
32
+ };
33
+ if (!window)
34
+ throw new Error('Window not defined');
35
+ window.addEventListener('message', handler);
36
+ }).finally(function () {
37
+ window.removeEventListener('message', handler);
38
+ })];
39
+ });
40
+ });
41
+ },
42
+ sendAndReceiveMessage: function (message, isResponseValid) {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ return __generator(this, function (_a) {
45
+ sendMessage(message);
46
+ return [2 /*return*/, this.listenForMessage(isResponseValid)];
47
+ });
48
+ });
49
+ },
50
+ }); });
51
+ var handleIframeMessages = useCallback(function (_a) {
52
+ var data = _a.data, origin = _a.origin;
53
+ if (!origin.includes(CoinflowUtils.getCoinflowBaseUrl(props.env)))
54
+ return;
55
+ var promise = handleIFrameMessage(data, props);
56
+ if (!promise)
57
+ return;
58
+ promise.then(sendMessage).catch(function (e) { return sendMessage('ERROR ' + e.message); });
59
+ }, [props, sendMessage]);
60
+ useEffect(function () {
61
+ if (!window)
62
+ throw new Error('Window not defined');
63
+ window.addEventListener('message', handleIframeMessages);
64
+ return function () {
65
+ window.removeEventListener('message', handleIframeMessages);
66
+ };
67
+ }, [handleIframeMessages]);
68
+ var handleHeightChange = props.handleHeightChange;
8
69
  return useMemo(function () { return (React.createElement("iframe", { scrolling: handleHeightChange ? 'no' : 'yes', onLoad: function () {
9
70
  if (IFrameRef.current)
10
71
  IFrameRef.current.style.opacity = '1';
@@ -14,5 +75,5 @@ export function CoinflowIFrame(props) {
14
75
  opacity: 0,
15
76
  transition: 'opacity 300ms linear',
16
77
  }, title: "withdraw", frameBorder: "0", src: url })); }, [IFrameRef, handleHeightChange, url]);
17
- }
78
+ });
18
79
  //# sourceMappingURL=CoinflowIFrame.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CoinflowIFrame.js","sourceRoot":"","sources":["../../src/CoinflowIFrame.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AACrC,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAG9C,MAAM,UAAU,cAAc,CAAC,KAA0B;IACvD,IAAM,GAAG,GAAG,OAAO,CAAC;QAClB,OAAO,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEL,IAAA,kBAAkB,GAAe,KAAK,mBAApB,EAAE,SAAS,GAAI,KAAK,UAAT,CAAU;IAC9C,OAAO,OAAO,CACZ,cAAM,OAAA,CACJ,gCACE,SAAS,EAAE,kBAAkB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAC5C,MAAM,EAAE;YACN,IAAI,SAAS,CAAC,OAAO;gBAAE,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC;QAC/D,CAAC,EACD,KAAK,EAAE,gBAAgB,EACvB,GAAG,EAAE,SAAS,EACd,KAAK,EAAE;YACL,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,CAAC;YACV,UAAU,EAAE,sBAAsB;SACnC,EACD,KAAK,EAAC,UAAU,EAChB,WAAW,EAAC,GAAG,EACf,GAAG,EAAE,GAAG,GACR,CACH,EAlBK,CAkBL,EACD,CAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,CA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