@shapeshiftoss/swap-widget 0.6.0 → 0.7.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/dist/index.js +27 -22
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { useAppKitAccount as useAppKitAccount3 } from "@reown/appkit/react";
|
|
|
3
3
|
import { useCallback as useCallback11, useEffect as useEffect10, useMemo as useMemo12, useRef as useRef7, useState as useState8 } from "react";
|
|
4
4
|
|
|
5
5
|
// src/api/client.ts
|
|
6
|
-
var DEFAULT_API_BASE_URL =
|
|
6
|
+
var DEFAULT_API_BASE_URL = "https://api.shapeshift.com";
|
|
7
7
|
var createApiClient = (config = {}) => {
|
|
8
8
|
const baseUrl = config.baseUrl ?? DEFAULT_API_BASE_URL;
|
|
9
9
|
const fetchWithConfig = async (endpoint, params, method = "GET", timeoutMs = 3e4) => {
|
|
@@ -1330,7 +1330,7 @@ var useStatusPolling = ({
|
|
|
1330
1330
|
|
|
1331
1331
|
// src/hooks/useSwapApproval.ts
|
|
1332
1332
|
import { useEffect as useEffect3, useRef as useRef2 } from "react";
|
|
1333
|
-
import { createPublicClient as createPublicClient2,
|
|
1333
|
+
import { createPublicClient as createPublicClient2, http as http2 } from "viem";
|
|
1334
1334
|
|
|
1335
1335
|
// src/constants/chains.ts
|
|
1336
1336
|
import {
|
|
@@ -1443,6 +1443,15 @@ var useSwapApproval = () => {
|
|
|
1443
1443
|
});
|
|
1444
1444
|
return;
|
|
1445
1445
|
}
|
|
1446
|
+
if (!sellAmountBaseUnit || sellAmountBaseUnit === "0") {
|
|
1447
|
+
actorRef.send({ type: "APPROVAL_ERROR", error: "No sell amount specified" });
|
|
1448
|
+
return;
|
|
1449
|
+
}
|
|
1450
|
+
const approvalTxs = quote.approval.approvalTxs;
|
|
1451
|
+
if (!approvalTxs?.length) {
|
|
1452
|
+
actorRef.send({ type: "APPROVAL_ERROR", error: "No approval transactions in quote" });
|
|
1453
|
+
return;
|
|
1454
|
+
}
|
|
1446
1455
|
const requiredChainId = getEvmNetworkId(sellAsset.chainId);
|
|
1447
1456
|
const client = walletClient;
|
|
1448
1457
|
const currentChainId = await client.getChainId();
|
|
@@ -1458,28 +1467,24 @@ var useSwapApproval = () => {
|
|
|
1458
1467
|
nativeCurrency,
|
|
1459
1468
|
rpcUrls: { default: { http: [] } }
|
|
1460
1469
|
};
|
|
1461
|
-
if (!sellAmountBaseUnit || sellAmountBaseUnit === "0") {
|
|
1462
|
-
actorRef.send({ type: "APPROVAL_ERROR", error: "No sell amount specified" });
|
|
1463
|
-
return;
|
|
1464
|
-
}
|
|
1465
|
-
const approvalData = encodeFunctionData({
|
|
1466
|
-
abi: erc20Abi2,
|
|
1467
|
-
functionName: "approve",
|
|
1468
|
-
args: [quote.approval.spender, BigInt(sellAmountBaseUnit)]
|
|
1469
|
-
});
|
|
1470
|
-
const approvalHash = await client.sendTransaction({
|
|
1471
|
-
to: sellAssetAddress,
|
|
1472
|
-
data: approvalData,
|
|
1473
|
-
value: BigInt(0),
|
|
1474
|
-
chain,
|
|
1475
|
-
account: walletAddress
|
|
1476
|
-
});
|
|
1477
1470
|
const rpcUrl = chain.rpcUrls?.default?.http?.[0];
|
|
1478
1471
|
const publicClient = createPublicClient2({
|
|
1479
1472
|
chain,
|
|
1480
1473
|
transport: rpcUrl ? http2(rpcUrl) : http2()
|
|
1481
1474
|
});
|
|
1482
|
-
|
|
1475
|
+
let approvalHash;
|
|
1476
|
+
for (const approvalTx of approvalTxs) {
|
|
1477
|
+
approvalHash = await client.sendTransaction({
|
|
1478
|
+
to: approvalTx.to,
|
|
1479
|
+
data: approvalTx.data,
|
|
1480
|
+
value: BigInt(approvalTx.value),
|
|
1481
|
+
chain,
|
|
1482
|
+
account: walletAddress
|
|
1483
|
+
});
|
|
1484
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash: approvalHash });
|
|
1485
|
+
if (receipt.status !== "success") throw new Error("Approval transaction reverted");
|
|
1486
|
+
}
|
|
1487
|
+
if (!approvalHash) throw new Error("Expected at least one approval transaction");
|
|
1483
1488
|
actorRef.send({ type: "APPROVAL_SUCCESS", txHash: approvalHash });
|
|
1484
1489
|
} catch (error) {
|
|
1485
1490
|
actorRef.send({
|
|
@@ -1623,7 +1628,7 @@ import { useQueries, useQueryClient } from "@tanstack/react-query";
|
|
|
1623
1628
|
import { getBalance, readContract } from "@wagmi/core";
|
|
1624
1629
|
import PQueue from "p-queue";
|
|
1625
1630
|
import { useCallback as useCallback3, useMemo as useMemo4 } from "react";
|
|
1626
|
-
import { erc20Abi as
|
|
1631
|
+
import { erc20Abi as erc20Abi2 } from "viem";
|
|
1627
1632
|
import { useConfig } from "wagmi";
|
|
1628
1633
|
var CONCURRENCY_LIMIT = 5;
|
|
1629
1634
|
var DELAY_BETWEEN_BATCHES_MS = 50;
|
|
@@ -1823,7 +1828,7 @@ var useMultiChainBalance = (evmAddress, utxoAddress, solanaAddress, assetId, pre
|
|
|
1823
1828
|
if (isErc20 && evmParsed.tokenAddress) {
|
|
1824
1829
|
const result2 = await readContract(config, {
|
|
1825
1830
|
address: evmParsed.tokenAddress,
|
|
1826
|
-
abi:
|
|
1831
|
+
abi: erc20Abi2,
|
|
1827
1832
|
functionName: "balanceOf",
|
|
1828
1833
|
args: [evmAddress],
|
|
1829
1834
|
chainId: evmParsed.evmChainId
|
|
@@ -1936,7 +1941,7 @@ var useMultiChainBalances = (evmAddress, utxoAddress, solanaAddress, assetIds, a
|
|
|
1936
1941
|
if (asset.tokenAddress) {
|
|
1937
1942
|
const result2 = await readContract(config, {
|
|
1938
1943
|
address: asset.tokenAddress,
|
|
1939
|
-
abi:
|
|
1944
|
+
abi: erc20Abi2,
|
|
1940
1945
|
functionName: "balanceOf",
|
|
1941
1946
|
args: [evmAddress],
|
|
1942
1947
|
// @ts-ignore - swap-widget supports more chains than main app's wagmi type registration
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshiftoss/swap-widget",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Embeddable swap widget using ShapeShift API",
|
|
5
5
|
"repository": "https://github.com/shapeshift/web",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"p-queue": "^8.0.1",
|
|
31
31
|
"react-virtuoso": "^4.7.11",
|
|
32
32
|
"xstate": "5.28.0",
|
|
33
|
+
"@shapeshiftoss/utils": "^1.1.0",
|
|
33
34
|
"@shapeshiftoss/caip": "^8.16.10",
|
|
34
|
-
"@shapeshiftoss/types": "^9.0.0"
|
|
35
|
-
"@shapeshiftoss/utils": "^1.1.0"
|
|
35
|
+
"@shapeshiftoss/types": "^9.0.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@wagmi/core": "^2.0.0",
|