@coinflowlabs/angular 0.3.1 → 0.3.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.
@@ -1,10 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { EventEmitter, Component, Input, Output, ViewChild, HostListener, Injectable, inject } from '@angular/core';
3
3
  import * as SolanaWeb3Js from '@solana/web3.js';
4
- import { Keypair, Transaction } from '@solana/web3.js';
5
4
  import base58Imported from 'bs58';
6
5
  import LZString from 'lz-string';
7
- import { sign } from 'tweetnacl';
8
6
  import * as i1 from '@angular/platform-browser';
9
7
 
10
8
  var SettlementType;
@@ -66,17 +64,6 @@ class CoinflowUtils {
66
64
  return undefined;
67
65
  });
68
66
  }
69
- async getCreditBalance(publicKey, merchantId, blockchain) {
70
- const response = await fetch(this.url + `/api/customer/balances/${merchantId}`, {
71
- method: 'GET',
72
- headers: {
73
- 'x-coinflow-auth-wallet': publicKey,
74
- 'x-coinflow-auth-blockchain': blockchain,
75
- },
76
- });
77
- const { credits } = await response.json();
78
- return credits;
79
- }
80
67
  static getCoinflowBaseUrl(env) {
81
68
  if (!env || env === 'prod')
82
69
  return 'https://coinflow.cash';
@@ -91,7 +78,7 @@ class CoinflowUtils {
91
78
  return 'http://localhost:5000';
92
79
  return `https://api-${env}.coinflow.cash`;
93
80
  }
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, }) {
81
+ 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, destinationAuthKey, }) {
95
82
  const prefix = routePrefix
96
83
  ? `/${routePrefix}/${blockchain}`
97
84
  : `/${blockchain}`;
@@ -185,6 +172,8 @@ class CoinflowUtils {
185
172
  url.searchParams.append('origins', LZString.compressToEncodedURIComponent(JSON.stringify(origins)));
186
173
  if (threeDsChallengePreference)
187
174
  url.searchParams.append('threeDsChallengePreference', threeDsChallengePreference);
175
+ if (destinationAuthKey)
176
+ url.searchParams.append('destinationAuthKey', destinationAuthKey);
188
177
  return url.toString();
189
178
  }
190
179
  static getTransaction(props) {
@@ -261,57 +250,6 @@ class CoinflowUtils {
261
250
  throw new Error('blockchain not supported!');
262
251
  }
263
252
  }
264
- static async getWalletFromUserId({ userId, merchantId, env, }) {
265
- return this.getWalletFromEmail({
266
- email: userId,
267
- merchantId,
268
- env,
269
- });
270
- }
271
- static async getWalletFromEmail({ email, merchantId, env, }) {
272
- const buffer = new TextEncoder().encode(email);
273
- const crypto = window.crypto.subtle;
274
- const hash = await crypto.digest('SHA-256', buffer);
275
- const seed = new Uint8Array(hash);
276
- const keypair = Keypair.fromSeed(seed);
277
- return {
278
- publicKey: keypair.publicKey,
279
- signMessage: (message) => Promise.resolve(sign.detached(message, keypair.secretKey)),
280
- signTransaction: async (transaction) => {
281
- if (transaction instanceof Transaction) {
282
- transaction.sign(keypair);
283
- return transaction;
284
- }
285
- else {
286
- transaction.sign([keypair]);
287
- return transaction;
288
- }
289
- },
290
- sendTransaction: async (transaction) => {
291
- if (transaction instanceof Transaction) {
292
- transaction.sign(keypair);
293
- }
294
- else {
295
- transaction.sign([keypair]);
296
- }
297
- const coinflowBaseUrl = this.getCoinflowApiUrl(env);
298
- const options = {
299
- method: 'POST',
300
- headers: {
301
- 'content-type': 'application/json',
302
- 'x-coinflow-auth-wallet': keypair.publicKey.toString(),
303
- 'x-coinflow-auth-blockchain': 'solana',
304
- },
305
- body: JSON.stringify({
306
- merchantId,
307
- signedTransaction: base58?.encode(transaction.serialize()),
308
- }),
309
- };
310
- const { signature } = await fetch(coinflowBaseUrl + '/api/utils/send-coinflow-tx', options).then(res => res.json());
311
- return signature;
312
- },
313
- };
314
- }
315
253
  }
316
254
 
317
255
  var IFrameMessageMethods;
@@ -918,7 +856,6 @@ class CoinflowCardNumberInput {
918
856
  this.TokenExCardNumberIframeId = TokenExCardNumberIframeId;
919
857
  }
920
858
  onScriptLoaded() {
921
- console.log('onScriptLoaded');
922
859
  this.cardFormService
923
860
  .initializeTokenExIframe(this.args.env, {
924
861
  css: JSON.stringify(this.args.css),
@@ -929,12 +866,18 @@ class CoinflowCardNumberInput {
929
866
  .then(iframe => (this.iframe = iframe))
930
867
  .catch(e => console.error(e));
931
868
  }
932
- ngOnInit() {
869
+ initializeTokenEx() {
933
870
  setTokenExScriptTag({
934
871
  env: this.args.env,
935
872
  setTokenExScriptLoaded: this.onScriptLoaded.bind(this),
936
873
  });
937
874
  }
875
+ ngOnInit() {
876
+ this.initializeTokenEx();
877
+ }
878
+ ngOnDestroy() {
879
+ this.iframe = undefined;
880
+ }
938
881
  tokenize() {
939
882
  return this.iframe.tokenize();
940
883
  }
@@ -960,7 +903,6 @@ class CoinflowCardNumberOnlyInput {
960
903
  this.TokenExCardNumberIframeId = TokenExCardNumberIframeId;
961
904
  }
962
905
  onScriptLoaded() {
963
- console.log('onScriptLoaded');
964
906
  this.cardFormService
965
907
  .initializeTokenExCardOnlyIframe(this.args.env, {
966
908
  css: JSON.stringify(this.args.css),
@@ -971,12 +913,18 @@ class CoinflowCardNumberOnlyInput {
971
913
  .then(iframe => (this.iframe = iframe))
972
914
  .catch(e => console.error(e));
973
915
  }
974
- ngOnInit() {
916
+ initializeTokenEx() {
975
917
  setTokenExScriptTag({
976
918
  env: this.args.env,
977
919
  setTokenExScriptLoaded: this.onScriptLoaded.bind(this),
978
920
  });
979
921
  }
922
+ ngOnInit() {
923
+ this.initializeTokenEx();
924
+ }
925
+ ngOnDestroy() {
926
+ this.iframe = undefined;
927
+ }
980
928
  tokenize() {
981
929
  return this.iframe.tokenize();
982
930
  }
@@ -1031,12 +979,18 @@ class CoinflowCvvOnlyInputComponent {
1031
979
  .then(iframe => (this.iframe = iframe))
1032
980
  .catch(e => console.error(e));
1033
981
  }
1034
- ngOnInit() {
982
+ initializeTokenEx() {
1035
983
  setTokenExScriptTag({
1036
984
  env: this.args.env,
1037
985
  setTokenExScriptLoaded: this.onScriptLoaded.bind(this),
1038
986
  });
1039
987
  }
988
+ ngOnInit() {
989
+ this.initializeTokenEx();
990
+ }
991
+ ngOnDestroy() {
992
+ this.iframe = undefined;
993
+ }
1040
994
  tokenize() {
1041
995
  return this.iframe.tokenize();
1042
996
  }