From 15e6c4ffef78154c27a771a8afbe1be5c7fe0e2a Mon Sep 17 00:00:00 2001 From: macqbat Date: Tue, 4 Oct 2022 17:57:36 +0200 Subject: [PATCH] Bug/1606 wrong update of new added deposit (#1608) * chore: fix for accounts update * chore: fix for accounts update Co-authored-by: maciek --- .../src/lib/accounts-data-provider.spec.ts | 37 ++++++++++++++++++- .../src/lib/accounts-data-provider.ts | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) 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;