Skip to content

Commit

Permalink
Merge branch 'main' into fix/lw-9912-fix-old-firmware-multidelegation…
Browse files Browse the repository at this point in the history
…-defect
  • Loading branch information
rhyslbw authored Apr 11, 2024
2 parents 071c150 + ce6a414 commit 9cdaa64
Show file tree
Hide file tree
Showing 29 changed files with 75 additions and 50 deletions.
5 changes: 2 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ module.exports = {
'no-invalid-this': 0,
'react/prop-types': 'off',
'max-len': 'off', // prettier is already handling this automatically,
// note: prod webpack config strips console logs anyway, nevertheless
// we don't want the dev build to be spammed by needless logging
'@typescript-eslint/no-explicit-any': ['error'],
'no-console': ['error', { allow: ['warn', 'error', 'info', 'debug'] }],
'lodash/import-scope': ['error', 'method']
'lodash/import-scope': ['error', 'method'],
'promise/avoid-new': 'off',
},
overrides: [
{
Expand Down
1 change: 1 addition & 0 deletions apps/browser-extension-wallet/.env.developerpreview
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ PRODUCTION_MODE_TRACKING=false
POSTHOG_DEV_TOKEN_MAINNET=phc_gH96Lx5lEVXTTWEyytSdTFPDk3Xsxwi4BqG88mKObd1
POSTHOG_DEV_TOKEN_PREPROD=phc_Xlmldm6EYSfQVgB9Uxm3b2xC1noDlgFFXpF9AJ6SMfJ
POSTHOG_DEV_TOKEN_PREVIEW=phc_e8SaOOWpXpNE59TnpLumeUjWm4iv024AWjhQqU406jr
POSTHOG_DEV_TOKEN_SANCHONET=phc_OUu6sPucDu5S6skRmYbWN5Jn8TpggWTQu1Y1ETkm3xt

# Cardano Services
CARDANO_SERVICES_URL_MAINNET=https://dev-mainnet.lw.iog.io
Expand Down
2 changes: 1 addition & 1 deletion apps/browser-extension-wallet/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "$WALLET_MANIFEST_NAME",
"description": "One fast, accessible, and secure platform for digital assets, DApps, NFTs, and DeFi.",
"version": "1.10.1",
"version": "1.10.2",
"manifest_version": 3,
"key": "$LACE_EXTENSION_KEY",
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion apps/browser-extension-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lace/browser-extension-wallet",
"version": "1.10.1",
"version": "1.10.2",
"description": "A fully capable wallet packaged as browser extensions for Chrome, Firefox, and Edge",
"homepage": "https://github.com/input-output-hk/lace/blob/master/apps/browser-extension-wallet/README.md",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const NonSSLBanner = () => {
const authorize = (authorization: 'deny' | 'just-once' | 'allow', url: string) => {
const api$ = of({
allowOrigin(origin: cip30.Origin): Promise<'deny' | 'just-once' | 'allow'> {
/* eslint-disable-next-line promise/avoid-new */
if (!url.startsWith(origin)) {
return Promise.reject();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OutsideHandlesProvider, StakingPopup } from '@lace/staking';
import { DEFAULT_STAKING_BROWSER_PREFERENCES, OutsideHandlesProvider, StakingPopup } from '@lace/staking';
import React, { useCallback, useEffect } from 'react';
import {
useAnalyticsContext,
Expand Down Expand Up @@ -89,7 +89,7 @@ export const MultiDelegationStakingPopup = (): JSX.Element => {
] = useLocalStorage(MULTIDELEGATION_FIRST_VISIT_SINCE_PORTFOLIO_PERSISTENCE_LS_KEY, true);

const [stakingBrowserPreferencesPersistence, { updateLocalStorage: setStakingBrowserPreferencesPersistence }] =
useLocalStorage(STAKING_BROWSER_PREFERENCES_LS_KEY);
useLocalStorage(STAKING_BROWSER_PREFERENCES_LS_KEY, DEFAULT_STAKING_BROWSER_PREFERENCES);

const walletAddress = walletInfo.addresses?.[0].address?.toString();
const analytics = useAnalyticsContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jest.mock('../../stores', () => ({
})
}));

// eslint-disable-next-line promise/avoid-new
const flushPromises = () => new Promise(setImmediate);

describe('Testing useBuildDelegation hook', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const launchCip30Popup = async (url: string, windowType: Windows.CreateTy
};

const waitForTabLoad = (tab: Tabs.Tab) =>
// eslint-disable-next-line promise/avoid-new
new Promise<void>((resolve) => {
const listener = (tabId: number, changeInfo: Tabs.OnUpdatedChangeInfoType) => {
// make sure the status is 'complete' and it's the right tab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export type Migration = {
downgrade?: (password?: string) => MigrationPersistance | Promise<MigrationPersistance>;
};

const migrations: Migration[] = [versions.v_1_0_0];
const migrations: Migration[] = [versions.v_1_10_2];

/**
* Applies all migrations in order between the two version provided
Expand Down Expand Up @@ -137,7 +137,6 @@ export const migrationsRequirePassword = async (
*/
export const checkMigrations = async (previousVersion: string, migrationsArray = migrations): Promise<void> => {
const currentVersion = runtime.getManifest().version;

// Return if a downgrade is occurring
if (isVersionOlderThanOrEqual(currentVersion, previousVersion)) {
// TODO: allow migrations if downgrading versions too [LW-5595]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './v1_0_0';
export * from './v1_10_2';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable camelcase, @typescript-eslint/no-empty-function, no-console */
import { getItemFromLocalStorage, removeItemFromLocalStorage } from '../util';
import { Migration } from '../migrations';

const MIGRATION_VERSION = '1.10.2';

export const v_1_10_2: Migration = {
version: MIGRATION_VERSION,
upgrade: async () => ({
prepare: () => {
try {
/**
* Between the v1.9.0 and v1.10.0 releases, the 'stakingBrowserPreferences'
* localStorage was updated, and contained a change in spelling, removing this
* object allows it to be saved again and any issues related to spelling
* are mitigated
* */
removeItemFromLocalStorage('stakingBrowserPreferences');
} catch (error) {
console.log(`error executing migration ${MIGRATION_VERSION}: ${error}`);
throw error;
}
},
assert: () => {
const stakingBrowserPreferences = getItemFromLocalStorage('stakingBrowserPreferences');
return !!stakingBrowserPreferences;
},
persist: () => {},
rollback: () => {}
})
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable promise/avoid-new */
import { createQueue, TaskQueue } from '../taskQueue';

describe('createQueue', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const DEFAULT_TIMEOUT = 1000;

export const fakeApiRequest = <TResponse>(response: TResponse, timeout = DEFAULT_TIMEOUT): Promise<TResponse> =>
// eslint-disable-next-line promise/avoid-new
new Promise<TResponse>((resolve) => {
setTimeout(() => resolve(response), timeout);
});
1 change: 0 additions & 1 deletion apps/browser-extension-wallet/src/utils/taskQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const createQueue = (batchTasks: number, intervalBetweenBatch: number): T
if (sent >= batchTasks) {
// Reset the sent count
sent = 0;
// eslint-disable-next-line promise/avoid-new
await new Promise((resolve) => setTimeout(resolve, intervalBetweenBatch));
}
execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { compactNumberWithUnit } from '@utils/format-number';
import { isMultidelegationSupportedByDevice } from '@views/browser/features/staking';
import { useWalletStore } from '@stores';
import { useAnalyticsContext, useCurrencyStore, useExternalLinkOpener } from '@providers';
import { OutsideHandlesProvider } from '@lace/staking';
import { DEFAULT_STAKING_BROWSER_PREFERENCES, OutsideHandlesProvider } from '@lace/staking';
import { useBalances, useFetchCoinPrice, useLocalStorage } from '@hooks';
import {
MULTIDELEGATION_FIRST_VISIT_LS_KEY,
Expand All @@ -27,7 +27,7 @@ export const StakingContainer = (): React.ReactElement => {

const analytics = useAnalyticsContext();
const [stakingBrowserPreferencesPersistence, { updateLocalStorage: setStakingBrowserPreferencesPersistence }] =
useLocalStorage(STAKING_BROWSER_PREFERENCES_LS_KEY);
useLocalStorage(STAKING_BROWSER_PREFERENCES_LS_KEY, DEFAULT_STAKING_BROWSER_PREFERENCES);
const [multidelegationFirstVisit, { updateLocalStorage: setMultidelegationFirstVisit }] = useLocalStorage(
MULTIDELEGATION_FIRST_VISIT_LS_KEY,
true
Expand Down
2 changes: 1 addition & 1 deletion apps/browser-extension-wallet/webpack.common.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports =
path: '.env',
safe: false,
silent: false,
defaults: process.env.BUILD_DEV_PREVIEW === 'true' ? '.env.devpreview' : true,
defaults: process.env.BUILD_DEV_PREVIEW === 'true' ? '.env.developerpreview' : true,
systemvars: true,
allowEmptyValues: true
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/browser-extension-wallet/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports = () => {
path: '.env',
safe: false,
silent: false,
defaults: process.env.BUILD_DEV_PREVIEW === 'true' ? '.env.devpreview' : true,
defaults: process.env.BUILD_DEV_PREVIEW === 'true' ? '.env.developerpreview' : true,
systemvars: true,
allowEmptyValues: true
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/browser-extension-wallet/webpack.common.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = () => ({
path: '.env',
safe: false,
silent: false,
defaults: process.env.BUILD_DEV_PREVIEW === 'true' ? '.env.devpreview' : true,
defaults: process.env.BUILD_DEV_PREVIEW === 'true' ? '.env.developerpreview' : true,
systemvars: true,
allowEmptyValues: true
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-magic-numbers */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable promise/avoid-new */
import '@testing-library/jest-dom';
import { getBlockInfoByHash } from '../get-block-info-by-hash';
import { stakepoolSearchProviderStub, mockedStakePools } from '../../test/mocks/StakepoolSearchProviderStub';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-magic-numbers */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable promise/avoid-new */
/* eslint-disable max-len */
/* eslint-disable sonarjs/no-identical-functions */
import '@testing-library/jest-dom';
Expand Down
18 changes: 8 additions & 10 deletions packages/cardano/src/wallet/test/mocks/AssetsProviderStub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ export const mockedAssets: Asset.AssetInfo[] = [
];

export const assetsProviderStub = (assets: Asset.AssetInfo[] = mockedAssets): AssetProvider => ({
getAsset: jest.fn().mockImplementation(
({ assetId }) =>
// eslint-disable-next-line promise/avoid-new
new Promise((resolve) => resolve(assets.find((asset) => asset.assetId === assetId) || assets[0]))
),
getAssets: jest.fn().mockImplementation(
({ assetIds }) =>
// eslint-disable-next-line promise/avoid-new
new Promise((resolve) => resolve(assets.filter((asset) => assetIds.includes(asset.assetId)) || assets[0]))
),
getAsset: jest
.fn()
.mockImplementation(async ({ assetId }) => assets.find((asset) => asset.assetId === assetId) || assets[0]),
getAssets: jest
.fn()
.mockImplementation(
async ({ assetIds }) => assets.filter((asset) => assetIds.includes(asset.assetId)) || assets[0]
),
healthCheck: jest.fn().mockResolvedValue({ ok: true })
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const TxSubmitProviderFake = {
return {
submittedTxs$: submittedTxs.asObservable(),
submitTx: ({ signedTransaction }): Promise<void> =>
// eslint-disable-next-line promise/avoid-new
new Promise((resolve) => {
submittedTxs.next(signedTransaction);
resolve();
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/ui/hooks/useFetchImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type FetchAction = {
const handleImageFetch = (image: string) => {
const downloadingImage = new Image();

// eslint-disable-next-line promise/avoid-new
const imageResponse: Promise<ImageResponse> = new Promise<ImageResponse>((resolve) => {
const onLoadEvent = (event: any) => {
resolve({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-magic-numbers, promise/avoid-new */
import React from 'react';
import type { Meta } from '@storybook/react';

Expand Down Expand Up @@ -40,7 +39,7 @@ const addressBook = [

const handleResolution =
'addr_test1qzrljm7nskakjydxlr450ktsj08zuw6aktvgfkmmyw9semrkrezryq3ydtmkg0e7e2jvzg443h0ffzfwd09wpcxy2fuql9tk0g' as Wallet.Cardano.PaymentAddress;
let timeout: NodeJS.Timeout;
let timeout: number;

const validateAddress: ValidateAddress = async (address) => {
if (!address) {
Expand All @@ -51,10 +50,12 @@ const validateAddress: ValidateAddress = async (address) => {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
const twoSeconds = 2000;
timeout = window.setTimeout(() => {
clearTimeout(timeout);
resolve(Math.random() < 0.5 ? { isValid: true, handleResolution } : { isValid: false });
}, 2000);
const factor = 0.5;
resolve(Math.random() < factor ? { isValid: true, handleResolution } : { isValid: false });
}, twoSeconds);
});
}
return {
Expand Down
7 changes: 6 additions & 1 deletion packages/staking/src/features/BrowsePools/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowsePoolsView, StakePoolSortOptions } from './types';
import { BrowsePoolsView, StakePoolSortOptions, StakingBrowserPreferences } from './types';
import { getDefaultSortOrderByField } from './utils';

export const SEARCH_DEBOUNCE_IN_MS = 300;
Expand All @@ -9,3 +9,8 @@ export const DEFAULT_SORT_OPTIONS: StakePoolSortOptions = {
};

export const DEFAULT_BROWSE_POOLS_VIEW: BrowsePoolsView = BrowsePoolsView.grid;

export const DEFAULT_STAKING_BROWSER_PREFERENCES: StakingBrowserPreferences = {
poolsView: DEFAULT_BROWSE_POOLS_VIEW,
selectedPoolIds: [],
};
4 changes: 2 additions & 2 deletions packages/staking/src/features/BrowsePools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ export { BrowsePools } from './BrowsePools';
export { BrowsePoolsPreferencesCard } from './BrowsePoolsPreferencesCard';
export { getPoolInfos } from './queries';
export { useBrowsePoolsPersistence } from './hooks';
export { DEFAULT_SORT_OPTIONS } from './constants';
export { DEFAULT_SORT_OPTIONS, DEFAULT_STAKING_BROWSER_PREFERENCES } from './constants';

// TODO: remove once multi delegation feature is GA'd
export { getSaturationLevel, isOversaturated, getDefaultSortOrderByField } from './utils';
export type { StakePoolSortOptions, TranslationsFor, SortField, SortOrder } from './types';
export type { StakingBrowserPreferences, StakePoolSortOptions, TranslationsFor, SortField, SortOrder } from './types';
export { BrowsePoolsView } from './types';
export { StakePoolCardProgressBar } from './StakePoolCard';
export { StakePoolsListRowSkeleton, config as stakePoolTableConfig } from './StakePoolsList';
Expand Down
5 changes: 5 additions & 0 deletions packages/staking/src/features/BrowsePools/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export type StakePoolSortOptions = {
};

export type TranslationsFor<T extends string> = Record<T, string>;

export type StakingBrowserPreferences = {
poolsView: BrowsePoolsView;
selectedPoolIds: string[];
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TxBuilder } from '@cardano-sdk/tx-construction';
import { Wallet } from '@lace/cardano';
import { AssetActivityListProps } from '@lace/core';
import { BrowsePoolsView, StakePoolSortOptions } from 'features/BrowsePools/types';
import { StakePoolSortOptions, StakingBrowserPreferences } from 'features/BrowsePools';
import type { IAnalyticsTracker } from '@lace/common';

type WalletBalance = {
Expand Down Expand Up @@ -40,11 +40,6 @@ export enum StateStatus {
ERROR = 'error',
}

export interface StakingBrowserPreferences {
poolsView: BrowsePoolsView;
selectedPoolIds: string[];
}

export interface IBlockchainProvider {
stakePoolProvider: Wallet.StakePoolProvider;
assetProvider: Wallet.AssetProvider;
Expand Down
4 changes: 2 additions & 2 deletions packages/staking/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { Staking, StakingPopup } from './features/staking';
export { BrowsePoolsPreferencesCard } from './features/BrowsePools';
export type { StakingBrowserPreferences } from 'features/BrowsePools';
export { BrowsePoolsPreferencesCard, DEFAULT_STAKING_BROWSER_PREFERENCES } from './features/BrowsePools';
export { OutsideHandlesProvider } from './features/outside-handles-provider';
export type { StakingBrowserPreferences } from './features/outside-handles-provider';
export { MAX_POOLS_COUNT } from './features/store';

// TODO: remove once multi delegaion feature is GA'd
Expand Down

0 comments on commit 9cdaa64

Please sign in to comment.