Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
goga-m committed Feb 7, 2025
1 parent bab7c69 commit 2754ff9
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/app/hooks/use-active-network.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Networks } from "@ardenthq/sdk";
import { Contracts } from "@ardenthq/sdk-profiles";
import { useConfiguration, useEnvironmentContext } from "@/app/contexts";
import { useEnvironmentContext } from "@/app/contexts";
import { DashboardConfiguration } from "@/domains/dashboard/pages/Dashboard";
import { assertNetwork } from "@/utils/assertions";

Expand Down Expand Up @@ -37,7 +37,7 @@ export const useActiveNetwork = ({
return network.isTest();
});

assertNetwork(activeNetwork)
assertNetwork(activeNetwork);

const setActiveNetwork = async (activeNetworkId: string) => {
const dashboardConfiguration = profile.settings().get(Contracts.ProfileSetting.DashboardConfiguration, {});
Expand Down
1 change: 0 additions & 1 deletion src/app/hooks/use-profile-synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from "@/utils/profile-utils";
import { useConfiguration, useEnvironmentContext } from "@/app/contexts";

import { DashboardConfiguration } from "@/domains/dashboard/pages/Dashboard";
import { ProfilePeers } from "@/utils/profile-peers";
import { delay } from "@/utils/delay";

Expand Down
28 changes: 16 additions & 12 deletions src/domains/portfolio/hooks/use-portfolio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ export function SelectedAddresses({ profile, activeNetwork }: { profile: IProfil
* @returns {string[]}
*/
all(): string[] {
const nethash = activeNetwork.meta().nethash
const nethash = activeNetwork.meta().nethash;

const config = profile.settings().get(Contracts.ProfileSetting.DashboardConfiguration, {
selectedAddresses: [],
selectedAddressesByActiveNetwork: { [nethash]: [] }
selectedAddressesByActiveNetwork: { [nethash]: [] },
}) as unknown as DashboardConfiguration;

if (!config.selectedAddressesByNetwork || !config.selectedAddressesByNetwork[nethash]) {
return []
return [];
}

const selectedAddresses = config.selectedAddressesByNetwork[nethash]
const selectedAddresses = config.selectedAddressesByNetwork[nethash];

const profileAddresses = new Set(
profile
Expand Down Expand Up @@ -92,16 +92,18 @@ export function SelectedAddresses({ profile, activeNetwork }: { profile: IProfil
* @returns {Promise<void>}
*/
set(selectedAddresses: string[]): void {
const defaultConfig = { selectedAddressesByNetwork: { [activeNetwork.meta().nethash]: [] } }
const nethash = activeNetwork.meta().nethash
const defaultConfig = { selectedAddressesByNetwork: { [activeNetwork.meta().nethash]: [] } };
const nethash = activeNetwork.meta().nethash;

const config = profile.settings().get(Contracts.ProfileSetting.DashboardConfiguration, defaultConfig) as DashboardConfiguration;
const config = profile
.settings()
.get(Contracts.ProfileSetting.DashboardConfiguration, defaultConfig) as DashboardConfiguration;

if (!config.selectedAddressesByNetwork) {
config.selectedAddressesByNetwork = { [nethash]: [] }
config.selectedAddressesByNetwork = { [nethash]: [] };
}

config.selectedAddressesByNetwork[nethash] = selectedAddresses
config.selectedAddressesByNetwork[nethash] = selectedAddresses;

profile.settings().set(Contracts.ProfileSetting.DashboardConfiguration, config);
},
Expand All @@ -113,15 +115,17 @@ export function SelectedAddresses({ profile, activeNetwork }: { profile: IProfil
toWallets(): IReadWriteWallet[] {
const selected = this.all();

return profile.wallets().findByCoinWithNetwork(activeNetwork.coin(), activeNetwork.id())
return profile
.wallets()
.findByCoinWithNetwork(activeNetwork.coin(), activeNetwork.id())
.filter((wallet) => selected.includes(wallet.address()));
},
};
}

export const usePortfolio = ({ profile }: { profile: Contracts.IProfile }) => {
const { persist } = useEnvironmentContext();
const { activeNetwork } = useActiveNetwork({ profile })
const { activeNetwork } = useActiveNetwork({ profile });
const addresses = SelectedAddresses({ activeNetwork, profile });
const wallets = addresses.toWallets();
const balance = Balance({ wallets });
Expand All @@ -139,7 +143,7 @@ export const usePortfolio = ({ profile }: { profile: Contracts.IProfile }) => {
addresses.set([profile.wallets().first().address()]);
}

await persist()
await persist();
},
};
};
2 changes: 1 addition & 1 deletion src/domains/portfolio/pages/Portfolio/Portfolio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const Portfolio = () => {
const profile = useActiveProfile();
const { t } = useTranslation();

const { selectedWallets } = usePortfolio({ profile })
const { selectedWallets } = usePortfolio({ profile });

if (selectedWallets.length === 0) {
if (profile.status().isRestored()) {
Expand Down
2 changes: 1 addition & 1 deletion src/domains/profile/pages/CreateProfile/CreateProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useHistory } from "react-router-dom";
import { Header } from "@/app/components/Header";
import { Page, Section } from "@/app/components/Layout";
import { useEnvironmentContext } from "@/app/contexts";
import { useLocaleCurrency, useProfileRestore, useTheme } from "@/app/hooks";
import { useLocaleCurrency, useTheme } from "@/app/hooks";

import { ProfileForm, ProfileFormState } from "@/domains/profile/components/ProfileForm";
import { ThemeIcon } from "@/app/components/Icon";
Expand Down
1 change: 0 additions & 1 deletion src/domains/profile/pages/ImportProfile/ImportProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const ImportProfile = () => {
.map((wallet) => wallet.address()),
);
}

}

await persist();
Expand Down
4 changes: 2 additions & 2 deletions src/domains/vote/hooks/use-vote-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const useVoteFilters = ({
() => (hasWalletId ? wallet.network().maximumVotesPerWallet() : undefined),
[hasWalletId, wallet],
);
const { activeNetwork } = useActiveNetwork({ profile })
const { activeNetwork } = useActiveNetwork({ profile });

const [walletsDisplayType, setWalletsDisplayType] = useState(defaultConfiguration.walletsDisplayType);
const [selectedNetworkIds, setSelectedNetworkIds] = useState([activeNetwork.id()]);
Expand Down Expand Up @@ -56,7 +56,7 @@ export const useVoteFilters = ({
return true;
}

return false
return false;
}, [walletsDisplayType, selectedNetworkIds, defaultConfiguration]);

const filterProperties = {
Expand Down
1 change: 0 additions & 1 deletion src/domains/wallet/hooks/use-wallet-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useMemo } from "react";

import { useConfiguration, useEnvironmentContext } from "@/app/contexts";
import { DashboardConfiguration } from "@/domains/dashboard/pages/Dashboard";
import { profileEnabledNetworkIds } from "@/utils/network-utils";
import { useNetworks } from "@/app/hooks";

export const useWalletConfig = ({
Expand Down
4 changes: 2 additions & 2 deletions src/domains/wallet/pages/CreateWallet/CreateWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const CreateWallet = () => {
const { t } = useTranslation();
const activeProfile = useActiveProfile();
const [activeTab, setActiveTab] = useState<Step>(Step.WalletOverviewStep);
const { activeNetwork } = useActiveNetwork({ profile: activeProfile })
const { activeNetwork } = useActiveNetwork({ profile: activeProfile });

const { setSelectedAddresses, selectedAddresses } = usePortfolio({ profile: activeProfile });

Expand All @@ -52,7 +52,7 @@ export const CreateWallet = () => {
const { useEncryption, encryptionPassword, confirmEncryptionPassword, wallet, mnemonic } = watch();

const [isGeneratingWallet, setIsGeneratingWallet] = useState(true);
const [generationError, setGenerationError] = useState<string | DefaultTReturn<TOptions>>("");
const [_, setGenerationError] = useState<string | DefaultTReturn<TOptions>>("");
const [isEditAliasModalOpen, setIsEditAliasModalOpen] = useState(false);

useEffect(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/domains/wallet/pages/ImportWallet/ImportWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const ImportWallet = () => {
const [isEditAliasModalOpen, setIsEditAliasModalOpen] = useState(false);

const { setSelectedAddresses, selectedAddresses } = usePortfolio({ profile: activeProfile });
const { activeNetwork } = useActiveNetwork({ profile: activeProfile })
const { activeNetwork } = useActiveNetwork({ profile: activeProfile });

const { t } = useTranslation();
const { importWalletByType } = useWalletImport({ profile: activeProfile });
Expand Down Expand Up @@ -105,7 +105,7 @@ export const ImportWallet = () => {
setActiveTab(Step.SummaryStep);

setIsEncrypting(false);
}
},
})[activeTab as Exclude<Step, Step.SummaryStep>]();

const handleBack = () => {
Expand All @@ -122,7 +122,7 @@ export const ImportWallet = () => {
};

const importWallet = async (): Promise<void> => {
console.log("importing wallet")
console.log("importing wallet");
const { importOption, encryptedWif, value: walletInput } = getValues();

const wallet = await importWalletByType({
Expand Down
8 changes: 4 additions & 4 deletions src/domains/wallet/pages/ImportWallet/MethodStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Select } from "@/app/components/SelectDropdown";
import { Toggle } from "@/app/components/Toggle";
import { Tooltip } from "@/app/components/Tooltip";
import { OptionsValue, useImportOptions } from "@/domains/wallet/hooks/use-import-options";
import { assertNetwork, assertString } from "@/utils/assertions";
import { assertString } from "@/utils/assertions";
import { Alert } from "@/app/components/Alert";
import { ThemeIcon } from "@/app/components/Icon";

Expand Down Expand Up @@ -157,7 +157,7 @@ const ImportInputField = ({
type: OptionsValue;
coin: Coins.Coin;
profile: Contracts.IProfile;
network: Networks.Network
network: Networks.Network;
}) => {
const { t } = useTranslation();
const { register } = useFormContext();
Expand Down Expand Up @@ -299,9 +299,9 @@ const ImportInputField = ({
);
};

export const MethodStep = ({ profile, network }: { profile: Contracts.IProfile, network: Networks.Network }) => {
export const MethodStep = ({ profile, network }: { profile: Contracts.IProfile; network: Networks.Network }) => {
const { t } = useTranslation();
const { getValues, watch, setValue, clearErrors } = useFormContext();
const { watch, setValue, clearErrors } = useFormContext();

const [coin] = useState(() => profile.coins().get(network.coin(), network.id()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Checkbox } from "@/app/components/Checkbox";
import { t } from "i18next";
import { Button } from "@/app/components/Button";
import React, { ChangeEvent, useEffect, useState } from "react";
import { IWalletRepository } from "@ardenthq/sdk-profiles/distribution/esm/wallet.repository.contract";
import { Divider } from "@/app/components/Divider";
import cn from "classnames";
import { Tooltip } from "@/app/components/Tooltip";
Expand Down

0 comments on commit 2754ff9

Please sign in to comment.