@shapeshiftoss/swap-widget 0.1.0 → 0.2.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 ShapeShift
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -18,7 +18,7 @@ An embeddable React widget that enables multi-chain token swaps using ShapeShift
18
18
  ## Installation
19
19
 
20
20
  ```bash
21
- yarn add @shapeshiftoss/swap-widget
21
+ pnpm add @shapeshiftoss/swap-widget
22
22
  # or
23
23
  npm install @shapeshiftoss/swap-widget
24
24
  ```
@@ -44,7 +44,7 @@ import { SwapWidget } from "@shapeshiftoss/swap-widget";
44
44
  function App() {
45
45
  return (
46
46
  <SwapWidget
47
- affiliateAddress="0xYourArbitrumAddress"
47
+ partnerCode="your-partner-code"
48
48
  theme="dark"
49
49
  onSwapSuccess={(txHash) => console.log("Success:", txHash)}
50
50
  onSwapError={(error) => console.error("Error:", error)}
@@ -59,7 +59,7 @@ function App() {
59
59
 
60
60
  | Prop | Type | Default | Description |
61
61
  | ------------------------ | ----------------------------------------------- | ---------------- | ---------------------------------------------------------------------------------------------------------- |
62
- | `affiliateAddress` | `string` | - | Your Arbitrum address for affiliate fee attribution. Optional the widget works without it. |
62
+ | `partnerCode` | `string` | - | Your registered partner code for affiliate fee attribution. Register at the affiliate dashboard. |
63
63
  | `apiBaseUrl` | `string` | - | Custom API base URL. Useful for testing or custom deployments. |
64
64
  | `defaultSellAsset` | `Asset` | ETH on Ethereum | Initial asset to sell. |
65
65
  | `defaultBuyAsset` | `Asset` | USDC on Ethereum | Initial asset to buy. |
@@ -132,7 +132,7 @@ function App() {
132
132
  import { SwapWidget } from "@shapeshiftoss/swap-widget";
133
133
 
134
134
  function App() {
135
- return <SwapWidget affiliateAddress="0xYourArbitrumAddress" theme="dark" />;
135
+ return <SwapWidget partnerCode="your-partner-code" theme="dark" />;
136
136
  }
137
137
  ```
138
138
 
@@ -149,7 +149,7 @@ function App() {
149
149
 
150
150
  return (
151
151
  <SwapWidget
152
- affiliateAddress="0xYourArbitrumAddress"
152
+ partnerCode="your-partner-code"
153
153
  walletClient={walletClient}
154
154
  onConnectWallet={() => {
155
155
  // Your custom wallet connection logic
@@ -198,7 +198,7 @@ const defaultBuyAsset: Asset = {
198
198
  function App() {
199
199
  return (
200
200
  <SwapWidget
201
- affiliateAddress="0xYourArbitrumAddress"
201
+ partnerCode="your-partner-code"
202
202
  defaultSellAsset={defaultSellAsset}
203
203
  defaultBuyAsset={defaultBuyAsset}
204
204
  theme="dark"
@@ -217,7 +217,7 @@ import { SwapWidget, EVM_CHAIN_IDS } from "@shapeshiftoss/swap-widget";
217
217
  function App() {
218
218
  return (
219
219
  <SwapWidget
220
- affiliateAddress="0xYourArbitrumAddress"
220
+ partnerCode="your-partner-code"
221
221
  allowedChainIds={[
222
222
  EVM_CHAIN_IDS.ethereum,
223
223
  EVM_CHAIN_IDS.polygon,
@@ -242,7 +242,7 @@ import { SwapWidget } from "@shapeshiftoss/swap-widget";
242
242
  function App() {
243
243
  return (
244
244
  <SwapWidget
245
- affiliateAddress="0xYourArbitrumAddress"
245
+ partnerCode="your-partner-code"
246
246
  enableWalletConnection={true}
247
247
  walletConnectProjectId="your-walletconnect-project-id"
248
248
  theme="dark"
@@ -267,7 +267,7 @@ import { SwapWidget } from "@shapeshiftoss/swap-widget";
267
267
  function App() {
268
268
  return (
269
269
  <SwapWidget
270
- affiliateAddress="0xYourArbitrumAddress"
270
+ partnerCode="your-partner-code"
271
271
  defaultReceiveAddress="0x1234567890abcdef1234567890abcdef12345678"
272
272
  theme="dark"
273
273
  />
@@ -481,9 +481,16 @@ The widget supports swaps across multiple blockchain types:
481
481
  - **Solana swaps** - Solana transactions can be signed via Phantom, Solflare, or other Solana wallets when using the built-in wallet connection.
482
482
  - **Unsupported chains** - Swaps involving chains without wallet support will redirect to [app.shapeshift.com](https://app.shapeshift.com) to complete the transaction.
483
483
 
484
- ### Affiliate Address
484
+ ### Partner Codes
485
485
 
486
- An affiliate address is optional. Pass your Arbitrum address via the `affiliateAddress` prop to attribute swaps for affiliate fee tracking. The widget works without it no registration or approval required.
486
+ Register an affiliate account at the affiliate dashboard and claim a partner code (e.g. `vultisig`, `venice`). Pass it via the `partnerCode` prop on the widget, or the `X-Partner-Code` header when using the REST API directly:
487
+
488
+ ```
489
+ GET /v1/swap/rates?...
490
+ X-Partner-Code: your-partner-code
491
+ ```
492
+
493
+ The API resolves the partner code to the registered affiliate address and BPS automatically.
487
494
 
488
495
  ### Internal QueryClient
489
496
 
package/package.json CHANGED
@@ -1,20 +1,19 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/swap-widget",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Embeddable swap widget using ShapeShift API",
5
+ "repository": "https://github.com/shapeshift/web",
6
+ "license": "MIT",
5
7
  "type": "module",
6
- "main": "dist/index.js",
7
- "module": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
9
- "style": "dist/style.css",
9
+ "style": "dist/index.css",
10
10
  "exports": {
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.js",
14
14
  "default": "./dist/index.js"
15
15
  },
16
- "./style.css": "./dist/style.css",
17
- "./dist/style.css": "./dist/style.css"
16
+ "./style.css": "./dist/index.css"
18
17
  },
19
18
  "sideEffects": [
20
19
  "*.css"
@@ -23,28 +22,20 @@
23
22
  "dist",
24
23
  "README.md"
25
24
  ],
26
- "scripts": {
27
- "dev": "BUILD_DEMO=true vite",
28
- "build": "vite build",
29
- "build:demo": "BUILD_DEMO=true vite build",
30
- "preview": "vite preview",
31
- "lint": "eslint src --ext .ts,.tsx",
32
- "lint:fix": "eslint src --ext .ts,.tsx --fix",
33
- "type-check": "tsc --noEmit",
34
- "test": "vitest run",
35
- "test:watch": "vitest"
36
- },
37
25
  "dependencies": {
38
- "@shapeshiftoss/caip": "^8.0.0",
39
- "@shapeshiftoss/types": "^8.0.0",
40
- "@shapeshiftoss/utils": "^1.0.0",
41
26
  "@xstate/react": "5.0.5",
42
27
  "bech32": "^2.0.0",
28
+ "bs58check": "^4.0.0",
29
+ "cashaddrjs": "^0.3.12",
43
30
  "p-queue": "^8.0.1",
44
31
  "react-virtuoso": "^4.7.11",
45
- "xstate": "5.28.0"
32
+ "xstate": "5.28.0",
33
+ "@shapeshiftoss/caip": "^8.16.7",
34
+ "@shapeshiftoss/utils": "^1.0.5",
35
+ "@shapeshiftoss/types": "^8.6.7"
46
36
  },
47
37
  "peerDependencies": {
38
+ "@wagmi/core": "^2.0.0",
48
39
  "@reown/appkit": "^1.8.17",
49
40
  "@reown/appkit-adapter-bitcoin": "^1.8.17",
50
41
  "@reown/appkit-adapter-solana": "^1.8.17",
@@ -52,9 +43,9 @@
52
43
  "@solana/wallet-adapter-wallets": "^0.19.32",
53
44
  "@solana/web3.js": "^1.98.0",
54
45
  "@tanstack/react-query": "^5.69.0",
55
- "react": ">=18.0.0",
56
- "react-dom": ">=18.0.0",
57
- "viem": "^2.40.0",
46
+ "react": "^18.0.0 || ^19.0.0",
47
+ "react-dom": "^18.0.0 || ^19.0.0",
48
+ "viem": "^2.43.5",
58
49
  "wagmi": "^3.3.0"
59
50
  },
60
51
  "peerDependenciesMeta": {
@@ -78,33 +69,40 @@
78
69
  }
79
70
  },
80
71
  "devDependencies": {
72
+ "@wagmi/core": "^2.0.0",
81
73
  "@reown/appkit": "^1.8.17",
82
74
  "@reown/appkit-adapter-bitcoin": "^1.8.17",
83
75
  "@reown/appkit-adapter-solana": "^1.8.17",
84
76
  "@reown/appkit-adapter-wagmi": "^1.8.17",
85
- "@shapeshiftoss/caip": "^8.16.7",
86
- "@shapeshiftoss/types": "^8.6.7",
87
- "@shapeshiftoss/utils": "^1.0.6",
88
77
  "@solana/wallet-adapter-wallets": "^0.19.32",
89
78
  "@solana/web3.js": "1.98.0",
90
79
  "@tanstack/react-query": "^5.69.0",
91
80
  "@testing-library/jest-dom": "6.9.1",
92
81
  "@testing-library/react": "16.3.2",
82
+ "@types/node": "^22.0.0",
93
83
  "@types/react": "^19.0.0",
94
84
  "@types/react-dom": "^19.0.0",
95
85
  "@vitejs/plugin-react": "^4.2.0",
96
86
  "jsdom": "28.0.0",
97
87
  "react": "^19.0.0",
98
88
  "react-dom": "^19.0.0",
89
+ "tsup": "^8.5.1",
99
90
  "typescript": "~5.2.2",
100
- "viem": "2.40.3",
91
+ "viem": "2.43.5",
101
92
  "vite": "^5.0.0",
102
- "vite-plugin-dts": "^4.5.4",
103
93
  "vite-plugin-node-polyfills": "0.23.0",
104
94
  "vitest": "4.0.18",
105
95
  "wagmi": "3.3.2"
106
96
  },
107
97
  "publishConfig": {
108
98
  "access": "public"
99
+ },
100
+ "scripts": {
101
+ "clean": "rm -rf dist node_modules",
102
+ "build": "rm -rf dist && tsc && tsup",
103
+ "build:demo": "rm -rf dist && vite build",
104
+ "dev": "vite",
105
+ "preview": "vite preview",
106
+ "test": "vitest run"
109
107
  }
110
108
  }
package/dist/index.d.ts DELETED
@@ -1,233 +0,0 @@
1
- import { Asset as Asset_2 } from '@shapeshiftoss/types';
2
- import { AssetId } from '@shapeshiftoss/caip';
3
- import { ChainId } from '@shapeshiftoss/caip';
4
- import { JSX } from 'react/jsx-runtime';
5
- import { UseQueryResult } from '@tanstack/react-query';
6
- import { WalletClient } from 'viem';
7
-
8
- export declare type Asset = {
9
- assetId: AssetId;
10
- chainId: ChainId;
11
- symbol: string;
12
- name: string;
13
- precision: number;
14
- icon?: string;
15
- color?: string;
16
- networkName?: string;
17
- networkIcon?: string;
18
- explorer?: string;
19
- explorerTxLink?: string;
20
- explorerAddressLink?: string;
21
- relatedAssetKey?: AssetId | null;
22
- };
23
-
24
- export { AssetId }
25
-
26
- declare type AssetQueryResult<TData> = Omit<UseQueryResult<RawAssetData>, 'data'> & {
27
- data: TData;
28
- };
29
-
30
- export declare type Chain = {
31
- chainId: ChainId;
32
- name: string;
33
- icon: string;
34
- color: string;
35
- nativeAssetId: AssetId;
36
- };
37
-
38
- export { ChainId }
39
-
40
- declare type ChainInfo = {
41
- chainId: ChainId;
42
- name: string;
43
- icon?: string;
44
- color?: string;
45
- nativeAsset: Asset;
46
- };
47
-
48
- export declare const COSMOS_CHAIN_IDS: {
49
- readonly cosmos: ChainId;
50
- readonly thorchain: ChainId;
51
- readonly mayachain: ChainId;
52
- };
53
-
54
- export declare const EVM_CHAIN_IDS: {
55
- readonly ethereum: ChainId;
56
- readonly arbitrum: ChainId;
57
- readonly optimism: ChainId;
58
- readonly polygon: ChainId;
59
- readonly base: ChainId;
60
- readonly avalanche: ChainId;
61
- readonly bsc: ChainId;
62
- readonly gnosis: ChainId;
63
- readonly monad: ChainId;
64
- readonly hyperEvm: ChainId;
65
- readonly plasma: ChainId;
66
- readonly worldChain: ChainId;
67
- readonly katana: ChainId;
68
- };
69
-
70
- export declare const formatAmount: (amount: string, decimals: number, maxDecimals?: number) => string;
71
-
72
- export declare const getBaseAsset: (chainId: ChainId) => Asset_2 | undefined;
73
-
74
- export declare const getChainColor: (chainId: ChainId) => string;
75
-
76
- export declare const getChainIcon: (chainId: ChainId) => string | undefined;
77
-
78
- export declare const getChainName: (chainId: ChainId) => string;
79
-
80
- export declare const getChainType: (chainId: string) => 'evm' | 'utxo' | 'cosmos' | 'solana' | 'other';
81
-
82
- export declare const getEvmNetworkId: (chainId: string) => number;
83
-
84
- export declare const getExplorerTxLink: (chainId: ChainId) => string;
85
-
86
- export declare const isEvmChainId: (chainId: string) => boolean;
87
-
88
- export declare const OTHER_CHAIN_IDS: {
89
- readonly solana: ChainId;
90
- };
91
-
92
- export declare const parseAmount: (amount: string, decimals: number) => string;
93
-
94
- declare type RawAssetData = {
95
- byId: Record<AssetId, Asset>;
96
- ids: AssetId[];
97
- };
98
-
99
- export declare enum SwapperName {
100
- Thorchain = "THORChain",
101
- Mayachain = "MAYAChain",
102
- CowSwap = "CoW Swap",
103
- Zrx = "0x",
104
- ArbitrumBridge = "Arbitrum Bridge",
105
- Portals = "Portals",
106
- Chainflip = "Chainflip",
107
- Jupiter = "Jupiter",
108
- Relay = "Relay",
109
- ButterSwap = "ButterSwap",
110
- Bebop = "Bebop",
111
- NearIntents = "NEAR Intents",
112
- Cetus = "Cetus",
113
- Sunio = "Sun.io",
114
- Avnu = "AVNU"
115
- }
116
-
117
- export declare const SwapWidget: (props: SwapWidgetProps) => JSX.Element;
118
-
119
- export declare type SwapWidgetProps = {
120
- affiliateAddress?: string;
121
- affiliateBps?: string;
122
- apiBaseUrl?: string;
123
- defaultSellAsset?: Asset;
124
- defaultBuyAsset?: Asset;
125
- disabledChainIds?: ChainId[];
126
- disabledAssetIds?: AssetId[];
127
- allowedChainIds?: ChainId[];
128
- sellDisabledChainIds?: ChainId[];
129
- buyDisabledChainIds?: ChainId[];
130
- sellDisabledAssetIds?: AssetId[];
131
- buyDisabledAssetIds?: AssetId[];
132
- sellAllowedChainIds?: ChainId[];
133
- buyAllowedChainIds?: ChainId[];
134
- sellAllowedAssetIds?: AssetId[];
135
- buyAllowedAssetIds?: AssetId[];
136
- allowedSwapperNames?: SwapperName[];
137
- walletClient?: WalletClient;
138
- onConnectWallet?: () => void;
139
- onSwapSuccess?: (txHash: string) => void;
140
- onSwapError?: (error: Error) => void;
141
- onAssetSelect?: (type: 'sell' | 'buy', asset: Asset) => void;
142
- theme?: ThemeMode | ThemeConfig;
143
- defaultSlippage?: string;
144
- showPoweredBy?: boolean;
145
- enableWalletConnection?: boolean;
146
- walletConnectProjectId?: string;
147
- defaultReceiveAddress?: string;
148
- ratesRefetchInterval?: number;
149
- isBuyAssetLocked?: boolean;
150
- };
151
-
152
- export declare type ThemeConfig = {
153
- mode: ThemeMode;
154
- accentColor?: string;
155
- backgroundColor?: string;
156
- cardColor?: string;
157
- textColor?: string;
158
- borderRadius?: string;
159
- fontFamily?: string;
160
- borderColor?: string;
161
- secondaryTextColor?: string;
162
- mutedTextColor?: string;
163
- inputColor?: string;
164
- hoverColor?: string;
165
- buttonVariant?: 'filled' | 'outline';
166
- };
167
-
168
- export declare type ThemeMode = 'light' | 'dark';
169
-
170
- export declare type TradeQuote = {
171
- id: string;
172
- rate: string;
173
- swapperName: SwapperName;
174
- steps: TradeQuoteStep[];
175
- receiveAddress: string;
176
- affiliateBps: string;
177
- slippageTolerancePercentageDecimal?: string;
178
- isStreaming?: boolean;
179
- };
180
-
181
- declare type TradeQuoteStep = {
182
- sellAsset: Asset;
183
- buyAsset: Asset;
184
- sellAmountCryptoBaseUnit: string;
185
- buyAmountCryptoBaseUnit: string;
186
- rate: string;
187
- source: SwapperName;
188
- feeData: {
189
- networkFeeCryptoBaseUnit: string;
190
- protocolFees?: Record<AssetId, {
191
- amountCryptoBaseUnit: string;
192
- }>;
193
- };
194
- allowanceContract?: string;
195
- estimatedExecutionTimeMs?: number;
196
- };
197
-
198
- export declare type TradeRate = {
199
- swapperName: SwapperName;
200
- rate: string;
201
- buyAmountCryptoBaseUnit: string;
202
- sellAmountCryptoBaseUnit: string;
203
- steps: number;
204
- estimatedExecutionTimeMs?: number;
205
- affiliateBps: string;
206
- networkFeeCryptoBaseUnit?: string;
207
- error?: {
208
- code: string;
209
- message: string;
210
- };
211
- id?: string;
212
- };
213
-
214
- export declare const truncateAddress: (address: string, chars?: number) => string;
215
-
216
- export declare const useAssetById: (assetId: AssetId | undefined) => AssetQueryResult<Asset | undefined>;
217
-
218
- export declare const useAssets: () => AssetQueryResult<Asset[]>;
219
-
220
- export declare const useAssetsByChainId: (chainId: ChainId | undefined) => AssetQueryResult<Asset[]>;
221
-
222
- export declare const useAssetSearch: (query: string, chainId?: ChainId) => AssetQueryResult<Asset[]>;
223
-
224
- export declare const useChains: () => AssetQueryResult<ChainInfo[]>;
225
-
226
- export declare const UTXO_CHAIN_IDS: {
227
- readonly bitcoin: ChainId;
228
- readonly bitcoinCash: ChainId;
229
- readonly dogecoin: ChainId;
230
- readonly litecoin: ChainId;
231
- };
232
-
233
- export { }