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: run proxy workers #1666

Merged
merged 7 commits into from
Apr 10, 2024
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
17 changes: 6 additions & 11 deletions src/renderer/entities/wallet/model/wallet-model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { combine, createEffect, createEvent, createStore, sample } from 'effector';
import { spread, combineEvents } from 'patronum';

import { WalletConnectAccount } from '@shared/core';
import { storageService } from '@shared/api/storage';
import { modelUtils } from '../lib/model-utils';
import { accountUtils } from '../lib/account-utils';
import { dictionary } from '@shared/lib/utils';
import type {
Account,
BaseAccount,
Expand All @@ -11,11 +16,6 @@ import type {
ProxiedAccount,
Wallet,
} from '@shared/core';
import { WalletConnectAccount } from '@shared/core';
import { storageService } from '@shared/api/storage';
import { modelUtils } from '../lib/model-utils';
import { accountUtils } from '../lib/account-utils';
import { dictionary } from '@shared/lib/utils';

const walletStarted = createEvent();
const watchOnlyCreated = createEvent<CreateParams<BaseAccount>>();
Expand Down Expand Up @@ -171,12 +171,7 @@ sample({
});

sample({
clock: walletConnectCreated,
target: walletCreatedFx,
});

sample({
clock: [watchOnlyCreated, multisigCreated, singleshardCreated],
clock: [walletConnectCreated, watchOnlyCreated, multisigCreated, singleshardCreated],
target: walletCreatedFx,
});

Expand Down
47 changes: 2 additions & 45 deletions src/renderer/widgets/AddProxyModal/model/add-proxy-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import { spread, delay } from 'patronum';
import { Transaction } from '@entities/transaction';
import { signModel } from '@features/operations/OperationSign/model/sign-model';
import { submitModel } from '@features/operations/OperationSubmit';
import { toAccountId } from '@shared/lib/utils';
import { walletSelectModel } from '@features/wallets';
import { walletModel } from '@entities/wallet';
import { ProxyGroup, NoID } from '@shared/core';
import { proxyModel, proxyUtils } from '@entities/proxy';
import { balanceSubModel } from '@features/balances';
import { Step, AddProxyStore } from '../lib/types';
import { formModel } from './form-model';
Expand All @@ -18,6 +15,7 @@ const stepChanged = createEvent<Step>();

const flowStarted = createEvent();
const flowFinished = createEvent();
const flowClosed = createEvent();

const $step = createStore<Step>(Step.NONE);

Expand Down Expand Up @@ -132,48 +130,6 @@ sample({
}),
});

sample({
clock: submitModel.output.formSubmitted,
source: $addProxyStore,
filter: (addProxyStore: AddProxyStore | null): addProxyStore is AddProxyStore => Boolean(addProxyStore),
fn: (addProxyStore) => [
{
accountId: toAccountId(addProxyStore.delegate),
proxiedAccountId: addProxyStore.account.accountId,
chainId: addProxyStore.chain.chainId,
proxyType: addProxyStore.proxyType,
delay: 0,
},
],
target: proxyModel.events.proxiesAdded,
});

sample({
clock: submitModel.output.formSubmitted,
source: {
wallet: walletSelectModel.$walletForDetails,
addProxyStore: $addProxyStore,
proxyGroups: proxyModel.$proxyGroups,
},
filter: ({ wallet, addProxyStore }) => Boolean(wallet) && Boolean(addProxyStore),
fn: ({ wallet, addProxyStore, proxyGroups }) => {
const newProxyGroup: NoID<ProxyGroup> = {
walletId: wallet!.id,
chainId: addProxyStore!.chain.chainId,
proxiedAccountId: addProxyStore!.account.accountId,
totalDeposit: addProxyStore!.proxyDeposit,
};

const proxyGroupExists = proxyGroups.some((group) => proxyUtils.isSameProxyGroup(group, newProxyGroup));

return proxyGroupExists ? { groupsUpdated: [newProxyGroup] } : { groupsAdded: [newProxyGroup] };
},
target: spread({
groupsAdded: proxyModel.events.proxyGroupsAdded,
groupsUpdated: proxyModel.events.proxyGroupsUpdated,
}),
});

