Skip to content

Commit

Permalink
fix: update indexer urls to FastNear (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiParraCrespo authored Dec 5, 2024
1 parent 0c30805 commit 423b660
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/lib/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
});

Expand All @@ -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",
});
});

Expand All @@ -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",
});
});

Expand All @@ -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",
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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 {
networkId,
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}'`);
Expand Down
16 changes: 7 additions & 9 deletions packages/modal-ui-js/src/lib/render-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,19 @@ const getAccountIds = async (publicKey: string): Promise<Array<string>> => {
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<string>; 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 (
Expand Down
16 changes: 7 additions & 9 deletions packages/modal-ui/src/lib/components/DerivationPath.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,19 @@ export const DerivationPath: React.FC<DerivationPathProps> = ({
const [headerTitle, setHeaderTitle] = useState(initalHeaderTitle);

const getAccountIds = async (publicKey: string): Promise<Array<string>> => {
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<string>; 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 (
Expand Down

0 comments on commit 423b660

Please sign in to comment.