@funkit/connect-rn 3.2.0 → 3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @funkit/connect-rn
2
2
 
3
+ ## 3.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3f8f25a: feat(connect-rn): support `prefillFiatEmail` on `FunkitConfig` to prefill the Swapped fiat ramp email
8
+
9
+ ### Patch Changes
10
+
11
+ - df4e7d8: fix: treat Bitcoin, Lightning and HyperCore consistently as non-EVM chains across web and RN
12
+ - ea114c9: fix(connect-rn): stop the Add money list flashing crypto-only on first open
13
+ - 340b63d: Internal refactor of the React Native forms-of-payment hook, no behavior change
14
+ - Updated dependencies [df4e7d8]
15
+ - Updated dependencies [4235f2f]
16
+ - @funkit/chains@2.2.0
17
+ - @funkit/connect-core@2.4.0
18
+
3
19
  ## 3.2.0
4
20
 
5
21
  ### Minor Changes
package/dist/index.js CHANGED
@@ -4074,30 +4074,23 @@ function SwappedWithdrawScreen({
4074
4074
  return /* @__PURE__ */ jsx23(SwappedScreenShell, { url, onMessage: handleMessage });
4075
4075
  }
4076
4076
 
4077
+ // src/flow/FunkitFlowProvider.tsx
4078
+ import { isEvmChainId as isEvmChainId2 } from "@funkit/connect-core";
4079
+
4077
4080
  // src/transfer/availableChains.ts
4078
- import {
4079
- bitcoinChain,
4080
- chainMetadataById,
4081
- solanaChain,
4082
- tronChain
4083
- } from "@funkit/chains";
4081
+ import { chainMetadataById } from "@funkit/chains";
4084
4082
  import {
4085
4083
  getConfiguredMinDepositUsd,
4086
- getMinTransferValueUsd
4084
+ getMinTransferValueUsd,
4085
+ isEvmChainId
4087
4086
  } from "@funkit/connect-core";
4088
- var NON_EVM_CHAIN_IDS = /* @__PURE__ */ new Set([
4089
- solanaChain.id,
4090
- tronChain.id,
4091
- bitcoinChain.id
4092
- ]);
4093
4087
  var EVM_NETWORK_ID = "evm";
4094
- function isNonEvmChainId(chainId) {
4095
- return NON_EVM_CHAIN_IDS.has(chainId);
4096
- }
4097
4088
  function belongsToNetwork(chainId, networkChainId) {
4098
4089
  if (networkChainId == null) return true;
4099
- if (NON_EVM_CHAIN_IDS.has(networkChainId)) return chainId === networkChainId;
4100
- return !NON_EVM_CHAIN_IDS.has(chainId);
4090
+ if (!isEvmChainId(networkChainId)) {
4091
+ return chainId === networkChainId;
4092
+ }
4093
+ return isEvmChainId(chainId);
4101
4094
  }
4102
4095
  function buildAvailableChains({
4103
4096
  t,
@@ -4125,7 +4118,7 @@ function buildAvailableChains({
4125
4118
  function buildDepositNetworks(t, chainFilters) {
4126
4119
  const chains = chainFilters.filter((f) => f.id !== "all").map((f) => ({ chainId: Number(f.id), label: f.label }));
4127
4120
  const iconUrl = (chainId) => chainMetadataById[chainId]?.iconUrl ?? FALLBACK_ASSET_LOGO;
4128
- const evmChains = chains.filter((c) => !isNonEvmChainId(c.chainId));
4121
+ const evmChains = chains.filter((c) => isEvmChainId(c.chainId));
4129
4122
  const networks = [];
4130
4123
  if (evmChains.length > 0) {
4131
4124
  networks.push({
@@ -4137,7 +4130,7 @@ function buildDepositNetworks(t, chainFilters) {
4137
4130
  });
4138
4131
  }
4139
4132
  for (const c of chains) {
4140
- if (!isNonEvmChainId(c.chainId)) continue;
4133
+ if (isEvmChainId(c.chainId)) continue;
4141
4134
  const meta = chainMetadataById[c.chainId];
4142
4135
  networks.push({
4143
4136
  id: String(c.chainId),
@@ -4224,11 +4217,12 @@ import {
4224
4217
  } from "@funkit/api-base";
4225
4218
  import {
4226
4219
  FUNKIT_CONNECT_CHECKOUT_NATIVE_CURRENCY_ADDRESS,
4227
- solanaChain as solanaChain2
4220
+ solanaChain
4228
4221
  } from "@funkit/chains";
4229
4222
  import {
4230
4223
  DEFAULT_FIAT_CURRENCY,
4231
4224
  FOPS_STALE_TIME,
4225
+ buildSwappedThirdPartyPaymentConfigs,
4232
4226
  getConfiguredMinDepositUsd as getConfiguredMinDepositUsd2,
4233
4227
  getDepositAddressForChain,
4234
4228
  getMinTransferValueEur,
@@ -4263,7 +4257,8 @@ function resolveFunkitIdentity(config, walletAddress) {
4263
4257
  apiKey: config.apiKey,
4264
4258
  userId,
4265
4259
  walletAddress: address,
4266
- loginType: config.loginType
4260
+ loginType: config.loginType,
4261
+ prefillFiatEmail: config.prefillFiatEmail
4267
4262
  };
4268
4263
  }
4269
4264
  var FunkitIdentityContext = createContext3(null);
@@ -4346,14 +4341,35 @@ function useFops({
4346
4341
  dynamicRoutingId,
4347
4342
  enabled = true
4348
4343
  }) {
4349
- const { apiKey, userId } = useFunkitIdentity();
4350
4344
  const isSwappedEnabled = !!useDynamicConfig("enableswappeddeposit");
4345
+ const input = useFopsQueryInput({
4346
+ checkoutConfig,
4347
+ dynamicRoutingId,
4348
+ enabled: enabled && isSwappedEnabled
4349
+ });
4350
+ const query = useDoFetchFops(input);
4351
+ const isLoading = isSwappedEnabled && (input.isDependencyLoading || input.enabled && query.isLoading);
4352
+ return {
4353
+ savedFops: query.data?.savedFormsOfPayments ?? [],
4354
+ genericFops: query.data?.genericFormsOfPayments ?? [],
4355
+ isLoading,
4356
+ isFetching: input.isTransferInitFetching,
4357
+ isError: query.isError,
4358
+ refetch: () => void query.refetch(),
4359
+ isSwappedEnabled
4360
+ };
4361
+ }
4362
+ function useFopsQueryInput({
4363
+ checkoutConfig,
4364
+ dynamicRoutingId,
4365
+ enabled
4366
+ }) {
4367
+ const { apiKey, userId, prefillFiatEmail } = useFunkitIdentity();
4351
4368
  const fopPriority = useDynamicConfig("foppriority");
4352
4369
  const { userIpInfo } = useUserIpInfo();
4353
- const countryCode = userIpInfo?.alpha2 || DEFAULT_COUNTRY_CODE;
4354
4370
  const {
4355
- data: swappedCurrencyCode = DEFAULT_FIAT_CURRENCY,
4356
- isLoading: isSwappedCurrencyCodeLoading
4371
+ data: fiatCurrencyCode = DEFAULT_FIAT_CURRENCY,
4372
+ isLoading: isFiatCurrencyCodeLoading
4357
4373
  } = useSwappedDefaultCurrencyQuery({
4358
4374
  apiKey,
4359
4375
  countryCode: userIpInfo?.alpha2,
@@ -4368,71 +4384,100 @@ function useFops({
4368
4384
  transferInit,
4369
4385
  isLoading: isTransferInitLoading,
4370
4386
  isFetching: isTransferInitFetching
4371
- } = useTransferInit({
4372
- checkoutConfig,
4373
- dynamicRoutingId,
4374
- enabled: enabled && isSwappedEnabled
4375
- });
4387
+ } = useTransferInit({ checkoutConfig, dynamicRoutingId, enabled });
4376
4388
  const targetAsset = checkoutConfig?.targetAsset;
4377
4389
  const targetChain = checkoutConfig?.targetChain;
4378
4390
  const recipientAddress = targetChain ? getDepositAddressForChain(Number(targetChain), transferInit) : void 0;
4391
+ const { defaultMinAmount, isLoading: isExchangeRatesLoading } = useDefaultMinAmountEur({ checkoutConfig, dynamicRoutingId, enabled });
4392
+ return {
4393
+ // `prefillFiatEmail` is intentionally kept out of the key (web parity):
4394
+ // it's read at fetch time, so post-mount changes don't refetch.
4395
+ queryKey: [
4396
+ "fops",
4397
+ {
4398
+ apiKey,
4399
+ userId,
4400
+ recipientAddress,
4401
+ solanaAddress: transferInit?.solanaAddr,
4402
+ targetAsset,
4403
+ targetChain,
4404
+ // fallback to DEFAULT_COUNTRY_CODE, do not use it in useSwappedDefaultCurrencyQuery
4405
+ countryCode: userIpInfo?.alpha2 || DEFAULT_COUNTRY_CODE,
4406
+ fiatCurrencyCode,
4407
+ fopPriority,
4408
+ themeConfig,
4409
+ defaultMinAmount
4410
+ }
4411
+ ],
4412
+ prefillFiatEmail,
4413
+ enabled: enabled && !!apiKey && !!targetAsset && !!targetChain && !!recipientAddress && !!transferInit && !isFiatCurrencyCodeLoading && !isExchangeRatesLoading,
4414
+ isDependencyLoading: isTransferInitLoading || isFiatCurrencyCodeLoading || isExchangeRatesLoading,
4415
+ isTransferInitFetching
4416
+ };
4417
+ }
4418
+ function useDefaultMinAmountEur({
4419
+ checkoutConfig,
4420
+ dynamicRoutingId,
4421
+ enabled
4422
+ }) {
4379
4423
  const minTransferLimits = useDynamicConfig("mintokentransfervalue");
4380
- const { data: exchangeRates, isLoading: isExchangeRatesLoading } = useFiatExchangeRates(enabled && isSwappedEnabled);
4381
- const defaultMinAmountEur = getMinTransferValueEur(
4424
+ const { data: exchangeRates, isLoading } = useFiatExchangeRates(enabled);
4425
+ const targetChain = checkoutConfig?.targetChain;
4426
+ const defaultMinAmount = getMinTransferValueEur(
4382
4427
  targetChain ? Number(targetChain) : void 0,
4383
4428
  minTransferLimits,
4384
4429
  getConfiguredMinDepositUsd2({
4385
4430
  targetChain,
4386
- targetAsset,
4431
+ targetAsset: checkoutConfig?.targetAsset,
4387
4432
  dynamicRoutingId,
4388
4433
  getMinDepositUSD: checkoutConfig?.getMinDepositUSD
4389
4434
  }),
4390
4435
  exchangeRates
4391
4436
  );
4392
- const isEnabled = enabled && isSwappedEnabled && !!apiKey && !!targetAsset && !!targetChain && !!recipientAddress && !!transferInit && !isSwappedCurrencyCodeLoading && !isExchangeRatesLoading;
4393
- const query = useQuery3({
4394
- queryKey: [
4395
- "fops",
4396
- userId,
4397
- recipientAddress,
4398
- targetAsset,
4399
- targetChain,
4400
- apiKey,
4401
- countryCode,
4402
- swappedCurrencyCode,
4403
- fopPriority,
4404
- themeConfig,
4405
- defaultMinAmountEur
4406
- ],
4407
- queryFn: async () => {
4437
+ return { defaultMinAmount, isLoading };
4438
+ }
4439
+ function useDoFetchFops({
4440
+ queryKey,
4441
+ prefillFiatEmail,
4442
+ enabled
4443
+ }) {
4444
+ return useQuery3({
4445
+ queryKey,
4446
+ queryFn: async ({ queryKey: [_, params] }) => {
4447
+ const { recipientAddress, targetAsset, targetChain, fopPriority } = params;
4408
4448
  if (!recipientAddress || !targetChain || !targetAsset) {
4409
4449
  return { genericFormsOfPayments: [], savedFormsOfPayments: [] };
4410
4450
  }
4411
4451
  const destinationToken = { chainId: targetChain, address: targetAsset };
4412
4452
  const recipientTargets = [
4413
4453
  { recipientAddress, destinationToken },
4414
- ...transferInit?.solanaAddr ? [
4454
+ ...params.solanaAddress ? [
4415
4455
  {
4416
- recipientAddress: transferInit.solanaAddr,
4456
+ recipientAddress: params.solanaAddress,
4417
4457
  destinationToken: {
4418
- chainId: solanaChain2.id.toString(),
4458
+ chainId: solanaChain.id.toString(),
4419
4459
  address: FUNKIT_CONNECT_CHECKOUT_NATIVE_CURRENCY_ADDRESS
4420
4460
  }
4421
4461
  }
4422
4462
  ] : []
4423
4463
  ];
4424
4464
  const response = await getFops({
4425
- apiKey,
4465
+ apiKey: params.apiKey,
4426
4466
  logger,
4427
4467
  params: {
4428
4468
  recipientAddress,
4429
- userId,
4469
+ userId: params.userId,
4430
4470
  destinationToken,
4431
- fiatCurrencyCode: swappedCurrencyCode,
4432
- countryCode,
4471
+ fiatCurrencyCode: params.fiatCurrencyCode,
4472
+ countryCode: params.countryCode,
4433
4473
  recipientTargets,
4434
- thirdPartyPaymentConfigs: { swapped: { themeConfig } },
4435
- checkoutLimitsCriteria: { defaultMinAmount: defaultMinAmountEur }
4474
+ thirdPartyPaymentConfigs: buildSwappedThirdPartyPaymentConfigs({
4475
+ prefillFiatEmail,
4476
+ themeConfig: params.themeConfig,
4477
+ logTag: "connect-rn:useFops",
4478
+ logger
4479
+ }),
4480
+ checkoutLimitsCriteria: { defaultMinAmount: params.defaultMinAmount }
4436
4481
  }
4437
4482
  });
4438
4483
  return {
@@ -4446,19 +4491,10 @@ function useFops({
4446
4491
  )
4447
4492
  };
4448
4493
  },
4449
- enabled: isEnabled,
4494
+ enabled,
4450
4495
  staleTime: FOPS_STALE_TIME,
4451
4496
  refetchOnWindowFocus: false
4452
4497
  });
4453
- return {
4454
- savedFops: query.data?.savedFormsOfPayments ?? [],
4455
- genericFops: query.data?.genericFormsOfPayments ?? [],
4456
- isLoading: query.isLoading || isTransferInitLoading,
4457
- isFetching: isTransferInitFetching,
4458
- isError: query.isError,
4459
- refetch: () => void query.refetch(),
4460
- isSwappedEnabled
4461
- };
4462
4498
  }
4463
4499
 
4464
4500
  // src/transfer/hooks/useWithdrawalFops.ts
@@ -4470,6 +4506,7 @@ import {
4470
4506
  DEFAULT_FIAT_CURRENCY as DEFAULT_FIAT_CURRENCY2,
4471
4507
  FOPS_STALE_TIME as FOPS_STALE_TIME2,
4472
4508
  buildSwappedSellLimits,
4509
+ buildSwappedThirdPartyPaymentConfigs as buildSwappedThirdPartyPaymentConfigs2,
4473
4510
  findSwappedSourceOverride,
4474
4511
  getExchangeRate,
4475
4512
  getSwappedCashMinUsd,
@@ -4538,7 +4575,8 @@ async function fetchWithdrawalFops({
4538
4575
  route,
4539
4576
  eurMax,
4540
4577
  usdBalance,
4541
- sourceToken
4578
+ sourceToken,
4579
+ prefillFiatEmail
4542
4580
  }) {
4543
4581
  const acceptedToken = {
4544
4582
  chainId: route.targetChainId,
@@ -4575,7 +4613,12 @@ async function fetchWithdrawalFops({
4575
4613
  countryCode,
4576
4614
  fiatCurrencyCode: swappedCurrencyCode,
4577
4615
  sourceToken: acceptedToken,
4578
- thirdPartyPaymentConfigs: { swapped: { themeConfig } },
4616
+ thirdPartyPaymentConfigs: buildSwappedThirdPartyPaymentConfigs2({
4617
+ prefillFiatEmail,
4618
+ themeConfig,
4619
+ logTag: "connect-rn:withdrawFops",
4620
+ logger
4621
+ }),
4579
4622
  checkoutLimitsCriteria: sellLimits
4580
4623
  }
4581
4624
  ]
@@ -4595,7 +4638,7 @@ function useWithdrawalFops({
4595
4638
  config,
4596
4639
  enabled = true
4597
4640
  }) {
4598
- const { apiKey, userId } = useFunkitIdentity();
4641
+ const { apiKey, userId, prefillFiatEmail } = useFunkitIdentity();
4599
4642
  const { isLoading: isStatsigLoading } = useStatsigClient();
4600
4643
  const isWithdrawalEnabled = !!useDynamicConfig("enableswappedwithdrawal");
4601
4644
  const fopPriority = useDynamicConfig("foppriority");
@@ -4619,6 +4662,8 @@ function useWithdrawalFops({
4619
4662
  const { usdBalance, eurMax, isBelowMinimumBalance, isAwaitingCap } = useWithdrawalSellCap(config, walletAddress);
4620
4663
  const isEnabled = enabled && isWithdrawalEnabled && !!apiKey && !!userId && !!walletAddress && walletAddress !== "0x" && !!countryCode && !isSwappedCurrencyCodeLoading && !isAwaitingCap;
4621
4664
  const query = useQuery4({
4665
+ // `prefillFiatEmail` is intentionally NOT in the queryKey (web parity): it's
4666
+ // read at fetch time, so post-mount changes don't trigger a refetch.
4622
4667
  queryKey: [
4623
4668
  WITHDRAW_FOPS_QUERY_KEY,
4624
4669
  userId,
@@ -4645,7 +4690,8 @@ function useWithdrawalFops({
4645
4690
  route,
4646
4691
  eurMax,
4647
4692
  usdBalance,
4648
- sourceToken: config.sourceToken
4693
+ sourceToken: config.sourceToken,
4694
+ prefillFiatEmail
4649
4695
  }) : Promise.resolve([]),
4650
4696
  enabled: isEnabled,
4651
4697
  staleTime: FOPS_STALE_TIME2,
@@ -4860,20 +4906,20 @@ function useSupportedTokens({
4860
4906
  }
4861
4907
 
4862
4908
  // src/transfer/hooks/useTokenTransfer.ts
4863
- import { bitcoinChain as bitcoinChain2, solanaChain as solanaChain3, tronChain as tronChain2 } from "@funkit/chains";
4909
+ import { bitcoinChain, solanaChain as solanaChain2, tronChain } from "@funkit/chains";
4864
4910
  import {
4865
4911
  getDepositAddressForChain as getDepositAddressForChain2,
4866
4912
  getTransferTokenQrCodeUri
4867
4913
  } from "@funkit/connect-core";
4868
4914
  var DEFAULT_MAX_SLIPPAGE_PERCENT = 0.25;
4869
4915
  function resolveBlockchain(chainId) {
4870
- if (chainId === solanaChain3.id) {
4916
+ if (chainId === solanaChain2.id) {
4871
4917
  return "solana";
4872
4918
  }
4873
- if (chainId === bitcoinChain2.id) {
4919
+ if (chainId === bitcoinChain.id) {
4874
4920
  return "bitcoin";
4875
4921
  }
4876
- if (chainId === tronChain2.id) {
4922
+ if (chainId === tronChain.id) {
4877
4923
  return "tron";
4878
4924
  }
4879
4925
  return "ethereum";
@@ -5304,7 +5350,7 @@ function FlowContent({
5304
5350
  const activeDynamicRoutingId = selectedCandidate?.dynamicRoutingId ?? config.dynamicRoutingId;
5305
5351
  const parsedSourceChain = config.sourceChain ? Number(config.sourceChain) : void 0;
5306
5352
  const initialChainId = parsedSourceChain != null && Number.isFinite(parsedSourceChain) ? parsedSourceChain : void 0;
5307
- const evmRepresentativeChainId = initialChainId != null && !isNonEvmChainId(initialChainId) ? initialChainId : DEFAULT_EVM_CHAIN_ID;
5353
+ const evmRepresentativeChainId = initialChainId != null && isEvmChainId2(initialChainId) ? initialChainId : DEFAULT_EVM_CHAIN_ID;
5308
5354
  const selectedChainId = resolveSelectedChainId(
5309
5355
  selectedNetworkId,
5310
5356
  initialChainId,
@@ -5323,6 +5369,7 @@ function FlowContent({
5323
5369
  });
5324
5370
  const fetched = useSupportedTokens({ transferInit });
5325
5371
  const tokenChainFilters = config.tokenChainFilters ?? fetched.chainFilters;
5372
+ const isChainListLoading = !config.tokenChainFilters && fetched.isLoading;
5326
5373
  const depositNetworks = useMemo10(
5327
5374
  () => buildDepositNetworks(t, tokenChainFilters),
5328
5375
  [t, tokenChainFilters]
@@ -5450,7 +5497,7 @@ function FlowContent({
5450
5497
  setSelectedCandidate(picked);
5451
5498
  }
5452
5499
  },
5453
- loading: isLoadingGeoCheck || isAddressLoading || isStatsigLoading || isSwappedEnabled && isFopsLoading,
5500
+ loading: isLoadingGeoCheck || isAddressLoading || isStatsigLoading || isChainListLoading || isSwappedEnabled && isFopsLoading,
5454
5501
  error: isSwappedEnabled && isFopsError,
5455
5502
  onRetry: refetchFops,
5456
5503
  onSelectMethod: (id) => {
@@ -5694,7 +5741,7 @@ function useFunkitFlow() {
5694
5741
  }
5695
5742
 
5696
5743
  // src/version.ts
5697
- var CONNECT_RN_VERSION = true ? "3.2.0" : "0.0.0-dev";
5744
+ var CONNECT_RN_VERSION = true ? "3.3.0" : "0.0.0-dev";
5698
5745
 
5699
5746
  // src/providers/FunkitStatsigProvider.tsx
5700
5747
  import {