Skip to content
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

Feature/improve api error states #1233

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions @shared/api/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,22 +669,17 @@ export const getIndexerAccountHistory = async ({
publicKey: string;
networkDetails: NetworkDetails;
}): Promise<Horizon.ServerApi.OperationRecord[]> => {
try {
const url = new URL(
`${INDEXER_URL}/account-history/${publicKey}?network=${networkDetails.network}`,
);
const response = await fetch(url.href);

const data = await response.json();
if (!response.ok) {
throw new Error(data);
}
const url = new URL(
`${INDEXER_URL}/account-history/${publicKey}?network=${networkDetails.network}`,
);
const response = await fetch(url.href);

return data;
} catch (e) {
console.error(e);
return [];
const data = await response.json();
if (!response.ok) {
throw new Error(data);
}

return data;
};

export const getAssetIcons = async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ import IconCube from "popup/assets/icon-cube.svg";
import "./styles.scss";

interface AccountHeaderProps {
// accountDropDownRef: React.RefObject<HTMLDivElement>;
allAccounts: Account[];
currentAccountName: string;
publicKey: string;
setLoading: (isLoading: boolean) => void;
}

export const AccountHeader = ({
// accountDropDownRef,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this just an unused prop now? should we get rid of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup it is, at some point it went from an unused prop to a commented out one so I deleted it.

allAccounts,
currentAccountName,
publicKey,
Expand Down
2 changes: 2 additions & 0 deletions extension/src/popup/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"Executable Wasm Hash": "Executable Wasm Hash",
"Extend To": "Extend To",
"Failed to fetch your account balances": "Failed to fetch your account balances.",
"Failed to fetch your account history": "Failed to fetch your account history.",
"FEDERATION ADDRESS": "FEDERATION ADDRESS",
"Fee": "Fee",
"Fees can vary depending on the network congestion": {
Expand Down Expand Up @@ -510,6 +511,7 @@
" Please review the transaction and try again": "Your account balance is not sufficient for this transaction. Please review the transaction and try again."
},
"Your account balances could not be fetched at this time": "Your account balances could not be fetched at this time.",
"Your account history could not be fetched at this time": "Your account history could not be fetched at this time.",
"Your Freighter install is complete": "Your Freighter install is complete",
"Your recovery phrase gives you access to your account and is the": "Your recovery phrase gives you access to your account and is the",
"Your Stellar secret key": "Your Stellar secret key"
Expand Down
2 changes: 2 additions & 0 deletions extension/src/popup/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"Executable Wasm Hash": "Executable Wasm Hash",
"Extend To": "Extend To",
"Failed to fetch your account balances": "Failed to fetch your account balances.",
"Failed to fetch your account history": "Failed to fetch your account history.",
"FEDERATION ADDRESS": "FEDERATION ADDRESS",
"Fee": "Fee",
"Fees can vary depending on the network congestion": {
Expand Down Expand Up @@ -510,6 +511,7 @@
" Please review the transaction and try again": "Your account balance is not sufficient for this transaction. Please review the transaction and try again."
},
"Your account balances could not be fetched at this time": "Your account balances could not be fetched at this time.",
"Your account history could not be fetched at this time": "Your account history could not be fetched at this time.",
"Your Freighter install is complete": "Your Freighter install is complete",
"Your recovery phrase gives you access to your account and is the": "Your recovery phrase gives you access to your account and is the",
"Your Stellar secret key": "Your Stellar secret key"
Expand Down
2 changes: 1 addition & 1 deletion extension/src/popup/views/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ export const Account = () => {
) : (
<>
<AccountHeader
// accountDropDownRef={accountDropDownRef}
allAccounts={allAccounts}
currentAccountName={currentAccountName}
publicKey={publicKey}
Expand Down Expand Up @@ -246,6 +245,7 @@ export const Account = () => {
</div>
<div className="AccountView__send-receive-button">
<NavButton
disabled={hasError}
showBorder
title={t("Send Payment")}
id="nav-btn-send"
Expand Down
14 changes: 13 additions & 1 deletion extension/src/popup/views/AccountHistory/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useEffect, useState } from "react";
import { useSelector, useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";
import { Loader } from "@stellar/design-system";
import { Loader, Notification } from "@stellar/design-system";
import { Horizon } from "stellar-sdk";
import { captureException } from "@sentry/browser";

import {
getAccountHistoryStandalone,
Expand Down Expand Up @@ -76,6 +77,7 @@ export const AccountHistory = () => {
defaultDetailViewProps,
);
const [isLoading, setIsLoading] = useState(false);
const [hasHistoryError, setHasHistoryError] = React.useState(false);

const stellarExpertUrl = getStellarExpertUrl(networkDetails);

Expand Down Expand Up @@ -144,6 +146,8 @@ export const AccountHistory = () => {
}
setHistorySegments(createSegments(operations));
} catch (e) {
captureException(`Failed to fetch account history - ${e}`);
setHasHistoryError(true);
console.error(e);
}
};
Expand Down Expand Up @@ -215,6 +219,14 @@ export const AccountHistory = () => {
</div>
)}
</div>
{hasHistoryError && (
<Notification
variant="error"
title={t("Failed to fetch your account history.")}
>
{t("Your account history could not be fetched at this time.")}
</Notification>
)}
</>
)}
</div>
Expand Down
Loading