-
Notifications
You must be signed in to change notification settings - Fork 433
Add can-transfer check #4078
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stage
Are you sure you want to change the base?
Add can-transfer check #4078
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -41,3 +41,35 @@ export async function getTransferStatus( | |||||||||||||||||||||||||||||
return null; | ||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
interface CanTransferResponse { | ||||||||||||||||||||||||||||||
can_transfer: boolean; | ||||||||||||||||||||||||||||||
reason: string; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const denomOfInt3face: Record<string, string> = { | ||||||||||||||||||||||||||||||
DOGE: 'dogecoin-doge' | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+50
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for unsupported assets The mapping only contains one entry for DOGE. When this mapping is used in const denomOfInt3face: Record<string, string> = {
DOGE: 'dogecoin-doge'
}
+
+export function getInt3faceDenom(assetId: string): string {
+ const denom = denomOfInt3face[assetId];
+ if (!denom) {
+ throw new Error(`Unsupported asset ID: ${assetId}`);
+ }
+ return denom;
+} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
export async function checkCanTransfer( | ||||||||||||||||||||||||||||||
srcChainId: string | number, | ||||||||||||||||||||||||||||||
destChainId: string, | ||||||||||||||||||||||||||||||
assetId: string, | ||||||||||||||||||||||||||||||
env: "testnet" | "mainnet" | ||||||||||||||||||||||||||||||
): Promise<CanTransferResponse> { | ||||||||||||||||||||||||||||||
let srcChainIdConverted; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
if (typeof srcChainId === "string" && srcChainId.startsWith("osmosis")) { | ||||||||||||||||||||||||||||||
srcChainIdConverted = "osmosis" | ||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||
srcChainIdConverted = srcChainId.toString(); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const origin = env === "mainnet" | ||||||||||||||||||||||||||||||
? "https://api.mainnet.int3face.zone/int3face" | ||||||||||||||||||||||||||||||
: "https://api.testnet.int3face.zone/int3face"; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
const url = new URL(`/bridge/v1beta1/can-transfer/${srcChainIdConverted}/${destChainId}/${denomOfInt3face[assetId]}`, origin); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
return apiClient<CanTransferResponse>(url.toString()); | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
Comment on lines
+54
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling and use the safer denom lookup method The function needs to handle possible API errors and provide better context for debugging. Also, it should use a safer method to get the denom to avoid potential undefined values in the URL. export async function checkCanTransfer(
srcChainId: string | number,
destChainId: string,
assetId: string,
env: "testnet" | "mainnet"
): Promise<CanTransferResponse> {
let srcChainIdConverted;
if (typeof srcChainId === "string" && srcChainId.startsWith("osmosis")) {
srcChainIdConverted = "osmosis"
} else {
srcChainIdConverted = srcChainId.toString();
}
const origin = env === "mainnet"
? "https://api.mainnet.int3face.zone/int3face"
: "https://api.testnet.int3face.zone/int3face";
- const url = new URL(`/bridge/v1beta1/can-transfer/${srcChainIdConverted}/${destChainId}/${denomOfInt3face[assetId]}`, origin);
+ const denom = getInt3faceDenom(assetId);
+ const url = new URL(`/bridge/v1beta1/can-transfer/${srcChainIdConverted}/${destChainId}/${denom}`, origin);
- return apiClient<CanTransferResponse>(url.toString());
+ try {
+ return await apiClient<CanTransferResponse>(url.toString());
+ } catch (error) {
+ console.error(`Failed to check transfer availability: ${error}`);
+ // Rethrow the error to be handled by the caller
+ throw error;
+ }
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve null handling in the can-transfer check
The current check may not handle all edge cases properly. It's better to be more explicit about the conditions that should trigger the error.
This change makes the check more explicit by verifying both that the response exists and that the
can_transfer
property is specificallyfalse
. It also provides a more descriptive message when the reason is empty or whencanTransfer
is null.📝 Committable suggestion