From 423b660a62c75a77297b2fdd648921bf0d23328c Mon Sep 17 00:00:00 2001 From: JordiParraCrespo <52425638+JordiParraCrespo@users.noreply.github.com> Date: Thu, 5 Dec 2024 19:45:53 +0100 Subject: [PATCH] fix: update indexer urls to FastNear (#1265) --- packages/core/src/lib/options.spec.ts | 8 ++++---- packages/core/src/lib/options.ts | 4 ++-- packages/modal-ui-js/src/lib/render-modal.ts | 16 +++++++--------- .../src/lib/components/DerivationPath.tsx | 16 +++++++--------- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/packages/core/src/lib/options.spec.ts b/packages/core/src/lib/options.spec.ts index a347e3758..533f9b948 100644 --- a/packages/core/src/lib/options.spec.ts +++ b/packages/core/src/lib/options.spec.ts @@ -11,7 +11,7 @@ describe("getNetworkPreset", () => { nodeUrl: "https://rpc.mainnet.near.org", helperUrl: "https://helper.mainnet.near.org", explorerUrl: "https://nearblocks.io", - indexerUrl: "https://api.kitwallet.app", + indexerUrl: "https://api.fastnear.com/v0", }); }); @@ -29,7 +29,7 @@ describe("getNetworkPreset", () => { nodeUrl: "https://rpc1.mainnet.near.org", helperUrl: "https://helper.mainnet.near.org", explorerUrl: "https://nearblocks.io", - indexerUrl: "https://api.kitwallet.app", + indexerUrl: "https://api.fastnear.com/v0", }); }); @@ -42,7 +42,7 @@ describe("getNetworkPreset", () => { nodeUrl: "https://rpc.testnet.near.org", helperUrl: "https://helper.testnet.near.org", explorerUrl: "https://testnet.nearblocks.io", - indexerUrl: "https://testnet-api.kitwallet.app", + indexerUrl: "https://test.api.fastnear.com/v0", }); }); @@ -60,7 +60,7 @@ describe("getNetworkPreset", () => { nodeUrl: "https://rpc1.testnet.near.org", helperUrl: "https://helper.testnet.near.org", explorerUrl: "https://testnet.nearblocks.io", - indexerUrl: "https://testnet-api.kitwallet.app", + indexerUrl: "https://test.api.fastnear.com/v0", }); }); }); diff --git a/packages/core/src/lib/options.ts b/packages/core/src/lib/options.ts index 7a5cf0dd5..0483aca28 100644 --- a/packages/core/src/lib/options.ts +++ b/packages/core/src/lib/options.ts @@ -13,7 +13,7 @@ export const getNetworkPreset = ( nodeUrl: fallbackRpcUrls?.[0] || "https://rpc.mainnet.near.org", helperUrl: "https://helper.mainnet.near.org", explorerUrl: "https://nearblocks.io", - indexerUrl: "https://api.kitwallet.app", + indexerUrl: "https://api.fastnear.com/v0", }; case "testnet": return { @@ -21,7 +21,7 @@ export const getNetworkPreset = ( nodeUrl: fallbackRpcUrls?.[0] || "https://rpc.testnet.near.org", helperUrl: "https://helper.testnet.near.org", explorerUrl: "https://testnet.nearblocks.io", - indexerUrl: "https://testnet-api.kitwallet.app", + indexerUrl: "https://test.api.fastnear.com/v0", }; default: throw Error(`Failed to find config for: '${networkId}'`); diff --git a/packages/modal-ui-js/src/lib/render-modal.ts b/packages/modal-ui-js/src/lib/render-modal.ts index fee984a8c..29fe6f1e7 100644 --- a/packages/modal-ui-js/src/lib/render-modal.ts +++ b/packages/modal-ui-js/src/lib/render-modal.ts @@ -29,21 +29,19 @@ const getAccountIds = async (publicKey: string): Promise> => { return []; } - const response = await fetch( - `${modalState.selector.options.network.indexerUrl}/publicKey/ed25519:${publicKey}/accounts` - ); + const url = `${modalState.selector.options.network.indexerUrl}/public_key/ed25519:${publicKey}`; + const response = await fetch(url); if (!response.ok) { - throw new Error("Failed to get account id from public key"); + throw new Error("Failed to get account ID from public key"); } - const accountIds = await response.json(); + const jsonResponse: { account_ids: Array; public_key: string } = + await response.json(); - if (!Array.isArray(accountIds) || !accountIds.length) { - return []; - } + const { account_ids: accountIds } = jsonResponse; - return accountIds; + return Array.isArray(accountIds) ? accountIds : []; }; export const resolveAccounts = async ( diff --git a/packages/modal-ui/src/lib/components/DerivationPath.tsx b/packages/modal-ui/src/lib/components/DerivationPath.tsx index 621f7a1e2..ce944b25f 100644 --- a/packages/modal-ui/src/lib/components/DerivationPath.tsx +++ b/packages/modal-ui/src/lib/components/DerivationPath.tsx @@ -69,21 +69,19 @@ export const DerivationPath: React.FC = ({ const [headerTitle, setHeaderTitle] = useState(initalHeaderTitle); const getAccountIds = async (publicKey: string): Promise> => { - const response = await fetch( - `${selector.options.network.indexerUrl}/publicKey/ed25519:${publicKey}/accounts` - ); + const url = `${selector.options.network.indexerUrl}/public_key/ed25519:${publicKey}`; + const response = await fetch(url); if (!response.ok) { - throw new Error("Failed to get account id from public key"); + throw new Error("Failed to get account ID from public key"); } - const accountIds = await response.json(); + const jsonResponse: { account_ids: Array; public_key: string } = + await response.json(); - if (!Array.isArray(accountIds) || !accountIds.length) { - return []; - } + const { account_ids: accountIds } = jsonResponse; - return accountIds; + return Array.isArray(accountIds) ? accountIds : []; }; const resolveAccounts = async (