Skip to content

Commit c935a77

Browse files
committed
refactor!: lift deepEquals to util package in preparation for further wallet decomposition
There are most likely more generic equals utils remaining, but I'm just being minimal for now
1 parent aaf430e commit c935a77

File tree

9 files changed

+20
-24
lines changed

9 files changed

+20
-24
lines changed

packages/util/src/equals.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import isEqual from 'lodash/isEqual';
2+
3+
export const deepEquals = <T>(a: T, b: T) => isEqual(a, b);

packages/util/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './equals';
12
export * from './types';
23
export * from './BigIntMath';
34
export * from './hexString';

packages/util/test/equals.test.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { deepEquals } from '../src';
2+
3+
describe('equals', () => {
4+
test('deepEquals', () => {
5+
expect(deepEquals([], [])).toBe(true);
6+
expect(deepEquals({}, {})).toBe(true);
7+
expect(deepEquals([{ prop: 'prop' }], [{ prop: 'prop' }])).toBe(true);
8+
expect(deepEquals([{ prop: 'prop' }], [{ prop: 'prop2' }])).toBe(false);
9+
});
10+
});

packages/wallet/src/KeyManagement/util/stubSignTransaction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Address, Cardano } from '@cardano-sdk/core';
22
import { GroupedAddress, SignTransactionOptions, TransactionSigner } from '../types';
3-
import { deepEquals } from '../../services';
3+
import { deepEquals } from '@cardano-sdk/util';
44
import { ownSignatureKeyPaths } from './ownSignatureKeyPaths';
55
import uniqWith from 'lodash/uniqWith';
66

packages/wallet/src/SingleAddressWallet.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import {
5858
createUtxoTracker,
5959
createWalletUtil,
6060
currentEpochTracker,
61-
deepEquals,
6261
distinctBlock,
6362
distinctEraSummaries,
6463
groupedAddressesEquals
@@ -86,7 +85,7 @@ import { Cip30DataSignature } from '@cardano-sdk/cip30';
8685
import { InputSelector, defaultSelectionConstraints, roundRobinRandomImprove } from '@cardano-sdk/cip2';
8786
import { Logger } from 'ts-log';
8887
import { RetryBackoffConfig } from 'backoff-rxjs';
89-
import { Shutdown, bufferToHexString, contextLogger } from '@cardano-sdk/util';
88+
import { Shutdown, bufferToHexString, contextLogger, deepEquals } from '@cardano-sdk/util';
9089
import { TrackedUtxoProvider } from './services/ProviderTracker/TrackedUtxoProvider';
9190
import { WalletStores, createInMemoryWalletStores } from './persistence';
9291
import { cip30signData } from './KeyManagement/cip8';

packages/wallet/src/TxBuilder/buildTx.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@ import {
1515
TxOutValidationError
1616
} from './types';
1717
import { ObservableWalletTxOutputBuilder, toOutputValidationError } from './OutputBuilder';
18-
import {
19-
OutputValidator,
20-
RewardAccount,
21-
StakeKeyStatus,
22-
WalletUtilContext,
23-
createWalletUtil,
24-
deepEquals
25-
} from '../services';
18+
import { OutputValidator, RewardAccount, StakeKeyStatus, WalletUtilContext, createWalletUtil } from '../services';
2619
import { SignTransactionOptions, TransactionSigner } from '../KeyManagement';
20+
import { deepEquals } from '@cardano-sdk/util';
2721

2822
/**
2923
* Minimal sub-type of ObservableWallet that is used by TxBuilder.

packages/wallet/src/services/DelegationTracker/RewardAccounts.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable unicorn/no-nested-ternary */
2-
import { BigIntMath, isNotNil } from '@cardano-sdk/util';
2+
import { BigIntMath, deepEquals, isNotNil } from '@cardano-sdk/util';
33
import { Cardano, RewardsProvider } from '@cardano-sdk/core';
44
import { Delegatee, RewardAccount, StakeKeyStatus } from '../types';
55
import { KeyValueStore } from '../../persistence';
@@ -12,7 +12,7 @@ import {
1212
import { RetryBackoffConfig } from 'backoff-rxjs';
1313
import { TrackedStakePoolProvider } from '../ProviderTracker';
1414
import { TxWithEpoch } from './types';
15-
import { coldObservableProvider, deepEquals, shallowArrayEquals } from '../util';
15+
import { coldObservableProvider, shallowArrayEquals } from '../util';
1616
import findLast from 'lodash/findLast';
1717
import isEqual from 'lodash/isEqual';
1818
import uniq from 'lodash/uniq';

packages/wallet/src/services/util/equals.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { Cardano, EpochInfo, EraSummary } from '@cardano-sdk/core';
22
import { GroupedAddress } from '../../KeyManagement';
3-
import isEqual from 'lodash/isEqual';
43

54
export const strictEquals = <T>(a: T, b: T) => a === b;
65

7-
export const deepEquals = <T>(a: T, b: T) => isEqual(a, b);
8-
96
export const arrayEquals = <T>(arrayA: T[], arrayB: T[], itemEquals: (a: T, b: T) => boolean) =>
107
arrayA.length === arrayB.length && arrayA.every((a) => arrayB.some((b) => itemEquals(a, b)));
118

packages/wallet/test/services/util/equals.test.ts

-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Cardano, EpochInfo, EraSummary } from '@cardano-sdk/core';
33
import { GroupedAddress } from '../../../src/KeyManagement';
44
import {
55
arrayEquals,
6-
deepEquals,
76
epochInfoEquals,
87
eraSummariesEquals,
98
groupedAddressesEquals,
@@ -38,13 +37,6 @@ describe('equals', () => {
3837
expect(shallowArrayEquals([a], [a])).toBe(true);
3938
});
4039

41-
test('deepEquals', () => {
42-
expect(deepEquals([], [])).toBe(true);
43-
expect(deepEquals({}, {})).toBe(true);
44-
expect(deepEquals([{ prop: 'prop' }], [{ prop: 'prop' }])).toBe(true);
45-
expect(deepEquals([{ prop: 'prop' }], [{ prop: 'prop2' }])).toBe(false);
46-
});
47-
4840
test('txEquals', () => {
4941
expect(txEquals({ id: txId1 } as Cardano.TxAlonzo, { id: txId2 } as Cardano.TxAlonzo)).toBe(false);
5042
expect(txEquals({ id: txId1 } as Cardano.TxAlonzo, { id: txId1 } as Cardano.TxAlonzo)).toBe(true);

0 commit comments

Comments
 (0)