@coinflowlabs/angular 1.12.0 → 1.14.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.
@@ -5,6 +5,7 @@ import base58Imported from 'bs58';
5
5
  import LZString from 'lz-string';
6
6
  import nsureSDK from '@nsure-ai/web-client-sdk';
7
7
  import * as i1 from '@angular/platform-browser';
8
+ import { NgStyle } from '@angular/common';
8
9
 
9
10
  var WithdrawCategory;
10
11
  (function (WithdrawCategory) {
@@ -25,6 +26,7 @@ var WithdrawSpeed;
25
26
  WithdrawSpeed["PAYPAL"] = "paypal";
26
27
  WithdrawSpeed["WIRE"] = "wire";
27
28
  WithdrawSpeed["INTERAC"] = "interac";
29
+ WithdrawSpeed["SWIFT"] = "swift";
28
30
  })(WithdrawSpeed || (WithdrawSpeed = {}));
29
31
  var SettlementType;
30
32
  (function (SettlementType) {
@@ -557,13 +559,15 @@ class CoinflowUtils {
557
559
  return 'http://localhost:5000';
558
560
  return `https://api-${env}.coinflow.cash`;
559
561
  }
560
- static getCoinflowUrl({ walletPubkey, sessionKey, route, routePrefix, env, subtotal, presentment, transaction, blockchain = 'solana', webhookInfo, email, loaderBackground, handleHeightChangeId, bankAccountLinkRedirect, additionalWallets, chargebackProtectionData, chargebackProtectionAccountType, merchantCss, color, rent, lockDefaultToken, tokens, planCode, disableApplePay, disableGooglePay, customerInfo, settlementType, lockAmount, nativeSolToConvert, theme, usePermit, transactionSigner, authOnly, deviceId, jwtToken, origins, threeDsChallengePreference, supportEmail, destinationAuthKey, allowedPaymentMethods, accountFundingTransaction, partialUsdcChecked, redemptionCheck, allowedWithdrawSpeeds, isZeroAuthorization, zeroAuthorizationConfig, userLocation, depositAmounts, baseUrl, }) {
562
+ static getCoinflowUrl({ walletPubkey, sessionKey, route, routePrefix, env, subtotal, useNativeSubtotal, presentment, transaction, blockchain = 'solana', webhookInfo, email, loaderBackground, handleHeightChangeId, bankAccountLinkRedirect, additionalWallets, chargebackProtectionData, chargebackProtectionAccountType, merchantCss, color, rent, lockDefaultToken, tokens, planCode, disableApplePay, disableGooglePay, customerInfo, settlementType, lockAmount, nativeSolToConvert, theme, usePermit, transactionSigner, authOnly, deviceId, jwtToken, origins, threeDsChallengePreference, supportEmail, destinationAuthKey, allowedPaymentMethods, accountFundingTransaction, partialUsdcChecked, redemptionCheck, allowedWithdrawSpeeds, isZeroAuthorization, zeroAuthorizationConfig, userLocation, appReturnUrl, depositAmounts, ownerOverride, bridgeId, baseUrl, }) {
561
563
  const prefix = routePrefix
562
564
  ? `/${routePrefix}/${blockchain}`
563
565
  : `/${blockchain}`;
564
566
  const url = new URL(prefix + route, baseUrl ?? CoinflowUtils.getCoinflowBaseUrl(env));
565
567
  if (walletPubkey)
566
568
  url.searchParams.append('pubkey', walletPubkey);
569
+ if (ownerOverride)
570
+ url.searchParams.append('ownerOverride', ownerOverride);
567
571
  if (sessionKey)
568
572
  url.searchParams.append('sessionKey', sessionKey);
569
573
  if (transaction) {
@@ -584,6 +588,10 @@ class CoinflowUtils {
584
588
  url.searchParams.append('amount', subtotal.amount.toString());
585
589
  }
586
590
  }
591
+ if (useNativeSubtotal)
592
+ url.searchParams.append('useNativeSubtotal', 'true');
593
+ if (bridgeId)
594
+ url.searchParams.append('bridgeId', bridgeId);
587
595
  if (presentment)
588
596
  url.searchParams.append('presentment', presentment);
589
597
  if (webhookInfo) {
@@ -683,6 +691,8 @@ class CoinflowUtils {
683
691
  url.searchParams.append('lat', userLocation.lat.toString());
684
692
  url.searchParams.append('lng', userLocation.lng.toString());
685
693
  }
694
+ if (appReturnUrl)
695
+ url.searchParams.append('appReturnUrl', appReturnUrl);
686
696
  return url.toString();
687
697
  }
688
698
  static getCoinflowIntentsUrl({ baseUrl, route, color, theme, env, origins, deviceId, merchantCss, loaderBackground, handleHeightChangeId, }) {
@@ -846,10 +856,13 @@ var IFrameMessageMethods;
846
856
  IFrameMessageMethods["HeightChange"] = "heightChange";
847
857
  IFrameMessageMethods["Success"] = "success";
848
858
  IFrameMessageMethods["AuthDeclined"] = "authDeclined";
859
+ IFrameMessageMethods["InputError"] = "inputError";
860
+ IFrameMessageMethods["InputValid"] = "inputValid";
849
861
  IFrameMessageMethods["Loaded"] = "loaded";
850
862
  IFrameMessageMethods["AccountLinked"] = "accountLinked";
851
863
  IFrameMessageMethods["Redirect"] = "redirect";
852
864
  IFrameMessageMethods["Overlay"] = "overlay";
865
+ IFrameMessageMethods["UpdateSubtotal"] = "updateSubtotal";
853
866
  })(IFrameMessageMethods || (IFrameMessageMethods = {}));
854
867
  function getWalletPubkey(input) {
855
868
  let wallet;
@@ -909,6 +922,16 @@ function handleIFrameMessage(rawMessage, handlers, handleHeightChangeId) {
909
922
  return;
910
923
  handlers.onAuthDeclined(walletCall.info);
911
924
  return;
925
+ case IFrameMessageMethods.InputError:
926
+ if (!handlers.onInputError)
927
+ return;
928
+ handlers.onInputError(walletCall.info);
929
+ return;
930
+ case IFrameMessageMethods.InputValid:
931
+ if (!handlers.onInputValid)
932
+ return;
933
+ handlers.onInputValid(walletCall.info);
934
+ return;
912
935
  case IFrameMessageMethods.Loaded:
913
936
  return;
914
937
  case IFrameMessageMethods.AccountLinked:
@@ -952,6 +975,8 @@ function getHandlers(props) {
952
975
  },
953
976
  onSuccess: props.onSuccess,
954
977
  onAuthDeclined: props.onAuthDeclined,
978
+ onInputError: props.onInputError,
979
+ onInputValid: props.onInputValid,
955
980
  };
956
981
  }
957
982
  return CoinflowUtils.byBlockchain(chain, {
@@ -959,46 +984,62 @@ function getHandlers(props) {
959
984
  wallet: wallet,
960
985
  onSuccess: props.onSuccess,
961
986
  onAuthDeclined: props.onAuthDeclined,
987
+ onInputError: props.onInputError,
988
+ onInputValid: props.onInputValid,
962
989
  }),
963
990
  eth: () => getEvmWalletHandlers({
964
991
  wallet: wallet,
965
992
  onSuccess: props.onSuccess,
966
993
  onAuthDeclined: props.onAuthDeclined,
994
+ onInputError: props.onInputError,
995
+ onInputValid: props.onInputValid,
967
996
  }),
968
997
  polygon: () => getEvmWalletHandlers({
969
998
  wallet: wallet,
970
999
  onSuccess: props.onSuccess,
971
1000
  onAuthDeclined: props.onAuthDeclined,
1001
+ onInputError: props.onInputError,
1002
+ onInputValid: props.onInputValid,
972
1003
  }),
973
1004
  base: () => getEvmWalletHandlers({
974
1005
  wallet: wallet,
975
1006
  onSuccess: props.onSuccess,
976
1007
  onAuthDeclined: props.onAuthDeclined,
1008
+ onInputError: props.onInputError,
1009
+ onInputValid: props.onInputValid,
977
1010
  }),
978
1011
  arbitrum: () => getEvmWalletHandlers({
979
1012
  wallet: wallet,
980
1013
  onSuccess: props.onSuccess,
981
1014
  onAuthDeclined: props.onAuthDeclined,
1015
+ onInputError: props.onInputError,
1016
+ onInputValid: props.onInputValid,
982
1017
  }),
983
1018
  stellar: () => getStellarWalletHandlers({
984
1019
  wallet: wallet,
985
1020
  onSuccess: props.onSuccess,
986
1021
  onAuthDeclined: props.onAuthDeclined,
1022
+ onInputError: props.onInputError,
1023
+ onInputValid: props.onInputValid,
987
1024
  }),
988
1025
  monad: () => getEvmWalletHandlers({
989
1026
  wallet: wallet,
990
1027
  onSuccess: props.onSuccess,
991
1028
  onAuthDeclined: props.onAuthDeclined,
1029
+ onInputError: props.onInputError,
1030
+ onInputValid: props.onInputValid,
992
1031
  }),
993
1032
  tempo: () => getEvmWalletHandlers({
994
1033
  wallet: wallet,
995
1034
  onSuccess: props.onSuccess,
996
1035
  onAuthDeclined: props.onAuthDeclined,
1036
+ onInputError: props.onInputError,
1037
+ onInputValid: props.onInputValid,
997
1038
  }),
998
1039
  user: () => getSessionKeyHandlers(props),
999
1040
  })();
1000
1041
  }
1001
- function getSolanaWalletHandlers({ wallet, onSuccess, onAuthDeclined, }) {
1042
+ function getSolanaWalletHandlers({ wallet, onSuccess, onAuthDeclined, onInputError, onInputValid, }) {
1002
1043
  return {
1003
1044
  handleSendTransaction: async (transaction) => {
1004
1045
  const tx = getSolanaTransaction(transaction);
@@ -1030,6 +1071,8 @@ function getSolanaWalletHandlers({ wallet, onSuccess, onAuthDeclined, }) {
1030
1071
  },
1031
1072
  onSuccess,
1032
1073
  onAuthDeclined,
1074
+ onInputError,
1075
+ onInputValid,
1033
1076
  };
1034
1077
  }
1035
1078
  function getSolanaTransaction(data) {
@@ -1043,7 +1086,7 @@ function getSolanaTransaction(data) {
1043
1086
  return web3.Transaction.from(parsedUInt8Array);
1044
1087
  return vtx;
1045
1088
  }
1046
- function getEvmWalletHandlers({ wallet, onSuccess, onAuthDeclined, }) {
1089
+ function getEvmWalletHandlers({ wallet, onSuccess, onAuthDeclined, onInputError, onInputValid, }) {
1047
1090
  return {
1048
1091
  handleSendTransaction: async (transaction) => {
1049
1092
  const tx = JSON.parse(Buffer.from(transaction, 'base64').toString());
@@ -1055,9 +1098,11 @@ function getEvmWalletHandlers({ wallet, onSuccess, onAuthDeclined, }) {
1055
1098
  },
1056
1099
  onSuccess,
1057
1100
  onAuthDeclined,
1101
+ onInputError,
1102
+ onInputValid,
1058
1103
  };
1059
1104
  }
1060
- function getStellarWalletHandlers({ wallet, onSuccess, onAuthDeclined, }) {
1105
+ function getStellarWalletHandlers({ wallet, onSuccess, onAuthDeclined, onInputError, onInputValid, }) {
1061
1106
  return {
1062
1107
  handleSendTransaction: async (transaction) => {
1063
1108
  // transaction is unsigned base64 XDR
@@ -1080,15 +1125,19 @@ function getStellarWalletHandlers({ wallet, onSuccess, onAuthDeclined, }) {
1080
1125
  },
1081
1126
  onSuccess,
1082
1127
  onAuthDeclined,
1128
+ onInputError,
1129
+ onInputValid,
1083
1130
  };
1084
1131
  }
1085
- function getSessionKeyHandlers({ onSuccess, onAuthDeclined, }) {
1132
+ function getSessionKeyHandlers({ onSuccess, onAuthDeclined, onInputError, onInputValid, }) {
1086
1133
  return {
1087
1134
  handleSendTransaction: async () => {
1088
1135
  return Promise.resolve('');
1089
1136
  },
1090
1137
  onSuccess,
1091
1138
  onAuthDeclined,
1139
+ onInputError,
1140
+ onInputValid,
1092
1141
  };
1093
1142
  }
1094
1143
 
@@ -1270,6 +1319,416 @@ function CSSPropertiesToComponent(dict) {
1270
1319
  return str;
1271
1320
  }
1272
1321
 
1322
+ /**
1323
+ * Single source of truth for the card-entry responsive layout.
1324
+ *
1325
+ * The real card-entry form (`UnifiedCardEntry` in the core-flows app) and the
1326
+ * React/Vue/Angular skeleton loaders all render the same grid. Historically the
1327
+ * form drove the inline↔two-row switch from JS (a ResizeObserver toggling React
1328
+ * state) while the skeletons hard-coded their own guesses, so the two drifted.
1329
+ *
1330
+ * This module defines the grid templates and the breakpoint ONCE, as pure data
1331
+ * plus a CSS builder, so every consumer reflows at exactly the same width via a
1332
+ * CSS container query — no JS width measurement, nothing to keep in sync.
1333
+ */
1334
+ /**
1335
+ * Minimum width (px) each field needs before the row is too cramped and the
1336
+ * layout drops to two rows. Mirrors the real form's field sizing.
1337
+ */
1338
+ const CARD_ENTRY_MIN_WIDTHS = {
1339
+ 'card-number': 180,
1340
+ expiration: 96,
1341
+ cvv: 80,
1342
+ };
1343
+ /** Notional gap (px) between fields, summed into the reflow breakpoint. */
1344
+ const CARD_ENTRY_SLOT_GAP_PX = 8;
1345
+ /** Field row height — matches the real form's `3rem` grid rows. */
1346
+ const CARD_ENTRY_ROW_HEIGHT = '3rem';
1347
+ const CARD_ENTRY_ROW_HEIGHT_PX = 48;
1348
+ /** 1px accent line between rows / between exp & cvv in the two-row layout. */
1349
+ const CARD_ENTRY_DIVIDER_PX = 1;
1350
+ /**
1351
+ * The form draws its fields inside a 1px border, so the query container (the
1352
+ * full iframe width) is 2px wider than the field row that `minRowWidth`
1353
+ * describes. The breakpoint bakes this in so form and skeleton flip together.
1354
+ */
1355
+ const CARD_ENTRY_BORDER_PX = 1;
1356
+ /**
1357
+ * The form insets its box by this much on every side (Tailwind `m-0.5`) so the
1358
+ * focus ring has room and isn't clipped at the iframe edge. It adds to the box's
1359
+ * rendered height, so the skeleton's height guess includes it to avoid a jump
1360
+ * when the loaded form replaces the skeleton.
1361
+ */
1362
+ const CARD_ENTRY_MARGIN_PX = 2;
1363
+ /** Inline (wide-layout) track width for each field. */
1364
+ const INLINE_SLOT_WIDTH = {
1365
+ 'card-number': '1fr',
1366
+ expiration: '96px',
1367
+ cvv: '80px',
1368
+ };
1369
+ /** grid-area name a field occupies. */
1370
+ const FIELD_AREA = {
1371
+ 'card-number': 'card',
1372
+ expiration: 'exp',
1373
+ cvv: 'cvv',
1374
+ };
1375
+ function has(inputs, name) {
1376
+ return inputs.includes(name);
1377
+ }
1378
+ /** The reflow breakpoint on the field row, before adding the form border. */
1379
+ function minRowWidthPx(inputs) {
1380
+ const fields = inputs.reduce((sum, name) => sum + CARD_ENTRY_MIN_WIDTHS[name], 0);
1381
+ const gaps = Math.max(0, inputs.length - 1) * CARD_ENTRY_SLOT_GAP_PX;
1382
+ return fields + gaps;
1383
+ }
1384
+ /** grid-template for the single-row inline layout. */
1385
+ function inlineTemplate({ inputs, hasIcon, }) {
1386
+ const areas = [];
1387
+ const cols = [];
1388
+ const pushSlot = (area, width) => {
1389
+ if (areas.length > 0) {
1390
+ areas.push(`d${area.toUpperCase()}`);
1391
+ cols.push('1px');
1392
+ }
1393
+ areas.push(area);
1394
+ cols.push(width);
1395
+ };
1396
+ if (hasIcon && has(inputs, 'card-number'))
1397
+ pushSlot('icon', 'auto');
1398
+ for (const name of inputs)
1399
+ pushSlot(FIELD_AREA[name], INLINE_SLOT_WIDTH[name]);
1400
+ return `"${areas.join(' ')}" ${CARD_ENTRY_ROW_HEIGHT} / ${cols.join(' ')}`;
1401
+ }
1402
+ /** grid-template + dividers for the two-row layout (PAN on top). */
1403
+ function twoRowTemplate({ inputs, hasIcon, }) {
1404
+ const showsCard = has(inputs, 'card-number');
1405
+ const showsExp = has(inputs, 'expiration');
1406
+ const showsCvv = has(inputs, 'cvv');
1407
+ if (!showsCard || (!showsExp && !showsCvv))
1408
+ return null;
1409
+ const rows = `${CARD_ENTRY_ROW_HEIGHT} ${CARD_ENTRY_DIVIDER_PX}px ${CARD_ENTRY_ROW_HEIGHT}`;
1410
+ if (showsExp && showsCvv) {
1411
+ const areas = hasIcon
1412
+ ? '"icon card card card" "dHR dHR dHR dHR" "exp exp dEV cvv"'
1413
+ : '"card card card" "dHR dHR dHR" "exp dEV cvv"';
1414
+ const cols = hasIcon
1415
+ ? 'auto minmax(0, 1fr) 1px minmax(0, 1fr)'
1416
+ : 'minmax(0, 1fr) 1px minmax(0, 1fr)';
1417
+ return {
1418
+ template: gridShorthand(areas, rows, cols),
1419
+ dividers: [
1420
+ { area: 'dHR', orientation: 'h' },
1421
+ { area: 'dEV', orientation: 'v' },
1422
+ ],
1423
+ };
1424
+ }
1425
+ const onlyBottom = showsExp ? 'exp' : 'cvv';
1426
+ const areas = hasIcon
1427
+ ? `"icon card" "dHR dHR" "${onlyBottom} ${onlyBottom}"`
1428
+ : `"card" "dHR" "${onlyBottom}"`;
1429
+ const cols = hasIcon ? 'auto minmax(0, 1fr)' : 'minmax(0, 1fr)';
1430
+ return {
1431
+ template: gridShorthand(areas, rows, cols),
1432
+ dividers: [{ area: 'dHR', orientation: 'h' }],
1433
+ };
1434
+ }
1435
+ /**
1436
+ * Compose a `grid-template` shorthand from a multi-row areas string, a matching
1437
+ * row-size list, and the column list — e.g. `"a" "b" 3rem 1px / 1fr`.
1438
+ */
1439
+ function gridShorthand(areas, rows, cols) {
1440
+ const areaRows = areas.match(/"[^"]*"/g) ?? [];
1441
+ const rowSizes = rows.split(/\s+/);
1442
+ const withRowSizes = areaRows
1443
+ .map((row, i) => `${row} ${rowSizes[i] ?? ''}`.trim())
1444
+ .join(' ');
1445
+ return `${withRowSizes} / ${cols}`;
1446
+ }
1447
+ /** Resolve the full layout (templates + breakpoint + areas) for a config. */
1448
+ function buildCardEntryLayout({ inputs, hasIcon = false, allowTwoRow = true, }) {
1449
+ const fieldAreas = inputs.map(name => FIELD_AREA[name]);
1450
+ // A lone field fills the width and never reflows (matches the real form's
1451
+ // single-input case — the fixed slot width and the icon are ignored).
1452
+ if (inputs.length === 1) {
1453
+ return {
1454
+ inline: `"${fieldAreas[0]}" ${CARD_ENTRY_ROW_HEIGHT} / 1fr`,
1455
+ twoRow: null,
1456
+ breakpointPx: null,
1457
+ fieldAreas,
1458
+ hasIconArea: false,
1459
+ twoRowDividers: [],
1460
+ };
1461
+ }
1462
+ const hasIconArea = hasIcon && has(inputs, 'card-number');
1463
+ const inline = inlineTemplate({ inputs, hasIcon: hasIconArea });
1464
+ const twoRow = allowTwoRow
1465
+ ? twoRowTemplate({ inputs, hasIcon: hasIconArea })
1466
+ : null;
1467
+ return {
1468
+ inline,
1469
+ twoRow: twoRow?.template ?? null,
1470
+ breakpointPx: twoRow
1471
+ ? minRowWidthPx(inputs) + 2 * CARD_ENTRY_BORDER_PX
1472
+ : null,
1473
+ fieldAreas,
1474
+ hasIconArea,
1475
+ twoRowDividers: twoRow?.dividers ?? [],
1476
+ };
1477
+ }
1478
+ /**
1479
+ * Container-query CSS that switches `gridSelector` between the inline and
1480
+ * two-row templates at the layout's breakpoint. The element matched by
1481
+ * `gridSelector` must be a descendant of a `container-type: inline-size`
1482
+ * ancestor named `containerName`.
1483
+ *
1484
+ * `extraBaseRules` are emitted before the `@container` block (e.g. the default
1485
+ * hidden state of two-row-only dividers); `extraCompactRules` are emitted inside
1486
+ * it (e.g. revealing those dividers / hiding wide-only chrome). Keeping the base
1487
+ * state first ensures the compact rules win when the query matches.
1488
+ */
1489
+ function buildCardEntryGridCss({ gridSelector, layout, containerName, extraBaseRules = '', extraCompactRules = '', }) {
1490
+ const base = `${gridSelector} { display: grid; grid-template: ${layout.inline}; }
1491
+ ${extraBaseRules}`;
1492
+ if (!layout.twoRow || layout.breakpointPx === null)
1493
+ return base;
1494
+ const container = containerName ? `${containerName} ` : '';
1495
+ return `${base}
1496
+ @container ${container}(width < ${layout.breakpointPx}px) {
1497
+ ${gridSelector} { grid-template: ${layout.twoRow}; }
1498
+ ${extraCompactRules}
1499
+ }`;
1500
+ }
1501
+
1502
+ /**
1503
+ * Framework-agnostic definitions for the V2 card-form skeleton loader.
1504
+ *
1505
+ * The React, Vue, and Angular libraries all render the same skeleton while the
1506
+ * card-form iframe loads. The grid templates and breakpoint come from the shared
1507
+ * {@link buildCardEntryLayout} — the SAME source of truth the real form uses —
1508
+ * so the skeleton reflows at exactly the width the loaded form does. Only the
1509
+ * box styling and per-framework wiring live here.
1510
+ */
1511
+ /** Which fields each iframe variant mounts. */
1512
+ const VARIANT_INPUTS = {
1513
+ 'card-form': ['card-number', 'expiration', 'cvv'],
1514
+ 'card-number-form': ['card-number', 'expiration'],
1515
+ 'cvv-form': ['cvv'],
1516
+ };
1517
+ // The iframe skeletons render without the optional card-brand icon.
1518
+ const CARD_ENTRY_LAYOUTS = {
1519
+ 'card-form': buildCardEntryLayout({ inputs: VARIANT_INPUTS['card-form'] }),
1520
+ 'card-number-form': buildCardEntryLayout({
1521
+ inputs: VARIANT_INPUTS['card-number-form'],
1522
+ }),
1523
+ 'cvv-form': buildCardEntryLayout({ inputs: VARIANT_INPUTS['cvv-form'] }),
1524
+ };
1525
+ // Iframe height (px) to guess before it reports its real height. Matches the
1526
+ // form's rendered height so the skeleton→form swap doesn't jump: field row(s) +
1527
+ // the 1px border and the box's `m-0.5` margin on top and bottom.
1528
+ const CARD_ENTRY_VERTICAL_CHROME_PX = 2 * CARD_ENTRY_BORDER_PX + 2 * CARD_ENTRY_MARGIN_PX;
1529
+ const INLINE_SKELETON_HEIGHT_PX = CARD_ENTRY_ROW_HEIGHT_PX + CARD_ENTRY_VERTICAL_CHROME_PX;
1530
+ /** Two-row layouts are a second field row plus the 1px divider taller. */
1531
+ const COMPACT_SKELETON_HEIGHT_PX = 2 * CARD_ENTRY_ROW_HEIGHT_PX +
1532
+ CARD_ENTRY_DIVIDER_PX +
1533
+ CARD_ENTRY_VERTICAL_CHROME_PX;
1534
+ function toSkeletonLayout(layout) {
1535
+ return {
1536
+ inline: layout.inline,
1537
+ compact: layout.twoRow ?? undefined,
1538
+ compactMaxWidthPx: layout.breakpointPx ?? undefined,
1539
+ areas: layout.fieldAreas,
1540
+ };
1541
+ }
1542
+ const SKELETON_LAYOUTS = {
1543
+ 'card-form': toSkeletonLayout(CARD_ENTRY_LAYOUTS['card-form']),
1544
+ 'card-number-form': toSkeletonLayout(CARD_ENTRY_LAYOUTS['card-number-form']),
1545
+ 'cvv-form': toSkeletonLayout(CARD_ENTRY_LAYOUTS['cvv-form']),
1546
+ };
1547
+ /** Name of the shared pulse keyframes; referenced by the box `animation`. */
1548
+ const SKELETON_PULSE_ANIMATION_NAME = 'coinflow-card-form-skeleton-pulse';
1549
+ /**
1550
+ * Duration (ms) of the skeleton's opacity fade-out. Matches the `opacity 300ms`
1551
+ * transition each renderer applies. Renderers unmount the skeleton on
1552
+ * `transitionend`, but that event can be skipped (reduced-motion, an ancestor
1553
+ * `display:none`, or opacity already 0) — so they also use this as a fallback
1554
+ * timeout to force the unmount and avoid a stuck (invisible) skeleton.
1555
+ */
1556
+ const SKELETON_FADE_MS = 300;
1557
+ /**
1558
+ * Whether the given container width would trigger the variant's two-row layout.
1559
+ * Mirrors the real form's container query (`width < breakpoint`). Variants
1560
+ * without a two-row layout never reflow.
1561
+ */
1562
+ function shouldStackSkeleton({ variant, width, }) {
1563
+ const { compact, compactMaxWidthPx } = SKELETON_LAYOUTS[variant];
1564
+ return (compact !== undefined &&
1565
+ compactMaxWidthPx !== undefined &&
1566
+ width > 0 &&
1567
+ width < compactMaxWidthPx);
1568
+ }
1569
+ /**
1570
+ * Height to guess before the iframe reports its real height. The two-row layout
1571
+ * is a field row plus divider taller than the inline one.
1572
+ */
1573
+ function guessSkeletonHeightPx({ variant, width, }) {
1574
+ return shouldStackSkeleton({ variant, width })
1575
+ ? COMPACT_SKELETON_HEIGHT_PX
1576
+ : INLINE_SKELETON_HEIGHT_PX;
1577
+ }
1578
+ /**
1579
+ * The `grid-template` to apply for the given container width. Frameworks that
1580
+ * drive the layout from JS (Vue, Angular) call this from their resize observer;
1581
+ * React instead injects a CSS container query via {@link buildSkeletonCss}.
1582
+ */
1583
+ function getSkeletonGridTemplate({ variant, width, }) {
1584
+ const { inline, compact } = SKELETON_LAYOUTS[variant];
1585
+ if (compact && shouldStackSkeleton({ variant, width }))
1586
+ return compact;
1587
+ return inline;
1588
+ }
1589
+ /** Stable class name for a variant's skeleton grid element. */
1590
+ function getSkeletonGridClass(variant) {
1591
+ return `coinflow-card-form-skeleton-grid--${variant}`;
1592
+ }
1593
+ /**
1594
+ * CSS (keyframes + grid + container-query breakpoint) for the container-query
1595
+ * driven renderer used by React, where the skeleton root is a query container.
1596
+ */
1597
+ function buildSkeletonCss(variant) {
1598
+ const gridClass = getSkeletonGridClass(variant);
1599
+ const grid = buildCardEntryGridCss({
1600
+ gridSelector: `.${gridClass}`,
1601
+ layout: CARD_ENTRY_LAYOUTS[variant],
1602
+ extraBaseRules: `.${gridClass} { gap: 0; flex: 1; }`,
1603
+ });
1604
+ return `@keyframes ${SKELETON_PULSE_ANIMATION_NAME} {0%,100%{opacity:1}50%{opacity:0.4}}
1605
+ ${grid}`;
1606
+ }
1607
+ /**
1608
+ * Padding (px) to inset the skeleton grid by, applied on the skeleton root. It
1609
+ * equals the form's own chrome — its `m-0.5` margin plus 1px border — so the
1610
+ * boxes land in the same area the real fields will, and the grid fills the root
1611
+ * exactly (no dead space that would make the boxes look too short).
1612
+ */
1613
+ const SKELETON_ROOT_PADDING_PX = CARD_ENTRY_MARGIN_PX + CARD_ENTRY_BORDER_PX;
1614
+ /**
1615
+ * Inline style for each skeleton box, MINUS the `background` — the fill color is
1616
+ * theme-dependent (see {@link getSkeletonColors}) so each renderer merges it in.
1617
+ * A hairline margin keeps a subtle gap between boxes while letting them fill
1618
+ * nearly the full field height (the root padding handles the outer inset). Uses
1619
+ * string units so it renders identically in React, Vue, and Angular.
1620
+ */
1621
+ const SKELETON_BOX_STYLE = {
1622
+ minWidth: '0',
1623
+ margin: '1px',
1624
+ borderRadius: '4px',
1625
+ opacity: '1',
1626
+ animation: `${SKELETON_PULSE_ANIMATION_NAME} 1.5s ease-in-out infinite`,
1627
+ };
1628
+ // Dark surface → light skeleton; light surface → dark skeleton (the original
1629
+ // look); unknown → a neutral mid-grey that reads on either.
1630
+ const DARK_SURFACE_COLORS = {
1631
+ backdrop: 'rgba(255, 255, 255, 0.05)',
1632
+ box: 'rgba(255, 255, 255, 0.30)',
1633
+ };
1634
+ const LIGHT_SURFACE_COLORS = {
1635
+ backdrop: 'rgba(0, 0, 0, 0.04)',
1636
+ box: 'rgba(0, 0, 0, 0.30)',
1637
+ };
1638
+ const NEUTRAL_COLORS = {
1639
+ backdrop: 'rgba(128, 128, 128, 0.08)',
1640
+ box: 'rgba(128, 128, 128, 0.38)',
1641
+ };
1642
+ /** Parse a hex (#rgb/#rrggbb/#rrggbbaa) or rgb()/rgba() string to [r,g,b]. */
1643
+ function parseRgb(color) {
1644
+ const c = color.trim().toLowerCase();
1645
+ let hex = c.startsWith('#') ? c.slice(1) : '';
1646
+ if (hex && /^[0-9a-f]+$/.test(hex)) {
1647
+ if (hex.length === 3)
1648
+ hex = hex
1649
+ .split('')
1650
+ .map(x => x + x)
1651
+ .join('');
1652
+ if (hex.length === 8)
1653
+ hex = hex.slice(0, 6);
1654
+ if (hex.length === 6)
1655
+ return [
1656
+ parseInt(hex.slice(0, 2), 16),
1657
+ parseInt(hex.slice(2, 4), 16),
1658
+ parseInt(hex.slice(4, 6), 16),
1659
+ ];
1660
+ }
1661
+ const m = c.match(/rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)/);
1662
+ if (m)
1663
+ return [Number(m[1]), Number(m[2]), Number(m[3])];
1664
+ return null;
1665
+ }
1666
+ /**
1667
+ * Best-effort skeleton palette. The skeleton renders in the SDK (parent), so it
1668
+ * can't see the form's resolved colors — it only has the optional `theme` the
1669
+ * integrator passed. When `theme.background` is a parseable color we tint the
1670
+ * skeleton light-on-dark or dark-on-light to match; otherwise we fall back to a
1671
+ * neutral mid-grey that stays visible on any surface.
1672
+ */
1673
+ function getSkeletonColors(theme) {
1674
+ const rgb = theme?.background ? parseRgb(theme.background) : null;
1675
+ if (!rgb)
1676
+ return NEUTRAL_COLORS;
1677
+ const [r, g, b] = rgb;
1678
+ const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
1679
+ return luminance < 0.5 ? DARK_SURFACE_COLORS : LIGHT_SURFACE_COLORS;
1680
+ }
1681
+
1682
+ const CARD_FIELD_ERROR_MESSAGES = {
1683
+ cardNumber: 'Card number is invalid. Please double check information.',
1684
+ expiration: 'Expiration is invalid. Please double check information.',
1685
+ cvv: 'CVV is invalid. Please double check information.',
1686
+ cvvEmpty: 'Please enter your CVV to proceed.',
1687
+ };
1688
+ function getCardFieldValidationError({ cardError, expirationError, cvvError, cvvEmpty, isCvvOnly, }) {
1689
+ if (cardError)
1690
+ return {
1691
+ field: 'card-number',
1692
+ message: CARD_FIELD_ERROR_MESSAGES.cardNumber,
1693
+ };
1694
+ if (expirationError)
1695
+ return {
1696
+ field: 'expiration',
1697
+ message: CARD_FIELD_ERROR_MESSAGES.expiration,
1698
+ };
1699
+ if (!cvvError)
1700
+ return null;
1701
+ if (isCvvOnly && cvvEmpty)
1702
+ return { field: 'cvv', message: CARD_FIELD_ERROR_MESSAGES.cvvEmpty };
1703
+ return { field: 'cvv', message: CARD_FIELD_ERROR_MESSAGES.cvv };
1704
+ }
1705
+ /**
1706
+ * Derives which messages to emit for a transition between two validation
1707
+ * states, so the parent hears about each change exactly once.
1708
+ *
1709
+ * Nothing is emitted while the state is unchanged (including the pristine
1710
+ * state, where both sides are null), so a field that is never invalid stays
1711
+ * silent and a visible error is not re-sent on every render.
1712
+ *
1713
+ * Only one error is displayed at a time (see getCardFieldValidationError's
1714
+ * precedence), so when the displayed error moves to a different field the
1715
+ * previous field has necessarily become valid and gets its own clear event.
1716
+ */
1717
+ function getCardFieldInputEvents({ previous, current, }) {
1718
+ if (!current)
1719
+ return previous ? [{ kind: 'valid', info: { field: previous.field } }] : [];
1720
+ if (!previous)
1721
+ return [{ kind: 'error', info: current }];
1722
+ if (previous.field === current.field)
1723
+ return previous.message === current.message
1724
+ ? []
1725
+ : [{ kind: 'error', info: current }];
1726
+ return [
1727
+ { kind: 'valid', info: { field: previous.field } },
1728
+ { kind: 'error', info: current },
1729
+ ];
1730
+ }
1731
+
1273
1732
  /* generated using openapi-typescript-codegen -- do no edit */
1274
1733
  /* istanbul ignore file */
1275
1734
  /* tslint:disable */
@@ -1542,6 +2001,47 @@ async function initCoinflowProtection({ coinflowEnv, merchantId, }) {
1542
2001
  }
1543
2002
  }
1544
2003
 
2004
+ function serializeCachedLinkToken(cached) {
2005
+ return JSON.stringify(cached);
2006
+ }
2007
+ /**
2008
+ * Reads a cache entry, tolerating the bare-token strings written before the
2009
+ * country was recorded. Those have unknown provenance, so they come back with
2010
+ * no country and `canReuseLinkToken` will refuse them for a specific rail.
2011
+ */
2012
+ function parseCachedLinkToken(raw) {
2013
+ if (!raw)
2014
+ return null;
2015
+ try {
2016
+ const parsed = JSON.parse(raw);
2017
+ if (typeof parsed?.token !== 'string' || !parsed.token)
2018
+ return null;
2019
+ return {
2020
+ token: parsed.token,
2021
+ country: typeof parsed.country === 'string' ? parsed.country : undefined,
2022
+ };
2023
+ }
2024
+ catch {
2025
+ // Legacy entry: the raw token with no recorded country.
2026
+ return { token: raw };
2027
+ }
2028
+ }
2029
+ /**
2030
+ * True when a cached token may be handed to a session for `country`.
2031
+ *
2032
+ * A caller that names a country needs a token minted for that same country;
2033
+ * anything else (a different rail, or an entry whose rail we never recorded)
2034
+ * has to be re-minted. A caller that names no country takes what is cached,
2035
+ * which is what the OAuth leg does when resuming a session already in flight.
2036
+ */
2037
+ function canReuseLinkToken({ cached, country, }) {
2038
+ if (!cached)
2039
+ return false;
2040
+ if (!country)
2041
+ return true;
2042
+ return cached.country === country;
2043
+ }
2044
+
1545
2045
  class CoinflowIFrameComponent {
1546
2046
  constructor(sanitizer) {
1547
2047
  this.sanitizer = sanitizer;
@@ -1985,17 +2485,112 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImpo
1985
2485
  }] } });
1986
2486
 
1987
2487
  class CoinflowCardForm {
1988
- constructor(sanitizer) {
2488
+ constructor(sanitizer, zone) {
1989
2489
  this.sanitizer = sanitizer;
2490
+ this.zone = zone;
1990
2491
  this.loaded = false;
1991
2492
  this.iframeHeight = null;
2493
+ this.areas = [];
2494
+ this.guessHeight = INLINE_SKELETON_HEIGHT_PX;
2495
+ this.gridTemplate = '';
2496
+ // Keep the skeleton mounted while it fades out so the opacity transition can
2497
+ // play, then unmount on transition end. Remount instantly when shown again.
2498
+ this.rendered = true;
2499
+ this.observer = null;
2500
+ this.unmountTimer = null;
1992
2501
  }
1993
2502
  ngOnInit() {
2503
+ this.layout = SKELETON_LAYOUTS[this.args.variant];
2504
+ this.areas = this.layout.areas;
2505
+ this.gridTemplate = this.layout.inline;
1994
2506
  this.buildUrl();
2507
+ this.observeWidth();
2508
+ }
2509
+ ngOnDestroy() {
2510
+ this.observer?.disconnect();
2511
+ if (this.unmountTimer)
2512
+ clearTimeout(this.unmountTimer);
2513
+ }
2514
+ get height() {
2515
+ return this.loaded && this.iframeHeight
2516
+ ? `${this.iframeHeight}px`
2517
+ : `${this.guessHeight}px`;
2518
+ }
2519
+ get skeletonRootStyle() {
2520
+ return {
2521
+ position: 'absolute',
2522
+ top: 0,
2523
+ left: 0,
2524
+ width: '100%',
2525
+ height: '100%',
2526
+ display: 'flex',
2527
+ pointerEvents: 'none',
2528
+ flexDirection: 'column',
2529
+ gap: '8px',
2530
+ padding: `${SKELETON_ROOT_PADDING_PX}px`,
2531
+ boxSizing: 'border-box',
2532
+ borderRadius: '8px',
2533
+ background: this.skeletonColors.backdrop,
2534
+ opacity: this.loaded ? '0%' : '100%',
2535
+ transition: 'opacity 300ms linear, height 150ms ease-out',
2536
+ };
2537
+ }
2538
+ get gridStyle() {
2539
+ return {
2540
+ display: 'grid',
2541
+ gap: 0,
2542
+ flex: 1,
2543
+ width: '100%',
2544
+ gridTemplate: this.gridTemplate,
2545
+ };
2546
+ }
2547
+ // Best-effort skeleton tint from the merchant theme's background (neutral when
2548
+ // absent), so the loader reads on light and dark forms alike.
2549
+ get skeletonColors() {
2550
+ return getSkeletonColors(this.args.theme);
2551
+ }
2552
+ boxStyle(area) {
2553
+ return {
2554
+ ...SKELETON_BOX_STYLE,
2555
+ background: this.skeletonColors.box,
2556
+ gridArea: area,
2557
+ };
1995
2558
  }
1996
2559
  onMessage(event) {
2560
+ // Only honor messages from THIS instance's iframe. Multiple card forms on
2561
+ // one page each listen on `window`, so without this every instance would
2562
+ // apply every other iframe's height/loaded events to itself.
2563
+ if (event.source !== this.iframeRef?.nativeElement?.contentWindow)
2564
+ return;
1997
2565
  this.handleMessage(event.data, event.origin);
1998
2566
  }
2567
+ onSkeletonTransitionEnd(e) {
2568
+ if (e.propertyName === 'opacity' && this.loaded)
2569
+ this.rendered = false;
2570
+ }
2571
+ observeWidth() {
2572
+ // Measure the wrapper div, not the iframe: a freshly-mounted <iframe> is a
2573
+ // replaced element with an intrinsic 300px default width before its
2574
+ // width:100% resolves, which would briefly (and wrongly) trip the compact
2575
+ // breakpoint. A block div reports the true container width immediately.
2576
+ const el = this.wrapperRef?.nativeElement;
2577
+ if (!el || !this.layout.compact)
2578
+ return;
2579
+ const measure = () => {
2580
+ const width = el.clientWidth;
2581
+ this.guessHeight = guessSkeletonHeightPx({
2582
+ variant: this.args.variant,
2583
+ width,
2584
+ });
2585
+ this.gridTemplate = getSkeletonGridTemplate({
2586
+ variant: this.args.variant,
2587
+ width,
2588
+ });
2589
+ };
2590
+ measure();
2591
+ this.observer = new ResizeObserver(() => this.zone.run(measure));
2592
+ this.observer.observe(el);
2593
+ }
1999
2594
  buildUrl() {
2000
2595
  const baseUrl = CoinflowUtils.getCoinflowBaseUrl(this.args.env);
2001
2596
  const iframeUrl = new URL(`/form/v2/${this.args.variant}`, baseUrl);
@@ -2018,6 +2613,14 @@ class CoinflowCardForm {
2018
2613
  if (parsed.method === IFrameMessageMethods.Loaded) {
2019
2614
  this.loaded = true;
2020
2615
  this.args.onLoad?.();
2616
+ // Fallback unmount: `transitionend` may never fire (reduced-motion, an
2617
+ // ancestor display:none, or opacity already 0), so force cleanup after
2618
+ // the fade window.
2619
+ if (this.unmountTimer)
2620
+ clearTimeout(this.unmountTimer);
2621
+ this.unmountTimer = setTimeout(() => {
2622
+ this.zone.run(() => (this.rendered = false));
2623
+ }, SKELETON_FADE_MS);
2021
2624
  }
2022
2625
  else if (parsed.method === IFrameMessageMethods.HeightChange) {
2023
2626
  const parsedHeight = Number(parsed.data);
@@ -2025,6 +2628,12 @@ class CoinflowCardForm {
2025
2628
  this.iframeHeight = parsedHeight;
2026
2629
  }
2027
2630
  }
2631
+ else if (parsed.method === IFrameMessageMethods.InputError) {
2632
+ void this.args.onInputError?.(parsed.info);
2633
+ }
2634
+ else if (parsed.method === IFrameMessageMethods.InputValid) {
2635
+ void this.args.onInputValid?.(parsed.info);
2636
+ }
2028
2637
  }
2029
2638
  catch {
2030
2639
  // not JSON
@@ -2066,44 +2675,84 @@ class CoinflowCardForm {
2066
2675
  iframe.contentWindow.postMessage('tokenize', targetOrigin);
2067
2676
  });
2068
2677
  }
2069
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: CoinflowCardForm, deps: [{ token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Component }); }
2070
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.10", type: CoinflowCardForm, isStandalone: true, selector: "lib-coinflow-card-form", inputs: { args: "args" }, host: { listeners: { "window:message": "onMessage($event)" } }, viewQueries: [{ propertyName: "iframeRef", first: true, predicate: ["cardFormIframe"], descendants: true, static: true }], ngImport: i0, template: `<iframe
2071
- #cardFormIframe
2072
- [src]="url"
2073
- title="Card Form"
2074
- frameBorder="0"
2075
- allow="payment"
2678
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: CoinflowCardForm, deps: [{ token: i1.DomSanitizer }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); }
2679
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.10", type: CoinflowCardForm, isStandalone: true, selector: "lib-coinflow-card-form", inputs: { args: "args" }, host: { listeners: { "window:message": "onMessage($event)" } }, viewQueries: [{ propertyName: "iframeRef", first: true, predicate: ["cardFormIframe"], descendants: true, static: true }, { propertyName: "wrapperRef", first: true, predicate: ["wrapper"], descendants: true, static: true }], ngImport: i0, template: `<div
2680
+ #wrapper
2681
+ [style.position]="'relative'"
2076
2682
  [style.width]="'100%'"
2077
- [style.height]="iframeHeight ? iframeHeight + 'px' : '60px'"
2078
- [style.border]="'none'"
2079
- [style.opacity]="loaded ? 1 : 0"
2080
- [style.transition]="'opacity 300ms linear, height 150ms ease-out'"
2081
- ></iframe>`, isInline: true }); }
2683
+ [style.height]="height"
2684
+ >
2685
+ @if (rendered) {
2686
+ <div
2687
+ role="status"
2688
+ aria-label="Loading card form"
2689
+ (transitionend)="onSkeletonTransitionEnd($event)"
2690
+ [ngStyle]="skeletonRootStyle"
2691
+ >
2692
+ <div [ngStyle]="gridStyle">
2693
+ @for (area of areas; track area) {
2694
+ <div [ngStyle]="boxStyle(area)"></div>
2695
+ }
2696
+ </div>
2697
+ </div>
2698
+ }
2699
+ <iframe
2700
+ #cardFormIframe
2701
+ [src]="url"
2702
+ title="Card Form"
2703
+ frameBorder="0"
2704
+ allow="payment"
2705
+ [style.width]="'100%'"
2706
+ [style.height]="height"
2707
+ [style.border]="'none'"
2708
+ [style.opacity]="loaded ? 1 : 0"
2709
+ [style.transition]="'opacity 300ms linear, height 150ms ease-out'"
2710
+ ></iframe>
2711
+ </div>`, isInline: true, styles: ["@keyframes coinflow-card-form-skeleton-pulse{0%,to{opacity:1}50%{opacity:.4}}\n"], dependencies: [{ kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] }); }
2082
2712
  }
2083
2713
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: CoinflowCardForm, decorators: [{
2084
2714
  type: Component,
2085
- args: [{
2086
- selector: 'lib-coinflow-card-form',
2087
- standalone: true,
2088
- imports: [],
2089
- template: `<iframe
2090
- #cardFormIframe
2091
- [src]="url"
2092
- title="Card Form"
2093
- frameBorder="0"
2094
- allow="payment"
2715
+ args: [{ selector: 'lib-coinflow-card-form', standalone: true, imports: [NgStyle], template: `<div
2716
+ #wrapper
2717
+ [style.position]="'relative'"
2095
2718
  [style.width]="'100%'"
2096
- [style.height]="iframeHeight ? iframeHeight + 'px' : '60px'"
2097
- [style.border]="'none'"
2098
- [style.opacity]="loaded ? 1 : 0"
2099
- [style.transition]="'opacity 300ms linear, height 150ms ease-out'"
2100
- ></iframe>`,
2101
- }]
2102
- }], ctorParameters: () => [{ type: i1.DomSanitizer }], propDecorators: { args: [{
2719
+ [style.height]="height"
2720
+ >
2721
+ @if (rendered) {
2722
+ <div
2723
+ role="status"
2724
+ aria-label="Loading card form"
2725
+ (transitionend)="onSkeletonTransitionEnd($event)"
2726
+ [ngStyle]="skeletonRootStyle"
2727
+ >
2728
+ <div [ngStyle]="gridStyle">
2729
+ @for (area of areas; track area) {
2730
+ <div [ngStyle]="boxStyle(area)"></div>
2731
+ }
2732
+ </div>
2733
+ </div>
2734
+ }
2735
+ <iframe
2736
+ #cardFormIframe
2737
+ [src]="url"
2738
+ title="Card Form"
2739
+ frameBorder="0"
2740
+ allow="payment"
2741
+ [style.width]="'100%'"
2742
+ [style.height]="height"
2743
+ [style.border]="'none'"
2744
+ [style.opacity]="loaded ? 1 : 0"
2745
+ [style.transition]="'opacity 300ms linear, height 150ms ease-out'"
2746
+ ></iframe>
2747
+ </div>`, styles: ["@keyframes coinflow-card-form-skeleton-pulse{0%,to{opacity:1}50%{opacity:.4}}\n"] }]
2748
+ }], ctorParameters: () => [{ type: i1.DomSanitizer }, { type: i0.NgZone }], propDecorators: { args: [{
2103
2749
  type: Input
2104
2750
  }], iframeRef: [{
2105
2751
  type: ViewChild,
2106
2752
  args: ['cardFormIframe', { static: true }]
2753
+ }], wrapperRef: [{
2754
+ type: ViewChild,
2755
+ args: ['wrapper', { static: true }]
2107
2756
  }], onMessage: [{
2108
2757
  type: HostListener,
2109
2758
  args: ['window:message', ['$event']]
@@ -2115,6 +2764,10 @@ class CoinflowMobileWalletButtonComponent {
2115
2764
  constructor() {
2116
2765
  this.opacity = 0.8;
2117
2766
  this.display = 'flex';
2767
+ // The subtotal is pinned to its initial value in the iframe URL (built once
2768
+ // in ngOnInit) so amount changes don't force a reload. Updates are instead
2769
+ // sent to the running iframe via postMessage once it has loaded.
2770
+ this.loaded = false;
2118
2771
  }
2119
2772
  handleMessage({ data }) {
2120
2773
  try {
@@ -2129,11 +2782,38 @@ class CoinflowMobileWalletButtonComponent {
2129
2782
  setTimeout(() => {
2130
2783
  this.display = 'none';
2131
2784
  }, 2000);
2785
+ this.loaded = true;
2786
+ if (this.pendingSubtotal) {
2787
+ const pendingSubtotal = this.pendingSubtotal;
2788
+ this.pendingSubtotal = undefined;
2789
+ this.sendSubtotalUpdate(pendingSubtotal);
2790
+ }
2132
2791
  }
2133
2792
  }
2134
2793
  catch (e) { }
2135
2794
  }
2795
+ ngOnChanges(changes) {
2796
+ const purchasePropsChange = changes['purchaseProps'];
2797
+ if (!purchasePropsChange || purchasePropsChange.firstChange)
2798
+ return;
2799
+ const subtotal = purchasePropsChange.currentValue?.subtotal;
2800
+ if (!subtotal)
2801
+ return;
2802
+ this.sendSubtotalUpdate(subtotal);
2803
+ }
2804
+ sendSubtotalUpdate(subtotal) {
2805
+ if (!this.loaded) {
2806
+ this.pendingSubtotal = subtotal;
2807
+ return;
2808
+ }
2809
+ const serializedSubtotal = JSON.stringify(subtotal);
2810
+ if (this.lastSentSubtotal === serializedSubtotal)
2811
+ return;
2812
+ this.lastSentSubtotal = serializedSubtotal;
2813
+ this.iframeComponent?.sendMessage(`${IFrameMessageMethods.UpdateSubtotal}:${serializedSubtotal}`);
2814
+ }
2136
2815
  ngOnInit() {
2816
+ this.lastSentSubtotal = JSON.stringify(this.purchaseProps?.subtotal);
2137
2817
  const walletPubkey = getWalletPubkey(this.purchaseProps);
2138
2818
  this.messageHandlers = getHandlers(this.purchaseProps);
2139
2819
  this.messageHandlers.handleHeightChange =
@@ -2149,7 +2829,7 @@ class CoinflowMobileWalletButtonComponent {
2149
2829
  };
2150
2830
  }
2151
2831
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: CoinflowMobileWalletButtonComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
2152
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.10", type: CoinflowMobileWalletButtonComponent, isStandalone: true, selector: "lib-coinflow-mobile-wallet-button", inputs: { purchaseProps: "purchaseProps", route: "route", overlayDisplayOverride: "overlayDisplayOverride", alignItems: "alignItems" }, ngImport: i0, template: ` <div style="position: relative; height: 100%;">
2832
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.10", type: CoinflowMobileWalletButtonComponent, isStandalone: true, selector: "lib-coinflow-mobile-wallet-button", inputs: { purchaseProps: "purchaseProps", route: "route", overlayDisplayOverride: "overlayDisplayOverride", alignItems: "alignItems" }, viewQueries: [{ propertyName: "iframeComponent", first: true, predicate: CoinflowIFrameComponent, descendants: true }], usesOnChanges: true, ngImport: i0, template: ` <div style="position: relative; height: 100%;">
2153
2833
  <div
2154
2834
  [style.background-color]="purchaseProps.color"
2155
2835
  [style.display]="overlayDisplayOverride ?? display"
@@ -2207,6 +2887,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImpo
2207
2887
  type: Input
2208
2888
  }], alignItems: [{
2209
2889
  type: Input
2890
+ }], iframeComponent: [{
2891
+ type: ViewChild,
2892
+ args: [CoinflowIFrameComponent]
2210
2893
  }] } });
