@xswap-link/sdk 0.8.0 → 0.8.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.
- package/CHANGELOG.md +6 -0
- package/dist/index.global.js +107 -107
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/utils/validation.ts +20 -4
package/package.json
CHANGED
package/src/utils/validation.ts
CHANGED
|
@@ -42,14 +42,22 @@ const getDefaultDestinationChain = ({
|
|
|
42
42
|
return defaultTargetChain;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
const getDefaultSwapTokenForChain = (
|
|
45
|
+
const getDefaultSwapTokenForChain = (
|
|
46
|
+
chain: Chain,
|
|
47
|
+
sameChain?: boolean,
|
|
48
|
+
sourceTokenId?: string,
|
|
49
|
+
) => {
|
|
46
50
|
const xswapToken = chain.tokens.find((token) => token.tokenId === "XSWAP");
|
|
47
51
|
|
|
48
52
|
if (xswapToken) {
|
|
49
53
|
return xswapToken;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
const fallbackToken = chain.tokens.find((token) =>
|
|
56
|
+
const fallbackToken = chain.tokens.find((token) =>
|
|
57
|
+
sameChain
|
|
58
|
+
? token.supported && token.tokenId !== sourceTokenId
|
|
59
|
+
: token.supported,
|
|
60
|
+
);
|
|
53
61
|
|
|
54
62
|
if (fallbackToken) {
|
|
55
63
|
return fallbackToken;
|
|
@@ -164,7 +172,11 @@ export const mapToValidPath = ({
|
|
|
164
172
|
let newTargetToken: Token | undefined =
|
|
165
173
|
target.token ||
|
|
166
174
|
(type === "SWAP"
|
|
167
|
-
? getDefaultSwapTokenForChain(
|
|
175
|
+
? getDefaultSwapTokenForChain(
|
|
176
|
+
newTargetChain,
|
|
177
|
+
newSourceChain.chainId === newTargetChain.chainId,
|
|
178
|
+
newSourceToken?.tokenId,
|
|
179
|
+
)
|
|
168
180
|
: getDefaultBridgeTokenForChain({
|
|
169
181
|
chain: newTargetChain,
|
|
170
182
|
bridgeTokensDictionary,
|
|
@@ -305,7 +317,11 @@ export const mapToValidPath = ({
|
|
|
305
317
|
newSourceToken = getDefaultSwapTokenForChain(newSourceChain);
|
|
306
318
|
}
|
|
307
319
|
if (!newTargetToken) {
|
|
308
|
-
newTargetToken = getDefaultSwapTokenForChain(
|
|
320
|
+
newTargetToken = getDefaultSwapTokenForChain(
|
|
321
|
+
newTargetChain,
|
|
322
|
+
newSourceChain.chainId === newTargetChain.chainId,
|
|
323
|
+
newSourceToken?.tokenId,
|
|
324
|
+
);
|
|
309
325
|
}
|
|
310
326
|
} else {
|
|
311
327
|
if (!newSourceToken) {
|