Skip to content

Commit

Permalink
chore: merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tuul-wq committed Nov 12, 2024
2 parents 8907a89 + 029e2fc commit 3d613ec
Show file tree
Hide file tree
Showing 62 changed files with 500 additions and 472 deletions.
4 changes: 1 addition & 3 deletions src/main/factories/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export function registerDeepLinkProtocol() {
}
}

export function processUrl(url: string, mainWindow?: BrowserWindow) {
if (!mainWindow) return;

export function processUrl(url: string, mainWindow: BrowserWindow) {
const parsed = new URL(url);
if (parsed.protocol !== `${APP_CONFIG.ELECTRON_PROTOCOL}:`) return;

Expand Down
30 changes: 0 additions & 30 deletions src/main/factories/setup.ts

This file was deleted.

56 changes: 38 additions & 18 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'source-map-support/register';

import { type BrowserWindow, app } from 'electron';

import { APP_CONFIG } from '../../app.config';
import { type BrowserWindow, app, session } from 'electron';
import installExtension, { REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer';

import { runAppSingleInstance } from './factories/instance';
import { setupLogger } from './factories/logs';
import { processUrl, registerDeepLinkProtocol } from './factories/protocol';
import { setupApplication } from './factories/setup';
import { setupAutoUpdater } from './factories/updater';
import { createWindow } from './factories/window';
import { ENVIRONMENT } from './shared/constants/environment';
Expand All @@ -18,47 +16,69 @@ runAppSingleInstance(async () => {
setupAutoUpdater();
registerDeepLinkProtocol();

app.commandLine.appendSwitch('force-color-profile', 'srgb');
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');

if (ENVIRONMENT.IS_DEV || ENVIRONMENT.IS_STAGE) {
app.commandLine.appendSwitch('ignore-certificate-errors');
}
app.commandLine.appendSwitch('force-color-profile', 'srgb');

app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
delete process.env.ELECTRON_ENABLE_SECURITY_WARNINGS;

if (PLATFORM.IS_LINUX) {
app.disableHardwareAcceleration();
}

// eslint-disable-next-line prefer-const
let mainWindow: BrowserWindow | undefined;
await app.whenReady();

let mainWindow: BrowserWindow | null = createWindow();

if (PLATFORM.IS_MAC) {
// Protocol handler for macos
app.on('open-url', (event, url) => {
event.preventDefault();
processUrl(url, mainWindow);
if (mainWindow) {
processUrl(url, mainWindow);
}
});
}

if (PLATFORM.IS_WINDOWS || PLATFORM.IS_LINUX) {
// Protocol handler for win32/Linux
app.on('second-instance', (_, commandLine) => {
app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
}

const url = commandLine[commandLine.length - 1];
if (!url.startsWith(APP_CONFIG.ELECTRON_PROTOCOL + '://')) return;

processUrl(url, mainWindow);
});
}

await app.whenReady();
app.on('activate', async () => {
if (mainWindow === null) {
mainWindow = createWindow();
}
});

app.on('web-contents-created', (_, contents) =>
contents.on('will-navigate', (event) => !ENVIRONMENT.IS_DEV && event.preventDefault()),
);

app.on('window-all-closed', () => {
if (!PLATFORM.IS_MAC) {
app.quit();
}

mainWindow = createWindow();
await setupApplication(mainWindow);
mainWindow?.destroy();
mainWindow = null;
});

if (ENVIRONMENT.IS_DEV) {
await installExtension(REACT_DEVELOPER_TOOLS);

// Reloading extensions for correct initialization in dev tools
session.defaultSession.getAllExtensions().map((e) => {
session.defaultSession.loadExtension(e.path);
});
}
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type Meta, type StoryFn } from '@storybook/react';

import { AssetType } from '@/shared/core';

import { AssetBalance } from './AssetBalance';

export default {
Expand All @@ -13,6 +15,7 @@ const assetDot = {
symbol: 'DOT',
precision: 10,
priceId: 'polkadot',
type: AssetType.NATIVE,
icon: 'https://raw.githubusercontent.com/novasamatech/nova-utils/master/icons/chains/white/Polkadot.svg',
name: 'Polkadot',
};
Expand Down
1 change: 1 addition & 0 deletions src/renderer/entities/transaction/lib/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const CONTROLLER_ARG_NAME = 'controller';
export const DEST_WEIGHT_ARG_NAME = 'destWeight';

export const TransferType: Record<AssetType, TransactionType> = {
[AssetType.NATIVE]: TransactionType.TRANSFER,
[AssetType.ORML]: TransactionType.ORML_TRANSFER,
[AssetType.STATEMINE]: TransactionType.ASSET_TRANSFER,
};
Expand Down
26 changes: 26 additions & 0 deletions src/renderer/entities/transaction/lib/transactionBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type ApiPromise } from '@polkadot/api';

import { type ClaimAction } from '@/shared/api/governance';
import { type MultisigTransactionDS } from '@/shared/api/storage';
import {
type AccountId,
type Address,
Expand Down Expand Up @@ -36,6 +37,7 @@ export const transactionBuilder = {
buildRevote,
buildRemoveVote,
buildRemoveVotes,
buildRejectMultisigTx,

buildBatchAll,
splitBatchAll,
Expand Down Expand Up @@ -478,3 +480,27 @@ function buildRemoveVotes({ chain, accountId, votes }: RemoveVotesParams): Trans

return buildBatchAll({ chain, accountId, transactions });
}

type RejectTxParams = {
chain: Chain;
signerAddress: Address;
threshold: number;
otherSignatories: Address[];
tx: MultisigTransactionDS;
};
function buildRejectMultisigTx({ chain, signerAddress, threshold, otherSignatories, tx }: RejectTxParams): Transaction {
return {
chainId: chain.chainId,
address: signerAddress,
type: TransactionType.MULTISIG_CANCEL_AS_MULTI,
args: {
threshold: threshold,
otherSignatories,
callHash: tx.callHash,
maybeTimepoint: {
height: tx.blockCreated,
index: tx.indexCreated,
},
},
};
}
4 changes: 2 additions & 2 deletions src/renderer/entities/transaction/lib/transactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ function getWrappedTransaction({ api, addressPrefix, transaction, txWrappers }:
const multisigTx = wrapAsMulti({
api,
addressPrefix,
txWrapper,
transaction: acc.wrappedTx,
txWrapper: txWrapper,
});

acc.coreTx = acc.wrappedTx;
Expand All @@ -281,8 +281,8 @@ function getWrappedTransaction({ api, addressPrefix, transaction, txWrappers }:
if (isProxy(txWrapper)) {
acc.wrappedTx = wrapAsProxy({
addressPrefix,
txWrapper,
transaction: acc.wrappedTx,
txWrapper: txWrapper,
});
}

Expand Down
37 changes: 16 additions & 21 deletions src/renderer/entities/wallet/model/__tests__/wallet-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('entities/wallet/model/wallet-model', () => {
const scope = fork();

await allSettled(walletModel.events.walletStarted, { scope });
expect(scope.getState(walletModel._test.$allWallets)).toEqual(wallets);
expect(scope.getState(walletModel.$allWallets)).toEqual(wallets);
expect(scope.getState(walletModel.$activeWallet)).toEqual(wallets[0]);
});

Expand All @@ -34,15 +34,15 @@ describe('entities/wallet/model/wallet-model', () => {
jest.spyOn(storageService.wallets, 'update').mockResolvedValue(3);

const scope = fork({
values: new Map().set(walletModel._test.$allWallets, wallets),
values: new Map().set(walletModel.$allWallets, wallets),
});

await allSettled(walletModel.events.watchOnlyCreated, {
scope,
params: { wallet: newWallet, accounts: [newAccounts[0]] as any[] },
});

expect(scope.getState(walletModel._test.$allWallets)).toEqual(
expect(scope.getState(walletModel.$allWallets)).toEqual(
wallets.concat({ ...newWallet, accounts: [newAccounts[0]] }),
);
});
Expand All @@ -57,18 +57,16 @@ describe('entities/wallet/model/wallet-model', () => {
jest.spyOn(storageService.wallets, 'update').mockResolvedValue(3);

const scope = fork({
values: new Map().set(walletModel._test.$allWallets, wallets),
values: new Map().set(walletModel.$allWallets, wallets),
});

expect(scope.getState(walletModel._test.$allWallets)).toHaveLength(wallets.length);
expect(scope.getState(walletModel.$allWallets)).toHaveLength(wallets.length);
await allSettled(walletModel.events.multishardCreated, {
scope,
params: { wallet: newWallet, accounts: newAccounts as any[] },
});

expect(scope.getState(walletModel._test.$allWallets)).toEqual(
wallets.concat({ ...newWallet, accounts: newAccounts }),
);
expect(scope.getState(walletModel.$allWallets)).toEqual(wallets.concat({ ...newWallet, accounts: newAccounts }));
});

test('should update $allWallets on walletRemoved', async () => {
Expand All @@ -81,13 +79,13 @@ describe('entities/wallet/model/wallet-model', () => {
const deleteAccountsSpy = jest.spyOn(storageService.accounts, 'deleteAll').mockResolvedValue([1, 2, 3]);

const scope = fork({
values: new Map().set(walletModel._test.$allWallets, wallets),
values: new Map().set(walletModel.$allWallets, wallets),
});

await allSettled(walletModel.events.walletRemoved, { scope, params: removedWallet.id });

expect(deleteAccountsSpy).toHaveBeenCalledWith(removedAccounts.map((a) => a.id));
expect(scope.getState(walletModel._test.$allWallets)).toEqual(remainingWallets);
expect(scope.getState(walletModel.$allWallets)).toEqual(remainingWallets);
});

test('should update $allWallets on walletsRemoved', async () => {
Expand All @@ -100,13 +98,13 @@ describe('entities/wallet/model/wallet-model', () => {
const deleteAccountsSpy = jest.spyOn(storageService.accounts, 'deleteAll').mockResolvedValue([1, 2, 3]);

const scope = fork({
values: new Map().set(walletModel._test.$allWallets, wallets),
values: new Map().set(walletModel.$allWallets, wallets),
});

await allSettled(walletModel.events.walletsRemoved, { scope, params: [removedWallet.id] });

expect(deleteAccountsSpy).toHaveBeenCalledWith(removedAccounts.map((a) => a.id));
expect(scope.getState(walletModel._test.$allWallets)).toEqual(remainingWallets);
expect(scope.getState(walletModel.$allWallets)).toEqual(remainingWallets);
});

test('should update $allWallets on walletHidden', async () => {
Expand All @@ -116,16 +114,13 @@ describe('entities/wallet/model/wallet-model', () => {
const updateSpy = jest.spyOn(storageService.wallets, 'update').mockResolvedValue(1);

const scope = fork({
values: new Map().set(walletModel._test.$allWallets, wallets),
values: new Map().set(walletModel.$allWallets, wallets),
});

await allSettled(walletModel.events.walletHidden, { scope, params: hiddenWallet });

expect(updateSpy).toHaveBeenCalledWith(1, { isHidden: true });
expect(scope.getState(walletModel._test.$allWallets)).toEqual([
{ ...hiddenWallet, isHidden: true },
...wallets.slice(1),
]);
expect(scope.getState(walletModel.$allWallets)).toEqual([{ ...hiddenWallet, isHidden: true }, ...wallets.slice(1)]);
});

test('should update $allWallets on walletRestore', async () => {
Expand All @@ -135,16 +130,16 @@ describe('entities/wallet/model/wallet-model', () => {
const updateSpy = jest.spyOn(storageService.wallets, 'update').mockResolvedValue(walletToRestore.id);

const scope = fork({
values: new Map().set(walletModel._test.$allWallets, wallets),
values: new Map().set(walletModel.$allWallets, wallets),
});

await allSettled(walletModel._test.$allWallets, { scope, params: wallets });
await allSettled(walletModel.$allWallets, { scope, params: wallets });
expect(scope.getState(walletModel.$hiddenWallets)).toEqual([walletToRestore]);

await allSettled(walletModel.events.walletRestored, { scope, params: walletToRestore });

expect(updateSpy).toHaveBeenCalledWith(walletToRestore.id, { isHidden: false });
expect(scope.getState(walletModel._test.$allWallets)).toEqual(
expect(scope.getState(walletModel.$allWallets)).toEqual(
wallets.map((wallet) => {
return wallet.id === walletToRestore.id ? { ...wallet, isHidden: false } : wallet;
}),
Expand All @@ -158,7 +153,7 @@ describe('entities/wallet/model/wallet-model', () => {

const scope = fork();

await allSettled(walletModel._test.$allWallets, { scope, params: wallets });
await allSettled(walletModel.$allWallets, { scope, params: wallets });

expect(scope.getState(walletModel.$hiddenWallets)).toEqual([hiddenWallet]);
expect(scope.getState(walletModel.$wallets)).toEqual(visibleWallets);
Expand Down
Loading

0 comments on commit 3d613ec

Please sign in to comment.