Skip to content

Commit 9ee0dd5

Browse files
authored
Merge pull request #3007 from input-output-hk/fix/ddw-1111-non-recommended-decimal-settings-warning-not-shown
[DDW-1111] Non-recommended decimal place setting alert is not displayed before 1st change of settings
2 parents 3b34f67 + 2cedd23 commit 9ee0dd5

File tree

13 files changed

+153
-54
lines changed

13 files changed

+153
-54
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Fixed downloaded installer being left in Downloads after latest update installs ([PR 2941](https://github.com/input-output-hk/daedalus/pull/2941))
88
- Fixed incorrect amount of token sent ([PR 2962](https://github.com/input-output-hk/daedalus/pull/2962))
9+
- Ensured non-recommended decimal place setting alert is correctly shown ([PR 3007](https://github.com/input-output-hk/daedalus/pull/3007))
910

1011
### Chores
1112

source/common/types/logging.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import type {
1414
} from '../../renderer/app/api/wallets/types';
1515
import type { Address } from '../../renderer/app/api/addresses/types';
1616
import type { GetTransactionsRequest } from '../../renderer/app/api/transactions/types';
17-
import type { HardwareWalletLocalData } from '../../renderer/app/api/utils/localStorage';
1817
import type { AdaApiStakePool } from '../../renderer/app/api/staking/types';
18+
import { HardwareWalletLocalData } from '../../renderer/app/types/localDataTypes';
1919

2020
export type LoggingLevel = 'debug' | 'info' | 'error' | 'warn';
2121
export type Logger = {

source/renderer/app/api/api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ import type {
223223
ApiAsset,
224224
StoredAssetMetadata,
225225
} from './assets/types';
226-
import type { AssetLocalData } from './utils/localStorage';
227226
import Asset from '../domains/Asset';
228227
import { getAssets } from './assets/requests/getAssets';
229228
import { getAccountPublicKey } from './wallets/requests/getAccountPublicKey';
230229
import { doesWalletRequireAdaToRemainToSupportTokens } from './utils/apiHelpers';
230+
import { AssetLocalData } from '../types/localDataTypes';
231231

232232
export default class AdaApi {
233233
config: RequestConfig;
@@ -663,14 +663,14 @@ export default class AdaApi {
663663
logger.debug('AdaApi::getAssets success', {
664664
assets: response,
665665
});
666-
const assetsLocaldata = await global.daedalus.api.localStorage.getAssetsLocalData();
666+
const assetsLocalData = await global.daedalus.api.localStorage.getAssetsLocalData();
667667
logger.debug('AdaApi::getAssetsLocalData success', {
668-
assetsLocaldata,
668+
assetsLocalData,
669669
});
670670
const assets = response.map((asset) =>
671671
_createAssetFromServerData(
672672
asset,
673-
assetsLocaldata[asset.policy_id + asset.asset_name] || {},
673+
assetsLocalData[asset.policy_id + asset.asset_name] || {},
674674
this.storedAssetMetadata
675675
)
676676
);

source/renderer/app/api/utils/localStorage.ts

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22
import { includes, without, get } from 'lodash';
33
import { toJS } from '../../../../common/utils/helper';
44
import { electronStoreConversation } from '../../ipc/electronStoreConversation';
5+
import type { WalletMigrationStatus } from '../../stores/WalletMigrationStore';
56
import { WalletMigrationStatuses } from '../../stores/WalletMigrationStore';
67
import {
78
STORAGE_TYPES as types,
89
STORAGE_KEYS as keys,
910
} from '../../../../common/config/electron-store.config';
1011
import type { NewsTimestamp } from '../news/types';
11-
import type { WalletMigrationStatus } from '../../stores/WalletMigrationStore';
1212
import type {
1313
TransportDevice,
1414
HardwareWalletExtendedPublicKeyResponse,
15-
DeviceType,
1615
} from '../../../../common/types/hardware-wallets.types';
1716
import type { StorageKey } from '../../../../common/types/electron-store.types';
1817
import type { Currency, DeprecatedCurrency } from '../../types/currencyTypes';
1918
import {
2019
CURRENCY_IS_ACTIVE_BY_DEFAULT,
2120
CURRENCY_DEFAULT_SELECTED,
2221
} from '../../config/currencyConfig';
22+
import {
23+
AssetLocalData,
24+
HardwareWalletDevicesType,
25+
HardwareWalletLocalData,
26+
HardwareWalletsLocalData,
27+
UnpairedHardwareWalletData,
28+
WalletLocalData,
29+
} from '../../types/localDataTypes';
2330

24-
export type WalletLocalData = {
25-
id: string;
26-
recoveryPhraseVerificationDate?: Date | null | undefined;
27-
creationDate: Date;
28-
showUsedAddresses: boolean;
29-
};
30-
export type WalletsLocalData = Record<StorageKey, WalletLocalData>;
3131
export type SetHardwareWalletLocalDataRequestType = {
3232
walletId: string;
3333
data: {
@@ -42,27 +42,6 @@ export type SetHardwareWalletDeviceRequestType = {
4242
data: UnpairedHardwareWalletData;
4343
};
4444

45-
export type UnpairedHardwareWalletData = {
46-
deviceType?: DeviceType;
47-
deviceModel?: string;
48-
deviceName?: string;
49-
path?: string | null | undefined;
50-
paired?: string | null | undefined;
51-
disconnected?: boolean;
52-
};
53-
54-
export type HardwareWalletLocalData = {
55-
id: string;
56-
deviceType: DeviceType;
57-
device: TransportDevice;
58-
extendedPublicKey: HardwareWalletExtendedPublicKeyResponse;
59-
disconnected: boolean;
60-
};
61-
export type HardwareWalletsLocalData = Record<string, HardwareWalletLocalData>;
62-
export type HardwareWalletDevicesType = Record<string, TransportDevice>;
63-
export type AssetLocalData = {
64-
decimals: number;
65-
};
6645
/**
6746
* This api layer provides access to the electron local storage
6847
* for user settings that are not synced with any coin backend.

source/renderer/app/components/assets/AssetSettingsDialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
MAX_DECIMAL_PRECISION,
1818
} from '../../config/assetsConfig';
1919
import { DiscreetTokenWalletAmount } from '../../features/discreet-mode';
20-
import { isRecommendedDecimal } from '../wallet/tokens/wallet-token/helpers';
20+
import { isNonRecommendedDecimalSettingUsed } from '../wallet/tokens/wallet-token/helpers';
2121

2222
const messages = defineMessages({
2323
title: {
@@ -154,7 +154,7 @@ class AssetSettingsDialog extends Component<Props, State> {
154154
},
155155
];
156156

157-
const hasWarning = isRecommendedDecimal({
157+
const hasWarning = isNonRecommendedDecimalSettingUsed({
158158
recommendedDecimals,
159159
decimals: savedDecimals,
160160
});

source/renderer/app/components/wallet/tokens/wallet-token/WalletToken.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import AssetContent from '../../../assets/AssetContent';
66
import type { AssetToken } from '../../../../api/assets/types';
77
import WalletTokenFooter from './WalletTokenFooter';
88
import WalletTokenHeader from './WalletTokenHeader';
9-
import { isRecommendedDecimal } from './helpers';
9+
import { isNonRecommendedDecimalSettingUsed } from './helpers';
1010

1111
type Props = {
1212
anyAssetWasHovered: boolean;
@@ -49,7 +49,7 @@ const WalletToken = observer((props: Props) => {
4949
setIsExpanded(!isExpanded);
5050
}, [setIsExpanded, isExpanded]);
5151

52-
const hasWarning = isRecommendedDecimal({
52+
const hasWarning = isNonRecommendedDecimalSettingUsed({
5353
decimals: asset.decimals,
5454
recommendedDecimals: asset.recommendedDecimals,
5555
});
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { isNonRecommendedDecimalSettingUsed } from './helpers';
2+
3+
describe('isNonRecommendedDecimalSettingUsed', () => {
4+
it('returns false if asset does not have recommended decimals', async () => {
5+
expect(
6+
isNonRecommendedDecimalSettingUsed({
7+
decimals: 0,
8+
recommendedDecimals: undefined,
9+
})
10+
).toEqual(false);
11+
12+
expect(
13+
isNonRecommendedDecimalSettingUsed({
14+
decimals: 5,
15+
recommendedDecimals: undefined,
16+
})
17+
).toEqual(false);
18+
});
19+
20+
it('returns false if recommended decimal settings are applied by user', async () => {
21+
expect(
22+
isNonRecommendedDecimalSettingUsed({
23+
decimals: 0,
24+
recommendedDecimals: 0,
25+
})
26+
).toEqual(false);
27+
28+
expect(
29+
isNonRecommendedDecimalSettingUsed({
30+
decimals: 5,
31+
recommendedDecimals: 5,
32+
})
33+
).toEqual(false);
34+
});
35+
36+
it('returns false if 0 (default value) is recommended and user never changed settings', async () => {
37+
expect(
38+
isNonRecommendedDecimalSettingUsed({
39+
decimals: undefined,
40+
recommendedDecimals: 0,
41+
})
42+
).toEqual(false);
43+
});
44+
45+
it('returns true if non-zero decimals are recommended but user never changed settings', async () => {
46+
expect(
47+
isNonRecommendedDecimalSettingUsed({
48+
decimals: undefined,
49+
recommendedDecimals: 3,
50+
})
51+
).toEqual(true);
52+
});
53+
54+
it('returns true if user applied non-recommended decimal settings', async () => {
55+
expect(
56+
isNonRecommendedDecimalSettingUsed({
57+
decimals: 3,
58+
recommendedDecimals: 0,
59+
})
60+
).toEqual(true);
61+
62+
expect(
63+
isNonRecommendedDecimalSettingUsed({
64+
decimals: 0,
65+
recommendedDecimals: 3,
66+
})
67+
).toEqual(true);
68+
});
69+
});
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
type IsRecommendedDecimal = {
1+
type IsNonRecommendedDecimalSettingUsedArgs = {
22
decimals: number | null | undefined;
33
recommendedDecimals: number | null | undefined;
44
};
55

6-
export const isRecommendedDecimal = ({
6+
export const isNonRecommendedDecimalSettingUsed = ({
77
recommendedDecimals,
88
decimals,
9-
}: IsRecommendedDecimal) => {
10-
return (
11-
typeof recommendedDecimals === 'number' &&
12-
typeof decimals === 'number' &&
13-
decimals !== recommendedDecimals
14-
);
9+
}: IsNonRecommendedDecimalSettingUsedArgs) => {
10+
const hasRecommendedDecimals = typeof recommendedDecimals === 'number';
11+
const hasConfiguredDecimals = typeof decimals === 'number';
12+
13+
if (!hasRecommendedDecimals) {
14+
return false;
15+
}
16+
if (hasConfiguredDecimals) {
17+
return decimals !== recommendedDecimals;
18+
}
19+
if (!hasConfiguredDecimals && recommendedDecimals === 0) {
20+
return false;
21+
}
22+
23+
return true;
1524
};

source/renderer/app/containers/wallet/WalletReceivePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import WalletAddress from '../../domains/WalletAddress';
1212
import { generateFileNameWithTimestamp } from '../../../../common/utils/files';
1313
import { ellipsis } from '../../utils/strings';
1414
import { generateSupportRequestLink } from '../../../../common/utils/reporting';
15-
import type { WalletLocalData } from '../../api/utils/localStorage';
15+
import { WalletLocalData } from '../../types/localDataTypes';
1616

1717
const messages = defineMessages({
1818
address: {

source/renderer/app/stores/HardwareWalletsStore.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@ import type {
8484
VotingDataType,
8585
} from '../api/transactions/types';
8686
import type {
87-
HardwareWalletLocalData,
88-
HardwareWalletsLocalData,
89-
HardwareWalletDevicesType,
9087
SetHardwareWalletLocalDataRequestType,
9188
SetHardwareWalletDeviceRequestType,
92-
UnpairedHardwareWalletData,
9389
} from '../api/utils/localStorage';
9490
import type {
9591
TransportDevice,
@@ -101,6 +97,12 @@ import type {
10197
TrezorWitness,
10298
} from '../../../common/types/hardware-wallets.types';
10399
import { logger } from '../utils/logging';
100+
import {
101+
HardwareWalletDevicesType,
102+
HardwareWalletLocalData,
103+
HardwareWalletsLocalData,
104+
UnpairedHardwareWalletData,
105+
} from '../types/localDataTypes';
104106

105107
export type TxSignRequestTypes = {
106108
coinSelection: CoinSelectionsResponse;

0 commit comments

Comments
 (0)