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/new network UI #554

Merged
merged 66 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
11b3bc5
feat: remove custom network button, move menu, add scroll ui
Nov 13, 2024
9810653
devop: add display networks
Nov 13, 2024
de5832f
ui: new tag ui
Nov 13, 2024
7fb5e27
Merge branch 'develop' of github.com:enkryptcom/enKrypt into feat/new…
gamalielhere Nov 15, 2024
889b12b
feat: create button bar w/o animation for now
gamalielhere Nov 15, 2024
abe0c00
feat: swap and pin button on the network
Nov 19, 2024
a7228b4
Merge branch 'feat/new-network-ui' of https://github.com/enkryptcom/e…
Nov 19, 2024
d73f01a
Merge branch 'develop' of github.com:enkryptcom/enKrypt into feat/new…
gamalielhere Nov 20, 2024
2bea8d7
devop: remove swap button
Nov 20, 2024
db7d245
Merge branch 'feat/new-network-ui' of github.com:enkryptcom/enKrypt i…
gamalielhere Nov 20, 2024
4aee9c3
devop: start renames
gamalielhere Nov 21, 2024
8b22f8b
devop: minor changes
gamalielhere Nov 22, 2024
1be1d3d
feat: networks tab ui, remove scroll components
Nov 22, 2024
9fa05ef
chore: move comment
Nov 22, 2024
96e4b12
feat: add pin logic
Nov 22, 2024
d20d196
feat: drag only pinned
Nov 22, 2024
a94eccd
feat: drag pinned
Nov 22, 2024
160240b
fix: weird div position
Nov 25, 2024
22fc0c4
Merge branch 'feat/new-network-ui' of github.com:enkryptcom/enKrypt i…
gamalielhere Nov 25, 2024
f4188aa
feat: new networks in tab and no networks message
Nov 25, 2024
5fb6876
feat: change filters and display, update on delete custom
gamalielhere Nov 26, 2024
4ad41fa
devop: update icons
gamalielhere Nov 26, 2024
32754fb
fix: toggle, update custom token logo
gamalielhere Nov 26, 2024
cc29277
Merge branch 'feat/new-network-ui' of github.com:enkryptcom/enKrypt i…
gamalielhere Nov 26, 2024
51e58f9
feat: update ui on add network
gamalielhere Nov 27, 2024
b7fd8e3
devop: remove extra styles
gamalielhere Nov 27, 2024
9a8e1c9
feat: sort button
Nov 27, 2024
3208784
feat: implement sticky scroll
Nov 28, 2024
955f274
feat: sort ui
Nov 28, 2024
74bcfab
devop: start using pinia for open with info
gamalielhere Dec 2, 2024
cf71d6e
Merge branch 'develop' into feat/new-network-ui
Dec 16, 2024
1fa9482
Merge branch 'feat/new-network-ui' into feat/custom-networks
Dec 16, 2024
142d049
feat: optimize network search
olgakup Dec 17, 2024
d6bd060
devop: ui fixes
olgakup Dec 18, 2024
3a6e4e4
Merge pull request #570 from enkryptcom/feat/custom-networks
olgakup Dec 18, 2024
81a7674
devop: put back the gradient update
olgakup Dec 18, 2024
a063c24
devop: enable disable testnet and new tags
kvhnuke Dec 18, 2024
c695e72
Merge branch 'feat/new-network-ui' of github.com:enkryptcom/enKrypt i…
kvhnuke Dec 18, 2024
484f074
devop: update main list on enable/disbale test network, ui fixes
olgakup Dec 19, 2024
cb72c50
fix: hover states, show selected network when changed in other catego…
olgakup Dec 26, 2024
04b683a
devop: fix sort
olgakup Dec 26, 2024
807ac74
fix: item prevent clicking
olgakup Dec 26, 2024
0b31963
devop: hide sort menu for the upcoming release
olgakup Jan 2, 2025
dd01b2b
fix: hovered states getting out of sync
olgakup Jan 2, 2025
f508fe9
devop: adjust actions ui bg, spacing in tokens and add header
olgakup Jan 3, 2025
cdc8bb8
chore: clean code
olgakup Jan 3, 2025
a38ed36
chore: fix methid name
olgakup Jan 3, 2025
b650e64
chore: fix review comments
olgakup Jan 3, 2025
61d0db1
fix: clone the variable instead of mutating
olgakup Jan 3, 2025
785f75d
fix: actually call method
olgakup Jan 3, 2025
869d592
fix: remove unneccessary radius declaration
olgakup Jan 3, 2025
17c9ea9
devop: add accessibility, fix opacity-100
olgakup Jan 3, 2025
b0c2789
fix: icon alignment
olgakup Jan 3, 2025
4727fb6
devop: replace hover states with css
olgakup Jan 3, 2025
5d84bc4
devop: add message when search custom network is empty
olgakup Jan 3, 2025
0bbab42
chore: update method name
olgakup Jan 3, 2025
5b36317
devop: cleanup scroll position
olgakup Jan 3, 2025
26c433b
feat: swap tag
olgakup Jan 6, 2025
40ba3d7
feat: add active network idon on top of identicon
olgakup Jan 6, 2025
690190d
devop: replace edit icon, add tooltips
olgakup Jan 8, 2025
20c1c9a
devop: change core action buttonui
olgakup Jan 9, 2025
539ee17
feat: show loader while custom networks get loaded
olgakup Jan 9, 2025
b074cb3
fix: update app menu when network is added
olgakup Jan 9, 2025
99e5f3e
devop: update bottom buttom opacity
olgakup Jan 9, 2025
555c2b7
devop: update default network order
olgakup Jan 9, 2025
70e11f2
devop: merge with develop, upate asset icon
olgakup Jan 9, 2025
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
86 changes: 80 additions & 6 deletions packages/extension/src/libs/networks-state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ class NetworksState {
const networks: NetworkStorageElement[] = POPULAR_NAMES.map(name => ({
name,
}));
await this.setState({ networks, newNetworksVersion: '' });
await this.setState({
networks,
newNetworksVersion: '',
enabledTestNetworks: [],
newUsedFeatures: { networks: [], swap: [] },
});
}

