@spicenet-io/spiceflow-ui 1.6.6 → 1.7.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.
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsxs, jsx } from 'react/jsx-runtime';
3
3
  import React, { useEffect, useState, useCallback } from 'react';
4
- import { c as createTheme, B as Button } from './Button-RifBkofT.js';
4
+ import { c as createTheme, B as Button } from './Button-aWXByNBC.js';
5
5
  import { useDynamicContext, useConnectWithOtp } from '@dynamic-labs/sdk-react-core';
6
6
 
7
7
  const Input = ({
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { useState, useEffect } from 'react';
4
- import { B as Button, c as createTheme } from './Button-RifBkofT.js';
4
+ import { B as Button, c as createTheme } from './Button-aWXByNBC.js';
5
5
  import { usePrivy, useLogin, useLogout } from '@privy-io/react-auth';
6
6
 
7
7
  const PrivyLogin = ({
@@ -16,5 +16,6 @@ export interface SpiceDepositProps {
16
16
  postDepositInstruction?: (bridgedAmount: string) => Promise<void> | void;
17
17
  postDepositInstructionLabel?: string;
18
18
  airdrop?: boolean;
19
+ sponsorGas?: boolean;
19
20
  }
20
21
  export declare const SpiceDeposit: React.FC<SpiceDepositProps>;
package/dist/index.cjs.js CHANGED
@@ -3914,7 +3914,8 @@ const SwapWidget = ({
3914
3914
 
3915
3915
  const DepositWidget = ({
3916
3916
  depositBatches,
3917
- tokenAddress = "0x0",
3917
+ tokenAddress,
3918
+ tokenDecimals,
3918
3919
  supportedChains,
3919
3920
  theme: themeMode = "light",
3920
3921
  styles,
@@ -4104,7 +4105,10 @@ const DepositWidget = ({
4104
4105
  [
4105
4106
  {
4106
4107
  tokenAddress,
4107
- tokenAmount: viem.parseEther(selectedDepositAsset.amount)
4108
+ tokenAmount: viem.parseUnits(
4109
+ selectedDepositAsset.amount,
4110
+ tokenDecimals
4111
+ )
4108
4112
  }
4109
4113
  ]
4110
4114
  ]
@@ -4615,6 +4619,7 @@ const DepositWidgetModal = ({
4615
4619
  // Pass through all DepositWidget props
4616
4620
  depositBatches,
4617
4621
  tokenAddress,
4622
+ tokenDecimals,
4618
4623
  supportedChains,
4619
4624
  theme: themeMode = "light",
4620
4625
  styles,
@@ -4680,6 +4685,7 @@ const DepositWidgetModal = ({
4680
4685
  {
4681
4686
  depositBatches,
4682
4687
  tokenAddress,
4688
+ tokenDecimals,
4683
4689
  supportedChains,
4684
4690
  theme: themeMode,
4685
4691
  styles: {
@@ -6917,7 +6923,8 @@ const DepositModal = React.memo(
6917
6923
  postDepositInstruction,
6918
6924
  postDepositInstructionLabel,
6919
6925
  nativeChainId,
6920
- airdrop = false
6926
+ airdrop = false,
6927
+ sponsorGas = false
6921
6928
  }) => {
6922
6929
  const depositAmount = depositInputHook?.depositAmount || "";
6923
6930
  const setDepositAmount = depositInputHook?.setDepositAmount || (() => {
@@ -7260,21 +7267,28 @@ const DepositModal = React.memo(
7260
7267
  console.log(`Waiting for transaction receipt: ${txHash}`);
7261
7268
  const receipt = await client.waitForTransactionReceipt({
7262
7269
  hash: txHash,
7263
- timeout: 6e4,
7264
- pollingInterval: 5e3,
7265
- confirmations: 1
7270
+ timeout: 12e4,
7271
+ pollingInterval: 2e3,
7272
+ confirmations: 2
7266
7273
  });
7267
7274
  console.log("Transaction receipt:", {
7268
7275
  hash: receipt.transactionHash,
7269
7276
  blockNumber: receipt.blockNumber,
7270
7277
  status: receipt.status,
7271
- confirmations: 1
7278
+ confirmations: 2
7272
7279
  });
7273
7280
  if (receipt.status !== "success") {
7274
7281
  throw new Error(
7275
7282
  `Transfer to delegate contract failed for ${selectedAsset.asset.symbol}`
7276
7283
  );
7277
7284
  }
7285
+ const currentBlock = await client.getBlockNumber();
7286
+ const confirmations = currentBlock - receipt.blockNumber;
7287
+ console.log(`Transaction has ${confirmations} confirmations`);
7288
+ if (confirmations < 2) {
7289
+ console.log("Waiting for additional confirmations...");
7290
+ await new Promise((resolve) => setTimeout(resolve, 3e3));
7291
+ }
7278
7292
  if (!depositDataRef.current) {
7279
7293
  depositDataRef.current = [];
7280
7294
  }
@@ -7303,11 +7317,27 @@ const DepositModal = React.memo(
7303
7317
  if (!sourceTransactionHash) {
7304
7318
  throw new Error("No transaction hash generated");
7305
7319
  }
7320
+ const finalClient = getClientForChain(chainId);
7321
+ const finalBlock = await finalClient.getBlockNumber();
7322
+ console.log(
7323
+ "Final block number before relayer submission:",
7324
+ finalBlock
7325
+ );
7326
+ console.log("All transactions confirmed, submitting to relayer...");
7306
7327
  if (!destinationTokenAddress) {
7307
7328
  throw new Error(
7308
7329
  "Destination token address is required for bridging"
7309
7330
  );
7310
7331
  }
7332
+ if (sponsorGas && nativeChainId) {
7333
+ const gasAmount = viem.parseUnits("0.0003", 18);
7334
+ tokenTransfers.push({
7335
+ tokenAddress: "0x0",
7336
+ tokenAmount: gasAmount.toString(),
7337
+ sender: sourceAddress,
7338
+ receiver: delegateContract
7339
+ });
7340
+ }
7311
7341
  const result = await relayerService.submitTransactionNon7702({
7312
7342
  tokenTransfers: [tokenTransfers],
7313
7343
  user: sourceAddress,
@@ -7376,21 +7406,28 @@ const DepositModal = React.memo(
7376
7406
  );
7377
7407
  const receipt = await client2.waitForTransactionReceipt({
7378
7408
  hash: transferToEmbeddedTx,
7379
- timeout: 6e4,
7380
- pollingInterval: 5e3,
7381
- confirmations: 1
7409
+ timeout: 12e4,
7410
+ pollingInterval: 2e3,
7411
+ confirmations: 2
7382
7412
  });
7383
7413
  console.log("Transaction receipt (EIP-7702):", {
7384
7414
  hash: receipt.transactionHash,
7385
7415
  blockNumber: receipt.blockNumber,
7386
7416
  status: receipt.status,
7387
- confirmations: 1
7417
+ confirmations: 2
7388
7418
  });
7389
7419
  if (receipt.status !== "success") {
7390
7420
  throw new Error(
7391
7421
  `Transfer to embedded wallet failed for ${selectedAsset.asset.symbol}`
7392
7422
  );
7393
7423
  }
7424
+ const currentBlock = await client2.getBlockNumber();
7425
+ const confirmations = currentBlock - receipt.blockNumber;
7426
+ console.log(`Transaction has ${confirmations} confirmations`);
7427
+ if (confirmations < 2) {
7428
+ console.log("Waiting for additional confirmations...");
7429
+ await new Promise((resolve) => setTimeout(resolve, 3e3));
7430
+ }
7394
7431
  console.log("Calling submitSpiceDeposit (EIP-7702) with:", {
7395
7432
  txHash: transferToEmbeddedTx,
7396
7433
  sender: sourceAddress,
@@ -7432,6 +7469,15 @@ const DepositModal = React.memo(
7432
7469
  receiver: isNative ? "" : escrowAddress
7433
7470
  });
7434
7471
  }
7472
+ if (sponsorGas && nativeChainId) {
7473
+ const gasAmount = viem.parseUnits("0.0003", 18);
7474
+ tokenTransfers.push({
7475
+ tokenAddress: "0x0",
7476
+ tokenAmount: gasAmount.toString(),
7477
+ sender: address,
7478
+ receiver: address
7479
+ });
7480
+ }
7435
7481
  const client = getClientForChain(chainId);
7436
7482
  const sourceRecentBlock = await client.getBlockNumber();
7437
7483
  const escrowDepositBatch = {
@@ -8093,7 +8139,8 @@ const SpiceDepositFlow = ({
8093
8139
  destinationTokenAddress,
8094
8140
  postDepositInstruction,
8095
8141
  postDepositInstructionLabel,
8096
- airdrop = false
8142
+ airdrop = false,
8143
+ sponsorGas = false
8097
8144
  }) => {
8098
8145
  const context = React.useContext(SpiceFlowProviderContext);
8099
8146
  if (!context) {
@@ -8222,7 +8269,8 @@ const SpiceDepositFlow = ({
8222
8269
  postDepositInstruction,
8223
8270
  postDepositInstructionLabel,
8224
8271
  nativeChainId,
8225
- airdrop
8272
+ airdrop,
8273
+ sponsorGas
8226
8274
  }
8227
8275
  );
8228
8276
  }
@@ -11916,7 +11964,7 @@ const LpModal = ({
11916
11964
  };
11917
11965
 
11918
11966
  const useFromInput = () => {
11919
- const [fromAmount, setFromAmount] = React.useState("");
11967
+ const [fromAmount, setFromAmount] = React.useState("0");
11920
11968
  return {
11921
11969
  fromAmount,
11922
11970
  setFromAmount
@@ -11924,7 +11972,7 @@ const useFromInput = () => {
11924
11972
  };
11925
11973
 
11926
11974
  const useToInputUpdate = () => {
11927
- const [toAmount, setToAmount] = React.useState("");
11975
+ const [toAmount, setToAmount] = React.useState("0");
11928
11976
  const updateToAmount = React.useCallback((amount) => {
11929
11977
  setToAmount(amount);
11930
11978
  }, []);
@@ -11936,7 +11984,7 @@ const useToInputUpdate = () => {
11936
11984
  };
11937
11985
 
11938
11986
  const useDepositInput = () => {
11939
- const [depositAmount, setDepositAmount] = React.useState("");
11987
+ const [depositAmount, setDepositAmount] = React.useState("0");
11940
11988
  return {
11941
11989
  depositAmount,
11942
11990
  setDepositAmount
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import React, { useState, useRef, useEffect, useCallback, createContext, useContext, useTransition, forwardRef, createElement, useMemo } from 'react';
4
4
  import { defineChain, createPublicClient, http, isAddress, getAddress, parseEther, encodeFunctionData, parseUnits, erc20Abi } from 'viem';
5
- import { c as createTheme, B as Button, d as defaultTheme } from './Button-RifBkofT.js';
5
+ import { c as createTheme, B as Button, d as defaultTheme } from './Button-aWXByNBC.js';
6
6
  import { getBalance, readContract } from 'viem/actions';
7
7
  import { basecampTestnet, citreaTestnet, baseSepolia, arbitrumSepolia, sepolia } from 'viem/chains';
8
8
  import { createPortal } from 'react-dom';
@@ -3912,7 +3912,8 @@ const SwapWidget = ({
3912
3912
 
3913
3913
  const DepositWidget = ({
3914
3914
  depositBatches,
3915
- tokenAddress = "0x0",
3915
+ tokenAddress,
3916
+ tokenDecimals,
3916
3917
  supportedChains,
3917
3918
  theme: themeMode = "light",
3918
3919
  styles,
@@ -4102,7 +4103,10 @@ const DepositWidget = ({
4102
4103
  [
4103
4104
  {
4104
4105
  tokenAddress,
4105
- tokenAmount: parseEther(selectedDepositAsset.amount)
4106
+ tokenAmount: parseUnits(
4107
+ selectedDepositAsset.amount,
4108
+ tokenDecimals
4109
+ )
4106
4110
  }
4107
4111
  ]
4108
4112
  ]
@@ -4613,6 +4617,7 @@ const DepositWidgetModal = ({
4613
4617
  // Pass through all DepositWidget props
4614
4618
  depositBatches,
4615
4619
  tokenAddress,
4620
+ tokenDecimals,
4616
4621
  supportedChains,
4617
4622
  theme: themeMode = "light",
4618
4623
  styles,
@@ -4678,6 +4683,7 @@ const DepositWidgetModal = ({
4678
4683
  {
4679
4684
  depositBatches,
4680
4685
  tokenAddress,
4686
+ tokenDecimals,
4681
4687
  supportedChains,
4682
4688
  theme: themeMode,
4683
4689
  styles: {
@@ -6915,7 +6921,8 @@ const DepositModal = React.memo(
6915
6921
  postDepositInstruction,
6916
6922
  postDepositInstructionLabel,
6917
6923
  nativeChainId,
6918
- airdrop = false
6924
+ airdrop = false,
6925
+ sponsorGas = false
6919
6926
  }) => {
6920
6927
  const depositAmount = depositInputHook?.depositAmount || "";
6921
6928
  const setDepositAmount = depositInputHook?.setDepositAmount || (() => {
@@ -7258,21 +7265,28 @@ const DepositModal = React.memo(
7258
7265
  console.log(`Waiting for transaction receipt: ${txHash}`);
7259
7266
  const receipt = await client.waitForTransactionReceipt({
7260
7267
  hash: txHash,
7261
- timeout: 6e4,
7262
- pollingInterval: 5e3,
7263
- confirmations: 1
7268
+ timeout: 12e4,
7269
+ pollingInterval: 2e3,
7270
+ confirmations: 2
7264
7271
  });
7265
7272
  console.log("Transaction receipt:", {
7266
7273
  hash: receipt.transactionHash,
7267
7274
  blockNumber: receipt.blockNumber,
7268
7275
  status: receipt.status,
7269
- confirmations: 1
7276
+ confirmations: 2
7270
7277
  });
7271
7278
  if (receipt.status !== "success") {
7272
7279
  throw new Error(
7273
7280
  `Transfer to delegate contract failed for ${selectedAsset.asset.symbol}`
7274
7281
  );
7275
7282
  }
7283
+ const currentBlock = await client.getBlockNumber();
7284
+ const confirmations = currentBlock - receipt.blockNumber;
7285
+ console.log(`Transaction has ${confirmations} confirmations`);
7286
+ if (confirmations < 2) {
7287
+ console.log("Waiting for additional confirmations...");
7288
+ await new Promise((resolve) => setTimeout(resolve, 3e3));
7289
+ }
7276
7290
  if (!depositDataRef.current) {
7277
7291
  depositDataRef.current = [];
7278
7292
  }
@@ -7301,11 +7315,27 @@ const DepositModal = React.memo(
7301
7315
  if (!sourceTransactionHash) {
7302
7316
  throw new Error("No transaction hash generated");
7303
7317
  }
7318
+ const finalClient = getClientForChain(chainId);
7319
+ const finalBlock = await finalClient.getBlockNumber();
7320
+ console.log(
7321
+ "Final block number before relayer submission:",
7322
+ finalBlock
7323
+ );
7324
+ console.log("All transactions confirmed, submitting to relayer...");
7304
7325
  if (!destinationTokenAddress) {
7305
7326
  throw new Error(
7306
7327
  "Destination token address is required for bridging"
7307
7328
  );
7308
7329
  }
7330
+ if (sponsorGas && nativeChainId) {
7331
+ const gasAmount = parseUnits("0.0003", 18);
7332
+ tokenTransfers.push({
7333
+ tokenAddress: "0x0",
7334
+ tokenAmount: gasAmount.toString(),
7335
+ sender: sourceAddress,
7336
+ receiver: delegateContract
7337
+ });
7338
+ }
7309
7339
  const result = await relayerService.submitTransactionNon7702({
7310
7340
  tokenTransfers: [tokenTransfers],
7311
7341
  user: sourceAddress,
@@ -7374,21 +7404,28 @@ const DepositModal = React.memo(
7374
7404
  );
7375
7405
  const receipt = await client2.waitForTransactionReceipt({
7376
7406
  hash: transferToEmbeddedTx,
7377
- timeout: 6e4,
7378
- pollingInterval: 5e3,
7379
- confirmations: 1
7407
+ timeout: 12e4,
7408
+ pollingInterval: 2e3,
7409
+ confirmations: 2
7380
7410
  });
7381
7411
  console.log("Transaction receipt (EIP-7702):", {
7382
7412
  hash: receipt.transactionHash,
7383
7413
  blockNumber: receipt.blockNumber,
7384
7414
  status: receipt.status,
7385
- confirmations: 1
7415
+ confirmations: 2
7386
7416
  });
7387
7417
  if (receipt.status !== "success") {
7388
7418
  throw new Error(
7389
7419
  `Transfer to embedded wallet failed for ${selectedAsset.asset.symbol}`
7390
7420
  );
7391
7421
  }
7422
+ const currentBlock = await client2.getBlockNumber();
7423
+ const confirmations = currentBlock - receipt.blockNumber;
7424
+ console.log(`Transaction has ${confirmations} confirmations`);
7425
+ if (confirmations < 2) {
7426
+ console.log("Waiting for additional confirmations...");
7427
+ await new Promise((resolve) => setTimeout(resolve, 3e3));
7428
+ }
7392
7429
  console.log("Calling submitSpiceDeposit (EIP-7702) with:", {
7393
7430
  txHash: transferToEmbeddedTx,
7394
7431
  sender: sourceAddress,
@@ -7430,6 +7467,15 @@ const DepositModal = React.memo(
7430
7467
  receiver: isNative ? "" : escrowAddress
7431
7468
  });
7432
7469
  }
7470
+ if (sponsorGas && nativeChainId) {
7471
+ const gasAmount = parseUnits("0.0003", 18);
7472
+ tokenTransfers.push({
7473
+ tokenAddress: "0x0",
7474
+ tokenAmount: gasAmount.toString(),
7475
+ sender: address,
7476
+ receiver: address
7477
+ });
7478
+ }
7433
7479
  const client = getClientForChain(chainId);
7434
7480
  const sourceRecentBlock = await client.getBlockNumber();
7435
7481
  const escrowDepositBatch = {
@@ -8091,7 +8137,8 @@ const SpiceDepositFlow = ({
8091
8137
  destinationTokenAddress,
8092
8138
  postDepositInstruction,
8093
8139
  postDepositInstructionLabel,
8094
- airdrop = false
8140
+ airdrop = false,
8141
+ sponsorGas = false
8095
8142
  }) => {
8096
8143
  const context = useContext(SpiceFlowProviderContext);
8097
8144
  if (!context) {
@@ -8220,7 +8267,8 @@ const SpiceDepositFlow = ({
8220
8267
  postDepositInstruction,
8221
8268
  postDepositInstructionLabel,
8222
8269
  nativeChainId,
8223
- airdrop
8270
+ airdrop,
8271
+ sponsorGas
8224
8272
  }
8225
8273
  );
8226
8274
  }
@@ -11914,7 +11962,7 @@ const LpModal = ({
11914
11962
  };
11915
11963
 
11916
11964
  const useFromInput = () => {
11917
- const [fromAmount, setFromAmount] = useState("");
11965
+ const [fromAmount, setFromAmount] = useState("0");
11918
11966
  return {
11919
11967
  fromAmount,
11920
11968
  setFromAmount
@@ -11922,7 +11970,7 @@ const useFromInput = () => {
11922
11970
  };
11923
11971
 
11924
11972
  const useToInputUpdate = () => {
11925
- const [toAmount, setToAmount] = useState("");
11973
+ const [toAmount, setToAmount] = useState("0");
11926
11974
  const updateToAmount = useCallback((amount) => {
11927
11975
  setToAmount(amount);
11928
11976
  }, []);
@@ -11934,7 +11982,7 @@ const useToInputUpdate = () => {
11934
11982
  };
11935
11983
 
11936
11984
  const useDepositInput = () => {
11937
- const [depositAmount, setDepositAmount] = useState("");
11985
+ const [depositAmount, setDepositAmount] = useState("0");
11938
11986
  return {
11939
11987
  depositAmount,
11940
11988
  setDepositAmount
@@ -19,7 +19,8 @@ export interface SpiceDepositResponse {
19
19
  }
20
20
  export interface DepositWidgetProps {
21
21
  depositBatches: ChainBatch[];
22
- tokenAddress?: Address;
22
+ tokenAddress: Address;
23
+ tokenDecimals: number;
23
24
  supportedChains: number[];
24
25
  theme?: ThemeMode;
25
26
  styles?: CustomStyles;
@@ -49,4 +50,5 @@ export interface DepositModalProps {
49
50
  postDepositInstructionLabel?: string;
50
51
  nativeChainId?: number;
51
52
  airdrop?: boolean;
53
+ sponsorGas?: boolean;
52
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spicenet-io/spiceflow-ui",
3
- "version": "1.6.6",
3
+ "version": "1.7.1",
4
4
  "description": "Spiceflow UI SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
File without changes