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

feat: add voi testnet block explorer #38

Merged
merged 2 commits into from
Dec 5, 2023
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
14 changes: 13 additions & 1 deletion src/extension/config/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,19 @@ const networks: INetwork[] = [
],
canonicalName: 'Voi',
chakraTheme: 'voi',
explorers: [],
explorers: [
{
accountPath: '/account',
applicationPath: '/application',
assetPath: '/asset',
baseUrl: 'https://voi.observer/explorer',
blockPath: '/block',
canonicalName: 'Voi Observer',
groupPath: '/group',
id: 'voi-observer',
transactionPath: '/transaction',
},
],
genesisId: 'voitest-v1',
genesisHash: 'IXnoWtviVVJW5LGivNFc0Dq14V3kqaXuK2u5OQrdVZo=',
indexers: [
Expand Down
6 changes: 4 additions & 2 deletions src/extension/features/settings/thunks/setSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {

// utils
import {
convertGenesisHashToHex,
selectDefaultNetwork,
selectNetworkFromSettings,
} from '@extension/utils';
Expand All @@ -48,8 +49,9 @@ const setSettings: AsyncThunk<
) {
selectedNetwork = selectDefaultNetwork(networks);

settings.general.preferredBlockExplorerId =
selectedNetwork.explorers[0]?.id || null;
settings.general.preferredBlockExplorerIds[
convertGenesisHashToHex(selectedNetwork.genesisHash).toUpperCase()
] = selectedNetwork.explorers[0]?.id || null;
settings.general.selectedNetworkGenesisHash = selectedNetwork.genesisHash;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function createDefaultSettings(networks: INetwork[]): ISettings {
theme: 'light',
},
general: {
preferredBlockExplorerId: defaultNetwork.explorers[0]?.id || null,
preferredBlockExplorerIds: {},
selectedNetworkGenesisHash: defaultNetwork.genesisHash,
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/extension/features/settings/utils/getInitialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function getInitialState(): ISettingsState {
},
fetching: false,
general: {
preferredBlockExplorerId: null,
preferredBlockExplorerIds: {},
selectedNetworkGenesisHash: null,
},
saving: false,
Expand Down
45 changes: 29 additions & 16 deletions src/extension/pages/GeneralSettingsPage/GeneralSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
INetwork,
ISettings,
} from '@extension/types';
import { convertGenesisHashToHex } from '@extension/utils';

const GeneralSettingsPage: FC = () => {
const { t } = useTranslation();
Expand All @@ -45,21 +46,30 @@ const GeneralSettingsPage: FC = () => {
const handlePreferredBlockExplorerChange = (
event: ChangeEvent<HTMLSelectElement>
) => {
const explorer: IExplorer | null =
selectedNetwork?.explorers.find(
(value) => value.id === event.target.value
) || null;
let explorer: IExplorer | null;

if (explorer) {
dispatch(
setSettings({
...settings,
general: {
...settings.general,
preferredBlockExplorerId: explorer.id,
},
})
);
if (selectedNetwork) {
explorer =
selectedNetwork?.explorers.find(
(value) => value.id === event.target.value
) || null;

if (explorer) {
dispatch(
setSettings({
...settings,
general: {
...settings.general,
preferredBlockExplorerIds: {
...settings.general.preferredBlockExplorerIds,
[convertGenesisHashToHex(
selectedNetwork.genesisHash
).toUpperCase()]: explorer.id,
},
},
})
);
}
}
};

Expand All @@ -82,8 +92,11 @@ const GeneralSettingsPage: FC = () => {
value: value.id,
}))}
value={
settings.general.preferredBlockExplorerId ||
selectedNetwork.explorers[0].id
settings.general.preferredBlockExplorerIds[
convertGenesisHashToHex(
selectedNetwork.genesisHash
).toUpperCase()
] || selectedNetwork.explorers[0].id
}
/>
)}
Expand Down
11 changes: 9 additions & 2 deletions src/extension/selectors/useSelectPreferredBlockExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useSelector } from 'react-redux';

// types
import { IExplorer, IMainRootState, INetwork } from '@extension/types';
import { convertGenesisHashToHex } from '@extension/utils';

/**
* Gets the currently preferred block explorer from the settings.
Expand All @@ -22,8 +23,14 @@ export default function useSelectPreferredBlockExplorer(): IExplorer | null {

return (
selectedNetwork.explorers.find(
(value) => value.id === state.settings.general.preferredBlockExplorerId
) || null
(value) =>
value.id ===
state.settings.general.preferredBlockExplorerIds[
convertGenesisHashToHex(selectedNetwork.genesisHash).toUpperCase()
]
) ||
selectedNetwork.explorers[0] ||
null
);
});
}
2 changes: 1 addition & 1 deletion src/extension/types/IGeneralSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
interface IGeneralSettings {
preferredBlockExplorerId: string | null;
preferredBlockExplorerIds: Record<string, string | null>;
selectedNetworkGenesisHash: string | null;
}

Expand Down
Loading