/**
* Pins or unpins a network on the UI.
* @param targetNetworkName - the name of the network to set the status of
* @param isActive - represents whether or not the network is pinned on the ui
*/
async setNetworkStatus(
targetNetworkName: string,
isActive: boolean,
Expand All @@ -43,6 +53,16 @@ class NetworksState {
await this.setState(state);
}

/**
* Inserts networks with new features.
*
* This method first retrieves the current state and checks if the networks
* have been updated to the latest version. If the state and networks are defined,
* it filters out the networks that are not in the predefined list of networks with new features.
* It then maps the filtered networks to a new network item and inserts them into the valid networks.
* The new networks are inserted at the 6th index, or at the end if there are fewer than 6 networks.
* The state is then updated with the new networks and the latest version.
*/
async insertNetworksWithNewFeatures(): Promise<void> {
const state: IState | undefined = await this.getState();
if (
Expand All @@ -69,11 +89,44 @@ class NetworksState {
.concat(fnetworkItem, validNetworks.slice(insertIdx));
state.networks = validNetworks;
state.newNetworksVersion = __PACKAGE_VERSION__ as string;
state.newUsedFeatures = { networks: [], swap: [] };
await this.setState(state);
}
}

async getActiveNetworkNames(): Promise<string[]> {
async setUsedFeature(feature: 'networks' | 'swap', networkName: string) {
const state: IState | undefined = await this.getState();
if (state) {
const newUsedFeatures = state.newUsedFeatures || {
networks: [],
swap: [],
};
newUsedFeatures[feature].push(networkName);
await this.setState({ ...state, newUsedFeatures });
}
}
olgakup marked this conversation as resolved.
Show resolved Hide resolved

async getUsedFeatures(): Promise<IState['newUsedFeatures']> {
const state: IState | undefined = await this.getState();
if (state && state.newUsedFeatures) {
return state.newUsedFeatures;
}
return { networks: [], swap: [] };
}

/**
* Retrieves the names of the pinned networks.
*
* This method first ensures that networks with new features are inserted.
* It then attempts to retrieve the current state. If the state and its networks
* are defined, it maps and returns the names of the valid networks.
* If the state or networks are not defined, it sets the initial active networks
* and returns a predefined list of popular network names.
*
* Previously, the method was named `getActiveNetworks`.
* @returns {Promise<string[]>} A promise that resolves to an array of active network names.
*/
async getPinnedNetworkNames(): Promise<string[]> {
await this.insertNetworksWithNewFeatures();
const state: IState | undefined = await this.getState();
if (state && state.networks) {
Expand All @@ -85,16 +138,37 @@ class NetworksState {
}
}

async getEnabledTestNetworks(): Promise<string[]> {
await this.insertNetworksWithNewFeatures();
const state: IState | undefined = await this.getState();
if (state && state.enabledTestNetworks) {
const validNetworks = state.enabledTestNetworks;
return validNetworks.map(({ name }) => name);
} else {
this.setState(Object.assign({}, state, { enabledTestNetworks: [] }));
return [];
}
}

async setTestnetStatus(
networkName: string,
isEnabled: boolean,
): Promise<void> {
const state: IState | undefined = await this.getState();
const enabledTestNetworks = (state.enabledTestNetworks || []).filter(
n => n.name !== networkName,
);
if (isEnabled) enabledTestNetworks.push({ name: networkName });
await this.setState({ ...state, enabledTestNetworks });
}

async reorderNetwork(networkNames: string[]): Promise<void> {
const state: IState | undefined = await this.getState();
const activeNetworks: NetworkStorageElement[] = networkNames.map(name => ({
name,
isActive: true,
}));
await this.setState({
networks: activeNetworks,
newNetworksVersion: state.newNetworksVersion,
});
await this.setState({ ...state, networks: activeNetworks });
}

async setState(state: IState): Promise<void> {
Expand Down
5 changes: 5 additions & 0 deletions packages/extension/src/libs/networks-state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ export interface NetworkStorageElement {
export interface IState {
networks: NetworkStorageElement[];
newNetworksVersion: string;
enabledTestNetworks: NetworkStorageElement[];
newUsedFeatures: {
networks: string[];
swap: string[];
};
}
12 changes: 7 additions & 5 deletions packages/extension/src/libs/utils/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ const providerNetworks: Record<ProviderName, Record<string, BaseNetwork>> = {
[ProviderName.solana]: SolanaNetworks,
[ProviderName.enkrypt]: {},
};
const getAllNetworks = async (): Promise<BaseNetwork[]> => {
const getAllNetworks = async (includeCustom: boolean = true): Promise<BaseNetwork[]> => {
const customNetworksState = new CustomNetworksState();

const customNetworks = (
await customNetworksState.getAllCustomEVMNetworks()
).map(options => new CustomEvmNetwork(options));

return (Object.values(EthereumNetworks) as BaseNetwork[])
const allNetworks = (Object.values(EthereumNetworks) as BaseNetwork[])
.concat(Object.values(PolkadotNetworks) as BaseNetwork[])
.concat(Object.values(BitcoinNetworks) as BaseNetwork[])
.concat(Object.values(KadenaNetworks) as BaseNetwork[])
.concat(Object.values(SolanaNetworks) as BaseNetwork[])
.concat(customNetworks);
.concat(Object.values(SolanaNetworks) as BaseNetwork[]);
if (!includeCustom) {
return allNetworks
}
return allNetworks.concat(customNetworks);
};
const getNetworkByName = async (
name: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NetworkNames } from '@enkryptcom/types';

const newNetworks = [NetworkNames.Bitrock, NetworkNames.Fraxtal];
const newSwaps: NetworkNames[] = [];
const newSwaps: NetworkNames[] = [NetworkNames.Dogecoin];

export { newNetworks, newSwaps };
Loading
Loading