Skip to content

Commit

Permalink
fix: disable rango from ui on unsupported networks
Browse files Browse the repository at this point in the history
  • Loading branch information
NickKelly1 committed Jan 3, 2025
1 parent eec3ed6 commit 5a31c56
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
18 changes: 15 additions & 3 deletions packages/swap/src/providers/paraswap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class ParaSwap extends ProviderClass {
.then((res) => res.json())
.then(async (response: ParaswapResponseType) => {
if (response.error) {
console.error(response.error);
console.error("Error in swap response from ParaSwap", response.error);
return Promise.resolve(null);
}
const transactions: EVMTransaction[] = [];
Expand Down Expand Up @@ -245,7 +245,7 @@ class ParaSwap extends ProviderClass {
};
})
.catch((e) => {
console.error(e);
console.error("Error generating swap from ParaSwap", e);
return Promise.resolve(null);
});
}
Expand Down Expand Up @@ -283,6 +283,18 @@ class ParaSwap extends ProviderClass {
.then((j) => j.json())
.then(async (jsonRes) => {
if (!jsonRes) return null;
// Note: sometimes `jsonRes.priceRoute` is undefined and "error" is set instead
if (!jsonRes.priceRoute) {
if (jsonRes.error) {
// Sometimes ParaSwap returns this error: "No routes found with enough liquidity"
throw new Error(`ParaSwap error getting prices: ${jsonRes.error}`);
} else {
// Didn't have the expected "priceRoute" property
throw new Error(
`ParaSwap error getting prices, no "priceRoute" property on response: ${JSON.stringify(jsonRes)}`,
);
}
}
const res: ParaswpQuoteResponse = jsonRes.priceRoute;
const transactions: EVMTransaction[] = [];
if (options.fromToken.address !== NATIVE_TOKEN_ADDRESS) {
Expand Down Expand Up @@ -320,7 +332,7 @@ class ParaSwap extends ProviderClass {
return response;
})
.catch((e) => {
console.error(e);
console.error("Error getting quote from ParaSwap", e);
return Promise.resolve(null);
});
}
Expand Down
15 changes: 14 additions & 1 deletion packages/swap/src/providers/rango/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ class Rango extends ProviderClass {
async init(tokenList?: TokenType[]): Promise<void> {
logger.info(`init: Initialising against ${tokenList?.length} tokens...`);

if (!Rango.isNetworkSupportedByEnkrypt(this.network)) {
logger.info(
`init: Enkrypt does not support network on Rango: ${this.network}`,
);
return;
}

const [rangoMeta, swaplist] = await Promise.all([
rangoClient.meta({
excludeNonPopulars: true,
Expand Down Expand Up @@ -429,10 +436,16 @@ class Rango extends ProviderClass {
return matchingRangoBlockchain;
}

static isNetworkSupportedByEnkrypt(
supportedNetworkName: SupportedNetworkName,
): boolean {
return supportedNetworkInfoByName.has(supportedNetworkName);
}

/**
* Is this network supported by both enkrypt and rango?
*/
static isNetworkSupported(
static isNetworkSupportedByEnkryptAndRango(
supportedNetworkName: SupportedNetworkName,
rangoBlockchains: ReadonlyArray<BlockchainMeta>,
): boolean {
Expand Down
3 changes: 1 addition & 2 deletions packages/swap/src/providers/rango/supported.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SupportedNetworkName, } from '../../types'
import { SupportedNetworkName } from "../../types";

export type SupportedNetworkInfo = {
/** Standard base10 chain ID, can be obtained from `https://chainlist.org` */
Expand Down Expand Up @@ -179,4 +179,3 @@ export const supportedNetworkByRangoBlockchain = new Map<
},
]),
);

4 changes: 1 addition & 3 deletions packages/swap/tests/changelly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ describe("Changelly Provider", () => {
(swap?.transactions[0] as EVMTransaction).data.startsWith("0xa9059cbb"),
).to.be.eq(true);
const status = await changelly.getStatus(
(
await swap!.getStatusObject({ transactions: [] })
).options,
(await swap!.getStatusObject({ transactions: [] })).options,
);
expect(status).to.be.eq("pending");
});
Expand Down

0 comments on commit 5a31c56

Please sign in to comment.