diff --git a/src/handlers/multiversx/index.ts b/src/handlers/multiversx/index.ts index c553390a..8b1bef80 100644 --- a/src/handlers/multiversx/index.ts +++ b/src/handlers/multiversx/index.ts @@ -85,7 +85,7 @@ export function multiversxHandler({ ) ).data; return { - metaData: atob(response.uris[0]), + metaData: atob(response.uris[1]), royalties: response.royalties ?? 0, }; }; @@ -541,6 +541,11 @@ export function multiversxHandler({ ); return bal; }, + async getTransactionStatus(txHash) { + return (await waitForTransaction(txHash)).isSuccessful() + ? "success" + : "failed"; + }, }; } diff --git a/src/handlers/multiversx/types.ts b/src/handlers/multiversx/types.ts index 05c9c2ac..4351d463 100644 --- a/src/handlers/multiversx/types.ts +++ b/src/handlers/multiversx/types.ts @@ -68,7 +68,12 @@ export type TMultiversXHandler = TSingularNftChain< string > & ReadClaimed721Event & - ReadClaimed1155Event; + ReadClaimed1155Event & + TGetTransactionStatus; + +type TGetTransactionStatus = { + getTransactionStatus(txHash: string): Promise; +}; export type TMultiversXParams = { provider: INetworkProvider; diff --git a/src/handlers/utils/fetchHttpOrIpfs.ts b/src/handlers/utils/fetchHttpOrIpfs.ts index 458ed159..7443f9e0 100644 --- a/src/handlers/utils/fetchHttpOrIpfs.ts +++ b/src/handlers/utils/fetchHttpOrIpfs.ts @@ -1,17 +1,35 @@ import axios from "axios"; -export async function fetchHttpOrIpfs(uri: string) { +async function fetchWithFallback(uri: string, fallbackUri: string) { const http = axios.create(); + try { + const response = await http.get(uri, { timeout: 10000 }); + return response.data; + } catch (ex) { + try { + const response = await http.get(fallbackUri, { timeout: 10000 }); + return response.data; + } catch (ex) { + return ""; + } + } +} + +export async function fetchHttpOrIpfs(uri: string) { const url = new URL(uri); if (url.protocol === "http:" || url.protocol === "https:") { - const response = await http.get(uri); - return response.data; + return fetchWithFallback( + uri, + `${uri.replace("ipfs.io", "xpnetwork.infura-ipfs.io")}`, + ); } if (url.protocol === "ipfs:") { - const response = await http.get( - `https://ipfs.io/ipfs/${uri.replace("ipfs://", "")}`, - ); - return response.data; + const ipfsUri = `https://ipfs.io/ipfs/${uri.replace("ipfs://", "")}`; + const fallbackIpfsUri = `https://xpnetwork.infura-ipfs.io/ipfs/${uri.replace( + "ipfs://", + "", + )}`; + return fetchWithFallback(ipfsUri, fallbackIpfsUri); } throw new Error("Unsupported protocol"); }