diff --git a/libs/accounts/src/lib/accounts-data-provider.spec.ts b/libs/accounts/src/lib/accounts-data-provider.spec.ts index 447e6887b..01dfec14d 100644 --- a/libs/accounts/src/lib/accounts-data-provider.spec.ts +++ b/libs/accounts/src/lib/accounts-data-provider.spec.ts @@ -1,6 +1,6 @@ import { AccountType } from '@vegaprotocol/types'; import type { AccountFields, Account } from './accounts-data-provider'; -import { getAccountData } from './accounts-data-provider'; +import { getAccountData, getId } from './accounts-data-provider'; describe('getAccountData', () => { it('should return the correct aggregated data', () => { @@ -9,6 +9,41 @@ describe('getAccountData', () => { }); }); +describe('getId', () => { + it('should return the correct string', () => { + expect( + getId({ + type: AccountType.ACCOUNT_TYPE_GENERAL, + balance: '1', + asset: { id: 'assetId' }, + market: null, + }) + ).toEqual( + getId({ + type: AccountType.ACCOUNT_TYPE_GENERAL, + balance: '1', + assetId: 'assetId', + marketId: '', + }) + ); + expect( + getId({ + type: AccountType.ACCOUNT_TYPE_GENERAL, + balance: '1', + asset: { id: 'assetId' }, + market: { id: 'testId' }, + }) + ).toEqual( + getId({ + type: AccountType.ACCOUNT_TYPE_GENERAL, + balance: '1', + assetId: 'assetId', + marketId: 'testId', + }) + ); + }); +}); + const accounts = [ { __typename: 'Account', diff --git a/libs/accounts/src/lib/accounts-data-provider.ts b/libs/accounts/src/lib/accounts-data-provider.ts index a353c7739..299b8e789 100644 --- a/libs/accounts/src/lib/accounts-data-provider.ts +++ b/libs/accounts/src/lib/accounts-data-provider.ts @@ -37,7 +37,7 @@ export const getId = ( ) => isAccount(account) ? `${account.type}-${account.asset.id}-${account.market?.id ?? 'null'}` - : `${account.type}-${account.assetId}-${account.marketId}`; + : `${account.type}-${account.assetId}-${account.marketId || 'null'}`; export type Account = Omit & { market?: Market | null;