chore: accounts-table reload after partyId change (#1764)
* chore: accounts-table reload after partyId change * chore: accounts-table reload after partyId change Co-authored-by: maciek <maciek@vegaprotocol.io>
This commit is contained in:
parent
3b41e9f2f8
commit
d8544ddd00
24
libs/accounts/src/lib/accounts-manager.spec.tsx
Normal file
24
libs/accounts/src/lib/accounts-manager.spec.tsx
Normal file
@ -0,0 +1,24 @@
|
||||
import { act, render } from '@testing-library/react';
|
||||
import { AccountManager } from './accounts-manager';
|
||||
|
||||
const mockReload = jest.fn();
|
||||
jest.mock('@vegaprotocol/react-helpers', () => ({
|
||||
...jest.requireActual('@vegaprotocol/react-helpers'),
|
||||
useDataProvider: jest.fn(() => ({
|
||||
data: [],
|
||||
reload: mockReload,
|
||||
})),
|
||||
}));
|
||||
|
||||
describe('AccountManager', () => {
|
||||
it('change partyId should reload data provider', async () => {
|
||||
const { rerender } = render(
|
||||
<AccountManager partyId="partyOne" onClickAsset={jest.fn} />
|
||||
);
|
||||
expect(mockReload).not.toHaveBeenCalled();
|
||||
await act(() => {
|
||||
rerender(<AccountManager partyId="partyTwo" onClickAsset={jest.fn} />);
|
||||
});
|
||||
expect(mockReload).toHaveBeenCalledWith(true);
|
||||
});
|
||||
});
|
@ -21,6 +21,7 @@ export const AccountManager = ({
|
||||
onClickDeposit,
|
||||
partyId,
|
||||
}: AccountManagerProps) => {
|
||||
const partyIdRef = useRef<string>(partyId);
|
||||
const gridRef = useRef<AgGridReact | null>(null);
|
||||
const dataRef = useRef<AccountFields[] | null>(null);
|
||||
const variables = useMemo(() => ({ partyId }), [partyId]);
|
||||
@ -32,11 +33,19 @@ export const AccountManager = ({
|
||||
},
|
||||
[gridRef]
|
||||
);
|
||||
const { data, loading, error } = useDataProvider<AccountFields[], never>({
|
||||
|
||||
const { data, loading, error, reload } = useDataProvider<
|
||||
AccountFields[],
|
||||
never
|
||||
>({
|
||||
dataProvider: aggregatedAccountsDataProvider,
|
||||
update,
|
||||
variables,
|
||||
});
|
||||
if (partyId !== partyIdRef.current) {
|
||||
reload(true);
|
||||
partyIdRef.current = partyId;
|
||||
}
|
||||
if (!dataRef.current && data) {
|
||||
dataRef.current = data;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user