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

fix: database duplicate and proxy details #3071

Merged
merged 2 commits into from
Jan 30, 2025
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
4 changes: 2 additions & 2 deletions src/renderer/app/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ const populate = async () => {
await networkModel.startNetworks();
await accounts.populate();
await walletModel.populate();
proxiesModel.findAllProxies();
await proxyModel.populate();
multisigsModel.subscribe();

// TODO rework as populate effects
kernelModel.events.appStarted();
governanceModel.events.governanceStarted();
proxyModel.events.proxyStarted();
assetsSettingsModel.events.assetsStarted();
notificationModel.events.notificationsStarted();
basketModel.events.basketStarted();
proxiesModel.findAllProxies();
};

export const bootstrap = () => {
Expand Down
11 changes: 6 additions & 5 deletions src/renderer/entities/proxy/model/proxy-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { proxyUtils } from '../lib/proxy-utils';

type ProxyStore = Record<AccountId, ProxyAccount[]>;

const proxyStarted = createEvent();
const proxiesAdded = createEvent<NoID<ProxyAccount>[]>();
const proxiesRemoved = createEvent<ProxyAccount[]>();

Expand Down Expand Up @@ -51,9 +50,9 @@ const removeProxyGroupsFx = createEffect((groups: ProxyGroup[]): Promise<ID[] |
return storageService.proxyGroups.deleteAll(groups.map((p) => p.id));
});

sample({
clock: proxyStarted,
target: [populateProxiesFx, populateProxyGroupsFx],
const proxyStartFx = createEffect(async () => {
await populateProxiesFx();
await populateProxyGroupsFx();
});

sample({
Expand Down Expand Up @@ -183,8 +182,10 @@ export const proxyModel = {
$proxies,
$proxyGroups,
$walletsProxyGroups,

populate: proxyStartFx,

events: {
proxyStarted,
proxiesAdded,
proxiesRemoved,

Expand Down
6 changes: 4 additions & 2 deletions src/renderer/features/proxies/model/proxies-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ const findProxiesFx = attach({
});

const findAllProxiesFx = attach({
source: { accounts: walletModel.$availableAccounts, chains: networkModel.$chains },
source: {
accounts: walletModel.$availableAccounts,
chains: networkModel.$chains,
},
mapParams(_: void, { chains, accounts }) {
return Object.values(chains)
.filter(proxiesUtils.chainSupportProxy)
Expand Down Expand Up @@ -267,7 +270,6 @@ sample({
});

export const proxiesModel = {
findProxies: findProxiesFx,
findAllProxies: findAllProxiesFx,
createProxiedWallet: createProxiedWalletFx,
createProxiesWallets: createProxiesWalletsFx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const $multiShardAccounts = $wallet.map(wallet => {
});

const $canCreateProxy = $wallet.map(wallet => {
if (nullable(wallet)) return false;
if (nullable(wallet) || wallet.accounts.length === 0) return false;

const canCreateAnyProxy = permissionUtils.canCreateAnyProxy(wallet);
const canCreateNonAnyProxy = permissionUtils.canCreateNonAnyProxy(wallet);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useGate, useUnit } from 'effector-react';

import { type Wallet } from '@/shared/core';
import { nullable } from '@/shared/lib/utils';
import { walletUtils } from '@/entities/wallet';
import { polkadotExtensionService } from '@/features/extension-wallet';
import { walletDetailsModel } from '../../model/wallet-details-model';
import { walletDetailsUtils } from '../../lib/utils';
import { MultishardWalletDetails } from '../wallets/MultishardWalletDetails';
import { MultisigWalletDetails } from '../wallets/MultisigWalletDetails';
import { ProxiedWalletDetails } from '../wallets/ProxiedWalletDetails';
Expand All @@ -19,9 +17,10 @@ type Props = {
};

export const WalletDetails = ({ isOpen, wallet, onClose }: Props) => {
useGate(walletDetailsModel.flow, { wallet });

const multiShardAccounts = useUnit(walletDetailsModel.$multiShardAccounts);
const multiShardAccounts =
nullable(wallet) || !walletUtils.isMultiShard(wallet)
? new Map()
: walletDetailsUtils.getMultishardMap(wallet.accounts);

if (!isOpen || nullable(wallet)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useUnit } from 'effector-react';
import { useGate, useUnit } from 'effector-react';

import { type MultiShardWallet } from '@/shared/core';
import { useI18n } from '@/shared/i18n';
Expand Down Expand Up @@ -35,6 +35,7 @@ type Props = {
onClose: () => void;
};
export const MultishardWalletDetails = ({ wallet, accounts, onClose }: Props) => {
useGate(walletDetailsModel.flow, { wallet });
const { t } = useI18n();

const chains = useUnit(networkModel.$chains);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useUnit } from 'effector-react';
import { useGate, useUnit } from 'effector-react';
import { useState } from 'react';

import { type ProxiedWallet, type ProxyType } from '@/shared/core';
Expand Down Expand Up @@ -43,6 +43,7 @@ type Props = {
};

export const ProxiedWalletDetails = ({ wallet, onClose }: Props) => {
useGate(walletDetailsModel.flow, { wallet });
const { t } = useI18n();

const chains = useUnit(networkModel.$chains);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useUnit } from 'effector-react';
import { useGate, useUnit } from 'effector-react';
import { useEffect, useMemo, useState } from 'react';

import { type Chain, type Wallet } from '@/shared/core';
Expand Down Expand Up @@ -33,6 +33,7 @@ type Props = {
onClose: () => void;
};
export const SimpleWalletDetails = ({ wallet, onClose }: Props) => {
useGate(walletDetailsModel.flow, { wallet });
const { t } = useI18n();

const allChains = useUnit(networkModel.$chains);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useUnit } from 'effector-react';
import { useGate, useUnit } from 'effector-react';
import { isEmpty } from 'lodash';
import { useEffect, useState } from 'react';

Expand Down Expand Up @@ -46,6 +46,7 @@ type Props = {
onClose: () => void;
};
export const VaultWalletDetails = ({ wallet, onClose }: Props) => {
useGate(walletDetailsModel.flow, { wallet });
const { t } = useI18n();

const allChains = useUnit(networkModel.$chains);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type Props = {
export const WalletConnectDetails = ({ wallet, onClose }: Props) => {
useGate(walletConnectForget.flow, { accounts: wallet.accounts });
useGate(walletConnectReconnect.flow, { accounts: wallet.accounts });
useGate(walletDetailsModel.flow, { wallet });

const { t } = useI18n();

const hasProxies = useUnit(walletDetailsModel.$hasProxies);
Expand Down
Loading