2211
2894
 
2212
2895
  class CoinflowApplePayButtonComponent {
@@ -2477,5 +3160,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImpo
2477
3160
  * Generated bundle index. Do not edit.
2478
3161
  */
2479
3162
 
2480
- export { BankingCurrencies, CARD_TYPE_MAPPING, CardType, ChargebackProtectionAccountType, CoinflowApplePayButtonComponent, CoinflowCardForm, CoinflowCardFormV2, CoinflowCardNumberInput, CoinflowCardNumberOnlyInput, CoinflowCvvInputComponent, CoinflowCvvOnlyInputComponent, CoinflowGooglePayButtonComponent, CoinflowIFrameComponent, CoinflowPurchaseComponent, CoinflowPurchaseHistoryComponent, CoinflowPurchaseProtectionComponent, CoinflowUtils, CoinflowWithdrawComponent, CoinflowWithdrawHistoryComponent, Currency, CurrencyToISO4217, DEVICE_ID_HEADER, EventBus, FORTER_TOKEN_HEADER, IFrameMessageMethods, MerchantStyle, PaymentMethods, REFERRER_HEADER, RN_REDIRECT_MESSAGE_NAME, SESSION_ID_HEADER, SettlementType, ThreeDsChallengePreference, TokenExCardNumberIframeId, TokenExCvvContainerID, WithdrawCategory, WithdrawCurrencies, WithdrawSpeed, awaitForterToken, captureForterToken, doInitializeCvvOnlyTokenExIframe, doInitializeTokenExCardOnlyIframe, doInitializeTokenExIframe, getCoinflowProtectionHeaders, getCoinflowPurchaseHeaders, getCurrencyDecimals, getCustomerName, getForterToken, getHandlers, getIframeConfig, getWalletPubkey, handleIFrameMessage, initCoinflowProtection, invertRate, isBankingCurrency, isTypedCurrencyCents, isWithdrawCurrency, isZeroAuthSavedPaymentMethods, isZeroAuthVerifyCard, nftCartItem, paymentMethodLabels, recordFrontendError, setTokenExScriptTag };
3163
+ export { BankingCurrencies, CARD_ENTRY_BORDER_PX, CARD_ENTRY_DIVIDER_PX, CARD_ENTRY_MARGIN_PX, CARD_ENTRY_MIN_WIDTHS, CARD_ENTRY_ROW_HEIGHT, CARD_ENTRY_ROW_HEIGHT_PX, CARD_ENTRY_SLOT_GAP_PX, CARD_FIELD_ERROR_MESSAGES, CARD_TYPE_MAPPING, COMPACT_SKELETON_HEIGHT_PX, CardType, ChargebackProtectionAccountType, CoinflowApplePayButtonComponent, CoinflowCardForm, CoinflowCardFormV2, CoinflowCardNumberInput, CoinflowCardNumberOnlyInput, CoinflowCvvInputComponent, CoinflowCvvOnlyInputComponent, CoinflowGooglePayButtonComponent, CoinflowIFrameComponent, CoinflowPurchaseComponent, CoinflowPurchaseHistoryComponent, CoinflowPurchaseProtectionComponent, CoinflowUtils, CoinflowWithdrawComponent, CoinflowWithdrawHistoryComponent, Currency, CurrencyToISO4217, DEVICE_ID_HEADER, EventBus, FORTER_TOKEN_HEADER, IFrameMessageMethods, INLINE_SKELETON_HEIGHT_PX, MerchantStyle, PaymentMethods, REFERRER_HEADER, RN_REDIRECT_MESSAGE_NAME, SESSION_ID_HEADER, SKELETON_BOX_STYLE, SKELETON_FADE_MS, SKELETON_LAYOUTS, SKELETON_PULSE_ANIMATION_NAME, SKELETON_ROOT_PADDING_PX, SettlementType, ThreeDsChallengePreference, TokenExCardNumberIframeId, TokenExCvvContainerID, WithdrawCategory, WithdrawCurrencies, WithdrawSpeed, awaitForterToken, buildCardEntryGridCss, buildCardEntryLayout, buildSkeletonCss, canReuseLinkToken, captureForterToken, doInitializeCvvOnlyTokenExIframe, doInitializeTokenExCardOnlyIframe, doInitializeTokenExIframe, getCardFieldInputEvents, getCardFieldValidationError, getCoinflowProtectionHeaders, getCoinflowPurchaseHeaders, getCurrencyDecimals, getCustomerName, getForterToken, getHandlers, getIframeConfig, getSkeletonColors, getSkeletonGridClass, getSkeletonGridTemplate, getWalletPubkey, guessSkeletonHeightPx, handleIFrameMessage, initCoinflowProtection, invertRate, isBankingCurrency, isTypedCurrencyCents, isWithdrawCurrency, isZeroAuthSavedPaymentMethods, isZeroAuthVerifyCard, nftCartItem, parseCachedLinkToken, paymentMethodLabels, recordFrontendError, serializeCachedLinkToken, setTokenExScriptTag, shouldStackSkeleton };
2481
3164
  //# sourceMappingURL=coinflowlabs-angular.mjs.map