Skip to content

Commit

Permalink
[WIP] Feature/auto horizon error (#1195)
Browse files Browse the repository at this point in the history
* first pass at adding horizon and generic notifications

* Added translations

* fix translations

* fix sentry errors

* update error type

* fix error

* show horizon error msg
  • Loading branch information
piyalbasu authored Mar 15, 2024
1 parent f54fbae commit bca1455
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 5 deletions.
6 changes: 6 additions & 0 deletions @shared/api/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ export const getAccountIndexerBalances = async (
throw new Error(_err);
}

if ("error" in data && (data?.error?.horizon || data?.error?.soroban)) {
const _err = JSON.stringify(data.error);
captureException(`Failed to fetch account balances - ${_err}`);
}

const formattedBalances = {} as NonNullable<
AccountBalancesInterface["balances"]
>;
Expand Down Expand Up @@ -1040,6 +1045,7 @@ export const saveSettings = async ({
isValidatingSafeAssetsEnabled: true,
isExperimentalModeEnabled: false,
isRpcHealthy: false,
userNotification: { enabled: false, message: "" },
settingsState: SettingsState.IDLE,
isSorobanPublicEnabled: false,
error: "",
Expand Down
8 changes: 8 additions & 0 deletions @shared/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface Response {
isExperimentalModeEnabled: boolean;
isSorobanPublicEnabled: boolean;
isRpcHealthy: boolean;
userNotification: UserNotification;
settingsState: SettingsState;
networkDetails: NetworkDetails;
sorobanRpcUrl: string;
Expand Down Expand Up @@ -149,10 +150,16 @@ export enum SettingsState {
SUCCESS = "SUCCESS",
}

export interface UserNotification {
enabled: boolean;
message: string;
}

export interface IndexerSettings {
settingsState: SettingsState;
isSorobanPublicEnabled: boolean;
isRpcHealthy: boolean;
userNotification: UserNotification;
}

export type Settings = {
Expand Down Expand Up @@ -204,6 +211,7 @@ export interface AccountBalancesInterface {
tokensWithNoBalance: string[];
isFunded: boolean | null;
subentryCount: number;
error?: { horizon: any; soroban: any };
}

export interface AccountHistoryInterface {
Expand Down
18 changes: 15 additions & 3 deletions extension/src/background/helpers/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,28 @@ export const getIsRpcHealthy = async (networkDetails: NetworkDetails) => {
return rpcHealth.status === "healthy";
};

export const getUserNotification = async () => {
let response = { enabled: false, message: "" };

try {
const res = await fetch(`${INDEXER_URL}/user-notification`);
response = await res.json();
} catch (e) {
captureException(`Failed to load user notification - ${JSON.stringify(e)}`);
console.error(e);
}

return response;
};

export const getFeatureFlags = async () => {
let featureFlags = { useSorobanPublic: false };

try {
const res = await fetch(`${INDEXER_URL}/feature-flags`);
featureFlags = await res.json();
} catch (e) {
captureException(
`Failed to load feature flag for Soroban mainnet - ${JSON.stringify(e)}`,
);
captureException(`Failed to load feature flag - ${JSON.stringify(e)}`);
console.error(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {
getIsExperimentalModeEnabled,
getIsHardwareWalletActive,
getIsRpcHealthy,
getUserNotification,
getSavedNetworks,
getNetworkDetails,
getNetworksList,
Expand Down Expand Up @@ -1231,6 +1232,7 @@ export const popupMessageListener = (request: Request, sessionStore: Store) => {
const networkDetails = await getNetworkDetails();
const featureFlags = await getFeatureFlags();
const isRpcHealthy = await getIsRpcHealthy(networkDetails);
const userNotification = await getUserNotification();

return {
allowList: await getAllowList(),
Expand All @@ -1243,6 +1245,7 @@ export const popupMessageListener = (request: Request, sessionStore: Store) => {
networksList: await getNetworksList(),
isSorobanPublicEnabled: featureFlags.useSorobanPublic,
isRpcHealthy,
userNotification,
};
};

Expand Down
4 changes: 4 additions & 0 deletions extension/src/popup/ducks/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const indexerInitialState: IndexerSettings = {
settingsState: SettingsState.IDLE,
isSorobanPublicEnabled: false,
isRpcHealthy: false,
userNotification: { enabled: false, message: "" },
};

const initialState = {
Expand Down Expand Up @@ -109,6 +110,7 @@ export const saveSettings = createAsyncThunk<
...settingsInitialState,
isSorobanPublicEnabled: false,
isRpcHealthy: false,
userNotification: { enabled: false, message: "" },
settingsState: SettingsState.IDLE,
};

Expand Down Expand Up @@ -244,6 +246,7 @@ const settingsSlice = createSlice({
isExperimentalModeEnabled,
isSorobanPublicEnabled,
isRpcHealthy,
userNotification,
} = action?.payload || {
...initialState,
};
Expand All @@ -260,6 +263,7 @@ const settingsSlice = createSlice({
isExperimentalModeEnabled,
isSorobanPublicEnabled,
isRpcHealthy,
userNotification,
settingsState: SettingsState.SUCCESS,
};
},
Expand Down
3 changes: 3 additions & 0 deletions extension/src/popup/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
"History": "History",
"Home": "Home",
"Home Domain": "Home Domain",
"Horizon is temporarily experiencing issues": "Horizon is temporarily experiencing issues",
"HORIZON RPC URL": "HORIZON RPC URL",
"I have my 12 word seed phrase": "I have my 12 word seed phrase",
"I have my recovery phrase safe": "I have my recovery phrase safe",
Expand Down Expand Up @@ -330,6 +331,7 @@
"Please double-check its information and characteristics": {
" This can help you identify fraudulent assets": "Please double-check its information and characteristics. This can help you identify fraudulent assets."
},
"Please note the following the message": "Please note the following the message",
"Please proceed with caution": "Please proceed with caution.",
"Please select a different network before removing it": "Please select a different network before removing it.",
"Please select each word in the same order you have": "Please select each word in the same order you have",
Expand Down Expand Up @@ -401,6 +403,7 @@
"Signing this transaction is not possible at the moment": "Signing this transaction is not possible at the moment.",
"Signs for external accounts": "Signs for external accounts",
"Some features may be disabled at this time": "Some features may be disabled at this time.",
"Some of your assets may not appear, but they are still safe on the network!": "Some of your assets may not appear, but they are still safe on the network!",
"Soroban RPC is temporarily experiencing issues": "Soroban RPC is temporarily experiencing issues",
"SOROBAN RPC URL": "SOROBAN RPC URL",
"Source": "Source",
Expand Down
3 changes: 3 additions & 0 deletions extension/src/popup/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
"History": "History",
"Home": "Home",
"Home Domain": "Home Domain",
"Horizon is temporarily experiencing issues": "Horizon is temporarily experiencing issues",
"HORIZON RPC URL": "HORIZON RPC URL",
"I have my 12 word seed phrase": "I have my 12 word seed phrase",
"I have my recovery phrase safe": "I have my recovery phrase safe",
Expand Down Expand Up @@ -330,6 +331,7 @@
"Please double-check its information and characteristics": {
" This can help you identify fraudulent assets": "Please double-check its information and characteristics. This can help you identify fraudulent assets."
},
"Please note the following the message": "Please note the following the message",
"Please proceed with caution": "Please proceed with caution.",
"Please select a different network before removing it": "Please select a different network before removing it.",
"Please select each word in the same order you have": "Please select each word in the same order you have",
Expand Down Expand Up @@ -401,6 +403,7 @@
"Signing this transaction is not possible at the moment": "Signing this transaction is not possible at the moment.",
"Signs for external accounts": "Signs for external accounts",
"Some features may be disabled at this time": "Some features may be disabled at this time.",
"Some of your assets may not appear, but they are still safe on the network!": "Some of your assets may not appear, but they are still safe on the network!",
"Soroban RPC is temporarily experiencing issues": "Soroban RPC is temporarily experiencing issues",
"SOROBAN RPC URL": "SOROBAN RPC URL",
"Source": "Source",
Expand Down
28 changes: 26 additions & 2 deletions extension/src/popup/views/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import {
settingsNetworkDetailsSelector,
settingsSorobanSupportedSelector,
settingsSelector,
} from "popup/ducks/settings";
import { View } from "popup/basics/layout/View";
import {
Expand Down Expand Up @@ -80,6 +81,7 @@ export const Account = () => {
const publicKey = useSelector(publicKeySelector);
const networkDetails = useSelector(settingsNetworkDetailsSelector);
const isSorobanSuported = useSelector(settingsSorobanSupportedSelector);
const { userNotification } = useSelector(settingsSelector);
const currentAccountName = useSelector(accountNameSelector);
const allAccounts = useSelector(allAccountsSelector);
const [sortedBalances, setSortedBalances] = useState([] as AssetType[]);
Expand All @@ -89,7 +91,7 @@ export const Account = () => {

const sorobanClient = useContext(SorobanContext);

const { balances, isFunded } = accountBalances;
const { balances, isFunded, error } = accountBalances;

useEffect(() => {
// reset to avoid any residual data eg switching between send and swap or
Expand Down Expand Up @@ -275,6 +277,28 @@ export const Account = () => {
</Notification>
</div>
)}
{error?.horizon && (
<div className="AccountView__fetch-fail">
<Notification
title={t("Horizon is temporarily experiencing issues")}
variant="primary"
>
{t(
"Some of your assets may not appear, but they are still safe on the network!",
)}
</Notification>
</div>
)}
{userNotification?.enabled && (
<div className="AccountView__fetch-fail">
<Notification
title={t("Please note the following the message")}
variant="primary"
>
{userNotification.message}
</Notification>
</div>
)}

{isFunded && !hasError && (
<div className="AccountView__assets-wrapper">
Expand All @@ -285,7 +309,7 @@ export const Account = () => {
/>
</div>
)}
{!isFunded && !hasError && (
{!isFunded && !hasError && !error?.horizon && (
<NotFundedMessage
canUseFriendbot={!!networkDetails.friendbotUrl}
setIsAccountFriendbotFunded={setIsAccountFriendbotFunded}
Expand Down

0 comments on commit bca1455

Please sign in to comment.