sample({
clock: delay(submitModel.output.formSubmitted, 2000),
target: flowFinished,
Expand Down Expand Up @@ -209,5 +165,6 @@ export const addProxyModel = {
},
output: {
flowFinished,
flowClosed,
},
};
2 changes: 1 addition & 1 deletion src/renderer/widgets/AddProxyModal/ui/AddProxy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const AddProxy = () => {
const step = useUnit(addProxyModel.$step);
const chain = useUnit(addProxyModel.$chain);

const [isModalOpen, closeModal] = useModalClose(!addProxyUtils.isNoneStep(step), addProxyModel.output.flowFinished);
const [isModalOpen, closeModal] = useModalClose(!addProxyUtils.isNoneStep(step), addProxyModel.output.flowClosed);

const getModalTitle = (step: Step, chain?: Chain) => {
if (addProxyUtils.isInitStep(step) || !chain) return t('operations.modalTitles.addProxy');
Expand Down
33 changes: 22 additions & 11 deletions src/renderer/widgets/AddProxyModal/ui/Confirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useState } from 'react';
import { useUnit } from 'effector-react';

import { FeeWithLabel, ProxyDepositWithLabel, MultisigDepositWithLabel } from '@entities/transaction';
import { Button, DetailRow, FootnoteText, Icon } from '@shared/ui';
import { FeeWithLabel, MultisigDepositWithLabel } from '@entities/transaction';
import { Button, DetailRow, FootnoteText, Icon, Tooltip } from '@shared/ui';
import { useI18n } from '@app/providers';
import { SignButton } from '@entities/operations';
import { AddressWithExplorers, WalletIcon, accountUtils, ExplorersPopover, WalletCardSm } from '@entities/wallet';
import { proxyUtils } from '@entities/proxy';
import { confirmModel } from '../model/confirm-model';
import { AssetBalance } from '@entities/asset';
import { AssetFiatBalance } from '@entities/price/ui/AssetFiatBalance';

type Props = {
onGoBack: () => void;
Expand All @@ -26,7 +28,6 @@ export const Confirmation = ({ onGoBack }: Props) => {
if (!confirmStore || !api || !initiatorWallet) return null;

const [isFeeLoading, setIsFeeLoading] = useState(true);
const [isProxyDepositLoading, setIsProxyDepositLoading] = useState(true);

return (
<div className="flex flex-col items-center pt-4 gap-y-4 pb-4 px-5">
Expand Down Expand Up @@ -126,13 +127,23 @@ export const Confirmation = ({ onGoBack }: Props) => {

<hr className="border-filter-border w-full pr-2" />

<ProxyDepositWithLabel
api={api}
deposit={'0'}
proxyNumber={confirmStore.proxyNumber || 1}
asset={confirmStore.chain.assets[0]}
onDepositLoading={setIsProxyDepositLoading}
/>
<DetailRow
className="text-text-primary"
label={
<>
<Icon className="text-text-tertiary" name="lock" size={12} />
<FootnoteText className="text-text-tertiary">{t('proxy.proxyDepositLabel')}</FootnoteText>
<Tooltip content={t('proxy.proxyDepositHint')} offsetPx={-60}>
<Icon name="info" className="hover:text-icon-hover cursor-pointer" size={16} />
</Tooltip>
</>
}
>
<div className="flex flex-col gap-y-0.5 items-end">
<AssetBalance value={confirmStore.proxyDeposit} asset={confirmStore.chain.assets[0]} />
<AssetFiatBalance asset={confirmStore.chain.assets[0]} amount={confirmStore.proxyDeposit} />
</div>
</DetailRow>

{accountUtils.isMultisigAccount(confirmStore.account) && (
<MultisigDepositWithLabel
Expand All @@ -156,7 +167,7 @@ export const Confirmation = ({ onGoBack }: Props) => {
</Button>

<SignButton
disabled={isFeeLoading || isProxyDepositLoading}
disabled={isFeeLoading}
type={(signerWallet || initiatorWallet).type}
onClick={confirmModel.output.formSubmitted}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ const getPureProxyFx = createEffect(
unsubscribe = subscriptionService.subscribeEvents(api, pureCreatedParams, (event) => {
unsubscribe?.then((fn) => fn());

const accountId = event.data[0].toHex();

resolve({
accountId,
accountId: event.data[0].toHex(),
blockNumber: timepoint.height,
extrinsicIndex: timepoint.index,
});
Expand Down Expand Up @@ -216,34 +214,6 @@ sample({
}),
});

sample({
clock: combineEvents({
events: [getPureProxyFx.doneData, proxiesModel.output.walletsCreated],
reset: flowStarted,
}),
source: {
addProxyStore: $addProxyStore,
proxyGroups: proxyModel.$proxyGroups,
},
filter: ({ addProxyStore }, [_, wallet]) => Boolean(wallet.wallets[0].id) && Boolean(addProxyStore),
fn: ({ addProxyStore, proxyGroups }, [{ accountId }, wallet]) => {
const newProxyGroup: NoID<ProxyGroup> = {
walletId: wallet.wallets[0].id,
chainId: addProxyStore!.chain.chainId,
proxiedAccountId: accountId,
totalDeposit: addProxyStore!.proxyDeposit,
};

const proxyGroupExists = proxyGroups.some((group) => proxyUtils.isSameProxyGroup(group, newProxyGroup));

return proxyGroupExists ? { groupsUpdated: [newProxyGroup] } : { groupsAdded: [newProxyGroup] };
},
target: spread({
groupsAdded: proxyModel.events.proxyGroupsAdded,
groupsUpdated: proxyModel.events.proxyGroupsUpdated,
}),
});

sample({
clock: submitModel.output.formSubmitted,
source: {
Expand Down Expand Up @@ -302,6 +272,34 @@ sample({
target: proxiesModel.events.proxiedWalletsCreated,
});

sample({
clock: combineEvents({
events: [getPureProxyFx.doneData, proxiesModel.output.walletsCreated],
reset: flowStarted,
}),
source: {
addProxyStore: $addProxyStore,
proxyGroups: proxyModel.$proxyGroups,
},
filter: ({ addProxyStore }, [_, wallet]) => Boolean(wallet.wallets[0].id) && Boolean(addProxyStore),
fn: ({ addProxyStore, proxyGroups }, [{ accountId }, wallet]) => {
const newProxyGroup: NoID<ProxyGroup> = {
walletId: wallet.wallets[0].id,
chainId: addProxyStore!.chain.chainId,
proxiedAccountId: accountId,
totalDeposit: addProxyStore!.proxyDeposit,
};

const proxyGroupExists = proxyGroups.some((group) => proxyUtils.isSameProxyGroup(group, newProxyGroup));

return proxyGroupExists ? { groupsUpdated: [newProxyGroup] } : { groupsAdded: [newProxyGroup] };
},
target: spread({
groupsAdded: proxyModel.events.proxyGroupsAdded,
groupsUpdated: proxyModel.events.proxyGroupsUpdated,
}),
});

sample({
clock: delay(getPureProxyFx.doneData, 2000),
target: flowFinished,
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/widgets/CreateWallet/ui/CreateWalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { WalletConnect } from '@pages/Onboarding/WalletConnect/WalletConnect';
import { MultisigWallet } from './MultisigWallet/MultisigWallet';
import { WalletType, WalletFamily } from '@shared/core';
import { walletPairingModel } from '@features/wallets';
import { proxiesModel } from '@features/proxies';
import { Paths } from '@shared/routes';
import { walletProviderModel } from '../model/wallet-provider-model';

Expand Down Expand Up @@ -38,7 +39,14 @@ export const CreateWalletProvider = () => {

const props: ModalProps = {
onClose: walletPairingModel.events.walletTypeCleared,
onComplete: walletProviderModel.events.completed,
onComplete: () => {
if (walletType !== WalletType.WATCH_ONLY) {
sokolova-an marked this conversation as resolved.
Show resolved Hide resolved
setTimeout(() => {
proxiesModel.events.workerStarted();
}, 1000);
}
walletProviderModel.events.completed();
},
};

return WalletModals[walletType](props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,14 @@ sample({
fn: ({ chains }, { proxy, account }) => {
const chain = chains[proxy!.chainId];

const store = {
return {
chain: chain!,
account,
delegate: toAddress(proxy!.accountId!, { prefix: chain!.addressPrefix }),
proxyType: proxy!.proxyType,
delay: proxy!.delay,
description: '',
};

return store;
},
target: $removeProxyStore,
});
Expand Down
12 changes: 11 additions & 1 deletion src/renderer/widgets/WalletDetails/model/vault-details-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { chainsService } from '@shared/api/network';
import { storageService } from '@shared/api/storage';
import { walletModel, accountUtils } from '@entities/wallet';
import type { ShardAccount, Chain, ChainId, ChainAccount, ID, DraftAccount, Account, AccountId } from '@shared/core';
import { proxiesModel } from '@features/proxies';

type AccountsCreatedParams = {
walletId: ID;
rootAccountId: AccountId;
accounts: DraftAccount<ChainAccount | ShardAccount>[];
};

const shardsSelected = createEvent<ShardAccount[]>();
const shardsCleared = createEvent();
const accountsCreated = createEvent<AccountsCreatedParams>();
Expand Down Expand Up @@ -85,6 +85,11 @@ sample({
target: walletModel.$accounts,
});

sample({
clock: removeKeysFx.doneData,
target: proxiesModel.events.workerStarted,
});

sample({ clock: accountsCreated, target: createAccountsFx });

sample({
Expand All @@ -95,6 +100,11 @@ sample({
target: walletModel.$accounts,
});

sample({
clock: createAccountsFx.doneData,
target: proxiesModel.events.workerStarted,
});

export const vaultDetailsModel = {
$shards,
$chain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { walletDetailsUtils } from '../lib/utils';
import type { MultishardMap, VaultMap } from '../lib/types';
import { proxyModel, proxyUtils } from '@entities/proxy';
import { networkModel } from '@entities/network';
import { proxiesModel } from '@features/proxies';
import { addProxyModel } from '../../AddProxyModal';
import type {
Account,
Signatory,
Expand Down Expand Up @@ -235,6 +237,11 @@ sample({
target: $proxyForRemoval,
});

sample({
clock: addProxyModel.output.flowFinished,
target: proxiesModel.events.workerStarted,
});

export const walletProviderModel = {
$accounts,

Expand Down
Loading