@coinflowlabs/angular 0.2.2 → 0.3.0

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.
@@ -91,12 +91,15 @@ class CoinflowUtils {
91
91
  return 'http://localhost:5000';
92
92
  return `https://api-${env}.coinflow.cash`;
93
93
  }
94
- static getCoinflowUrl({ walletPubkey, route, routePrefix, env, amount, transaction, blockchain, 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, origins, threeDsChallengePreference, }) {
94
+ static getCoinflowUrl({ walletPubkey, sessionKey, route, routePrefix, env, amount, transaction, blockchain = 'solana', 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, origins, threeDsChallengePreference, supportEmail, }) {
95
95
  const prefix = routePrefix
96
96
  ? `/${routePrefix}/${blockchain}`
97
97
  : `/${blockchain}`;
98
98
  const url = new URL(prefix + route, CoinflowUtils.getCoinflowBaseUrl(env));
99
- url.searchParams.append('pubkey', walletPubkey);
99
+ if (walletPubkey)
100
+ url.searchParams.append('pubkey', walletPubkey);
101
+ if (sessionKey)
102
+ url.searchParams.append('sessionKey', sessionKey);
100
103
  if (transaction) {
101
104
  url.searchParams.append('transaction', transaction);
102
105
  }
@@ -115,6 +118,8 @@ class CoinflowUtils {
115
118
  if (email) {
116
119
  url.searchParams.append('email', email);
117
120
  }
121
+ if (supportEmail)
122
+ url.searchParams.append('supportEmail', supportEmail);
118
123
  if (token) {
119
124
  url.searchParams.append('token', token.toString());
120
125
  }
@@ -183,6 +188,8 @@ class CoinflowUtils {
183
188
  return url.toString();
184
189
  }
185
190
  static getTransaction(props) {
191
+ if (!props.blockchain)
192
+ return undefined;
186
193
  return this.byBlockchain(props.blockchain, {
187
194
  solana: () => {
188
195
  if (!('transaction' in props))
@@ -229,6 +236,9 @@ class CoinflowUtils {
229
236
  const { action } = props;
230
237
  return LZString.compressToEncodedURIComponent(JSON.stringify(action));
231
238
  },
239
+ user: () => {
240
+ return undefined;
241
+ },
232
242
  })();
233
243
  }
234
244
  static byBlockchain(blockchain, args) {
@@ -245,6 +255,8 @@ class CoinflowUtils {
245
255
  return args.base;
246
256
  case 'arbitrum':
247
257
  return args.arbitrum;
258
+ case 'user':
259
+ return args.user;
248
260
  default:
249
261
  throw new Error('blockchain not supported!');
250
262
  }
@@ -309,16 +321,20 @@ var IFrameMessageMethods;
309
321
  IFrameMessageMethods["SendTransaction"] = "sendTransaction";
310
322
  IFrameMessageMethods["HeightChange"] = "heightChange";
311
323
  IFrameMessageMethods["Success"] = "success";
324
+ IFrameMessageMethods["Load"] = "load";
312
325
  })(IFrameMessageMethods || (IFrameMessageMethods = {}));
313
- function getWalletPubkey({ wallet, }) {
314
- if ('publicKey' in wallet) {
315
- return wallet.publicKey.toString();
316
- }
317
- if ('address' in wallet) {
318
- return wallet.address;
319
- }
320
- if ('accountId' in wallet) {
321
- return wallet.accountId;
326
+ function getWalletPubkey(input) {
327
+ if ('wallet' in input && input.wallet) {
328
+ const { wallet } = input;
329
+ if ('publicKey' in wallet) {
330
+ return wallet.publicKey.toString();
331
+ }
332
+ if ('address' in wallet) {
333
+ return wallet.address;
334
+ }
335
+ if ('accountId' in wallet) {
336
+ return wallet.accountId;
337
+ }
322
338
  }
323
339
  return null;
324
340
  }
@@ -358,6 +374,20 @@ function handleIFrameMessage(rawMessage, handlers) {
358
374
  console.warn(`Didn't expect to get here, handleIFrameMessage method:${method} is not one of ${Object.values(IFrameMessageMethods)}`);
359
375
  }
360
376
  function getHandlers(props) {
377
+ if (!props.blockchain) {
378
+ return {
379
+ handleSendTransaction: () => {
380
+ throw new Error('handleSendTransaction Not Implemented for sessionKey');
381
+ },
382
+ handleSignMessage: () => {
383
+ throw new Error('handleSendTransaction Not Implemented for sessionKey');
384
+ },
385
+ handleSignTransaction: () => {
386
+ throw new Error('handleSendTransaction Not Implemented for sessionKey');
387
+ },
388
+ onSuccess: props.onSuccess,
389
+ };
390
+ }
361
391
  return CoinflowUtils.byBlockchain(props.blockchain, {
362
392
  solana: () => getSolanaWalletHandlers(props),
363
393
  near: () => getNearWalletHandlers(props),
@@ -365,6 +395,7 @@ function getHandlers(props) {
365
395
  polygon: () => getEvmWalletHandlers(props),
366
396
  base: () => getEvmWalletHandlers(props),
367
397
  arbitrum: () => getEvmWalletHandlers(props),
398
+ user: () => getIdWalletHandlers(props),
368
399
  })();
369
400
  }
370
401
  function getSolanaWalletHandlers({ wallet, onSuccess, }) {
@@ -439,6 +470,14 @@ function getEvmWalletHandlers({ wallet, onSuccess, }) {
439
470
  onSuccess,
440
471
  };
441
472
  }
473
+ function getIdWalletHandlers({ onSuccess, }) {
474
+ return {
475
+ handleSendTransaction: async () => {
476
+ return Promise.resolve('');
477
+ },
478
+ onSuccess,
479
+ };
480
+ }
442
481
 
443
482
  // Type definitions for TokenEx iframe integration
444
483
  const TokenExCardNumberIframeId = 'tokenExCardNumber';
@@ -679,7 +718,7 @@ class CoinflowPurchaseComponent {
679
718
  this.iframeProps = {
680
719
  ...this.purchaseProps,
681
720
  walletPubkey,
682
- route: `/purchase/${this.purchaseProps?.merchantId}`,
721
+ route: `/purchase-v2/${this.purchaseProps?.merchantId}`,
683
722
  transaction: CoinflowUtils.getTransaction(this.purchaseProps),
684
723
  };
685
724
  }
@@ -984,6 +1023,11 @@ class CoinflowMobileWalletButtonComponent {
984
1023
  handleMessage({ data }) {
985
1024
  try {
986
1025
  const res = JSON.parse(data);
1026
+ console.log({ data });
1027
+ if ('method' in res && res.data.startsWith('ERROR')) {
1028
+ this.purchaseProps.onError?.(res.info);
1029
+ return;
1030
+ }
987
1031
  if ('method' in res && res.method === 'loaded') {
988
1032
  this.opacity = 1;
989
1033
  setTimeout(() => {