Skip to content

Commit

Permalink
Merge pull request #891 from rainlanguage/2024-09-25-account-settings
Browse files Browse the repository at this point in the history
Resetting account filter on settings change
  • Loading branch information
thedavidmeister authored Oct 15, 2024
2 parents 114e4e2 + 0c511db commit 7db075d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tauri-app/src/lib/mocks/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ConfigSource } from '$lib/typeshare/config';
import { writable } from 'svelte/store';

const mockConfigSource: ConfigSource = {
export const mockConfigSource: ConfigSource = {
networks: {
mainnet: {
rpc: 'https://mainnet.infura.io/v3/YOUR-PROJECT-ID',
Expand Down
42 changes: 42 additions & 0 deletions tauri-app/src/lib/stores/settings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect, test, beforeEach, describe } from 'vitest';
import { settings, activeAccountsItems } from './settings';
import { mockConfigSource } from '$lib/mocks/settings';
import { get } from 'svelte/store';

describe('Settings active accounts items', async () => {
beforeEach(() => {
activeAccountsItems.set(mockConfigSource.accounts as Record<string, string>);
expect(get(activeAccountsItems)).toEqual(mockConfigSource.accounts);
});

test('should remove account if that account is removed', () => {
const newSettings = {
...mockConfigSource,
accounts: {
name_one: mockConfigSource.accounts?.name_one as string,
},
};

settings.set(newSettings);

expect(get(activeAccountsItems)).toEqual({
name_one: mockConfigSource.accounts?.name_one as string,
});
});

test('should remove account if the value is different', () => {
const newSettings = {
...mockConfigSource,
accounts: {
name_one: mockConfigSource.accounts?.name_one as string,
name_two: 'new_value',
},
};

settings.set(newSettings);

expect(get(activeAccountsItems)).toEqual({
name_one: mockConfigSource.accounts?.name_one as string,
});
});
});
16 changes: 16 additions & 0 deletions tauri-app/src/lib/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ settings.subscribe(async () => {
) {
resetActiveOrderbookRef();
}

// Reset active account items if accounts have changed
if ($settings?.accounts === undefined) {
activeAccountsItems.set({});
} else {
const currentActiveAccounts = get(activeAccountsItems);
const updatedActiveAccounts = Object.fromEntries(
Object.entries($settings.accounts ?? {}).filter(([key, value]) => {
if (key in currentActiveAccounts) {
return currentActiveAccounts[key] === value;
}
return false;
}),
);
activeAccountsItems.set(updatedActiveAccounts);
}
});

// When active network is updated to undefined, reset active orderbook
Expand Down

0 comments on commit 7db075d

Please sign in to comment.