@coin-voyage/swapkit 0.1.0-beta.2 → 0.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/dist/components/connected-wallets.d.ts +1 -1
- package/dist/components/connected-wallets.js +37 -14
- package/dist/components/connected-wallets.test.d.ts +1 -0
- package/dist/components/connected-wallets.test.js +104 -0
- package/dist/components/execution-modal.js +8 -2
- package/dist/components/styles.d.ts +4 -1
- package/dist/components/styles.js +86 -16
- package/dist/components/swap.d.ts +27 -1
- package/dist/components/swap.js +41 -18
- package/dist/components/token-picker.d.ts +3 -1
- package/dist/components/token-picker.js +19 -9
- package/dist/components/token-picker.test.d.ts +1 -0
- package/dist/components/token-picker.test.js +43 -0
- package/dist/components/wallet-connector.d.ts +3 -1
- package/dist/components/wallet-connector.js +69 -20
- package/dist/components/wallet-connector.test.d.ts +1 -0
- package/dist/components/wallet-connector.test.js +89 -0
- package/dist/hooks/use-swap-execution.d.ts +1 -1
- package/dist/hooks/use-swap-execution.js +69 -35
- package/dist/hooks/use-swap-state.d.ts +4 -1
- package/dist/hooks/use-swap-state.js +3 -3
- package/dist/hooks/use-token-data.d.ts +1 -0
- package/dist/hooks/use-token-data.js +4 -3
- package/dist/lib/currency-selection.js +3 -4
- package/dist/lib/execution.d.ts +12 -5
- package/dist/lib/quote.d.ts +1 -1
- package/dist/lib/quote.js +7 -7
- package/dist/providers/swapkit-provider.d.ts +1 -1
- package/dist/providers/swapkit-provider.js +3 -1
- package/dist/providers/swapkit-provider.test.d.ts +1 -0
- package/dist/providers/swapkit-provider.test.js +20 -0
- package/dist/types.d.ts +2 -1
- package/package.json +4 -4
package/dist/lib/execution.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { ExecuteTransaction } from "@coin-voyage/crypto/types";
|
|
2
2
|
import type { SwapExecuteResponse } from "@coin-voyage/shared/types";
|
|
3
|
+
type CompletedTransactionHashes = {
|
|
4
|
+
sourceTxHash: string;
|
|
5
|
+
destinationTxHash?: string;
|
|
6
|
+
} | {
|
|
7
|
+
sourceTxHash?: string;
|
|
8
|
+
destinationTxHash: string;
|
|
9
|
+
};
|
|
3
10
|
export type SwapStage = {
|
|
4
11
|
kind: "idle";
|
|
5
12
|
} | {
|
|
@@ -7,6 +14,7 @@ export type SwapStage = {
|
|
|
7
14
|
} | {
|
|
8
15
|
kind: "awaiting_payment";
|
|
9
16
|
swapData: SwapExecuteResponse;
|
|
17
|
+
orderId: string;
|
|
10
18
|
paymentStepIndex: number;
|
|
11
19
|
} | {
|
|
12
20
|
kind: "source_confirming";
|
|
@@ -18,21 +26,20 @@ export type SwapStage = {
|
|
|
18
26
|
swapData: SwapExecuteResponse;
|
|
19
27
|
orderId: string;
|
|
20
28
|
sourceTxHash?: string;
|
|
21
|
-
} | {
|
|
29
|
+
} | ({
|
|
22
30
|
kind: "done";
|
|
23
31
|
swapData: SwapExecuteResponse;
|
|
24
32
|
orderId: string;
|
|
25
|
-
|
|
26
|
-
txHash: string;
|
|
27
|
-
} | {
|
|
33
|
+
} & CompletedTransactionHashes) | {
|
|
28
34
|
kind: "refunded";
|
|
29
35
|
swapData: SwapExecuteResponse;
|
|
30
36
|
orderId: string;
|
|
31
37
|
sourceTxHash?: string;
|
|
32
|
-
refundTxHash
|
|
38
|
+
refundTxHash?: string;
|
|
33
39
|
} | {
|
|
34
40
|
kind: "error";
|
|
35
41
|
swapData: SwapExecuteResponse | null;
|
|
36
42
|
message: string;
|
|
37
43
|
};
|
|
38
44
|
export declare function buildSwapExecuteTransactions(swapData: SwapExecuteResponse, fromAddress: string): ExecuteTransaction[];
|
|
45
|
+
export {};
|
package/dist/lib/quote.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CurrencyBase, SwapQuoteRequest } from "@coin-voyage/shared/types";
|
|
2
2
|
export type SwapSide = "input" | "output";
|
|
3
3
|
export declare function toCurrencyBase(currency: CurrencyBase): CurrencyBase;
|
|
4
4
|
interface BuildSwapQuoteRequestProps {
|
package/dist/lib/quote.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addressesMatch } from "@coin-voyage/crypto/utils";
|
|
2
|
+
import { getChainTypeByChainId } from "@coin-voyage/shared/chain";
|
|
3
|
+
import { currenciesMatch } from "./currency-selection";
|
|
2
4
|
export function toCurrencyBase(currency) {
|
|
3
5
|
return currency.address ? { chain_id: currency.chain_id, address: currency.address } : { chain_id: currency.chain_id };
|
|
4
6
|
}
|
|
@@ -15,10 +17,8 @@ export function buildSwapQuoteRequest({ amount, activeSide, source, destination,
|
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
export function isSameSwap(source, destination, inputWalletAddress, outputWalletAddress) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
outputWalletAddress &&
|
|
23
|
-
inputWalletAddress.toLowerCase() === outputWalletAddress.toLowerCase());
|
|
20
|
+
if (!source || !destination || !currenciesMatch(source, destination))
|
|
21
|
+
return false;
|
|
22
|
+
const chainType = getChainTypeByChainId(source.chain_id);
|
|
23
|
+
return Boolean(inputWalletAddress && outputWalletAddress && addressesMatch(inputWalletAddress, outputWalletAddress, chainType));
|
|
24
24
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { SwapKitProviderProps } from "../types";
|
|
2
|
-
export declare function SwapKitProvider({ apiKey, environment, mode, theme, children, }: SwapKitProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare function SwapKitProvider({ apiKey, environment, mode, theme, onConnect, onDisconnect, children, }: SwapKitProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useInWagmiContext } from "@coin-voyage/crypto/evm";
|
|
3
|
+
import { useConnectCallback } from "@coin-voyage/crypto/hooks";
|
|
3
4
|
import { ApiClient } from "@coin-voyage/shared/api";
|
|
4
5
|
import { generateSessionId } from "@coin-voyage/shared/utils";
|
|
5
6
|
import { useMemo, useState } from "react";
|
|
6
7
|
import { SwapKitContext } from "./swapkit-context";
|
|
7
8
|
import { swapkitVersion } from "../lib/version";
|
|
8
|
-
export function SwapKitProvider({ apiKey, environment = "production", mode = "auto", theme = {}, children, }) {
|
|
9
|
+
export function SwapKitProvider({ apiKey, environment = "production", mode = "auto", theme = {}, onConnect, onDisconnect, children, }) {
|
|
9
10
|
const inWalletContext = useInWagmiContext();
|
|
10
11
|
if (!inWalletContext)
|
|
11
12
|
throw new Error("SwapKitProvider must be used within a WalletProvider");
|
|
12
13
|
if (!apiKey.trim())
|
|
13
14
|
throw new Error("SwapKitProvider requires a public API key");
|
|
15
|
+
useConnectCallback({ onConnect, onDisconnect });
|
|
14
16
|
const [sessionId] = useState(generateSessionId);
|
|
15
17
|
const api = useMemo(() => new ApiClient({ apiKey, environment, sessionId, version: `swapkit/${swapkitVersion}` }), [apiKey, environment, sessionId]);
|
|
16
18
|
const context = useMemo(() => ({ api, environment, mode, theme }), [api, environment, mode, theme]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// @vitest-environment jsdom
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { SwapKitProvider } from "./swapkit-provider";
|
|
6
|
+
const useConnectCallback = vi.fn();
|
|
7
|
+
vi.mock("@coin-voyage/crypto/evm", () => ({
|
|
8
|
+
useInWagmiContext: () => true,
|
|
9
|
+
}));
|
|
10
|
+
vi.mock("@coin-voyage/crypto/hooks", () => ({
|
|
11
|
+
useConnectCallback: (props) => useConnectCallback(props),
|
|
12
|
+
}));
|
|
13
|
+
describe("SwapKitProvider", () => {
|
|
14
|
+
it("listens for connected-provider address changes", () => {
|
|
15
|
+
const onConnect = vi.fn();
|
|
16
|
+
const onDisconnect = vi.fn();
|
|
17
|
+
render(_jsx(SwapKitProvider, { apiKey: "public-api-key", onConnect: onConnect, onDisconnect: onDisconnect, children: _jsx("div", {}) }));
|
|
18
|
+
expect(useConnectCallback).toHaveBeenCalledWith({ onConnect, onDisconnect });
|
|
19
|
+
});
|
|
20
|
+
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { APIEnvironment } from "@coin-voyage/shared/api";
|
|
2
|
+
import type { useConnectCallbackProps } from "@coin-voyage/crypto/hooks";
|
|
2
3
|
import type { CurrencyBase } from "@coin-voyage/shared/types";
|
|
3
4
|
import type { ReactNode } from "react";
|
|
4
5
|
export type SwapKitMode = "light" | "dark" | "auto";
|
|
@@ -20,7 +21,7 @@ export interface SwapKitTheme {
|
|
|
20
21
|
shadow: string;
|
|
21
22
|
radius: string;
|
|
22
23
|
}
|
|
23
|
-
export interface SwapKitProviderProps {
|
|
24
|
+
export interface SwapKitProviderProps extends Pick<useConnectCallbackProps, "onConnect" | "onDisconnect"> {
|
|
24
25
|
apiKey: string;
|
|
25
26
|
environment?: APIEnvironment;
|
|
26
27
|
mode?: SwapKitMode;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coin-voyage/swapkit",
|
|
3
3
|
"description": "A reusable cross-chain swap component for CoinVoyage.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"author": "Lars <lars@coinvoyage.io>",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"LICENSE"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@coin-voyage/crypto": "3.
|
|
26
|
-
"@coin-voyage/shared": "3.
|
|
25
|
+
"@coin-voyage/crypto": "3.5.0",
|
|
26
|
+
"@coin-voyage/shared": "3.5.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@testing-library/react": "^16.3.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"typescript-plugin-styled-components": "^3.0.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@bigmi/react": "^0.
|
|
39
|
+
"@bigmi/react": "^0.9.1",
|
|
40
40
|
"@mysten/dapp-kit-react": "^2.1.4",
|
|
41
41
|
"@solana/wallet-adapter-react": "^0.15.39",
|
|
42
42
|
"@tanstack/react-query": "^5.90.6",
|