-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dapp: add connection options to vuex user settings
This extension of the user settings allows to make the Ethereum connection options as provided by the user can be easily preserved and reloaded. This is a preparation for the connection management by the user. For this commit the connection options are still derived from the configuration file. Later this will allows to save the users connection options and pre-fill the connection dialog, allow for auto-logins, change the options somewhere else and more.
- Loading branch information
Showing
7 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { GetterTree } from 'vuex'; | ||
|
||
import type { EthereumConnectionOptions } from '@/services/ethereum-connection'; | ||
import type { RootState } from '@/types'; | ||
|
||
import type { UserSettingsState } from './types'; | ||
|
||
type Getters = { | ||
getEthereumConnectionOptions( | ||
state: UserSettingsState, | ||
): (connectionName: string) => EthereumConnectionOptions; | ||
}; | ||
|
||
export const getters: GetterTree<UserSettingsState, RootState> & Getters = { | ||
// This getter is relevant to have a standardized default value that works for | ||
// all component which interact with such connection options. | ||
getEthereumConnectionOptions: (state) => (connectionName) => { | ||
return state.ethereumConnectionOptions[connectionName] ?? {}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
import type { EthereumConnectionOptions } from '@/services/ethereum-connection'; | ||
|
||
export interface UserSettingsState { | ||
useRaidenAccount: boolean; | ||
ethereumConnectionOptions: { [connectionName: string]: EthereumConnectionOptions }; | ||
} |
19 changes: 19 additions & 0 deletions
19
raiden-dapp/tests/unit/store/user-settings/getters.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getters } from '@/store/user-settings/getters'; | ||
import { defaultState } from '@/store/user-settings/state'; | ||
|
||
describe('user settings store getters', () => { | ||
test('get empty options for etherum connections per default', () => { | ||
const state = defaultState(); | ||
|
||
expect(getters.getEthereumConnectionOptions(state)('test_connection')).toMatchObject({}); | ||
}); | ||
|
||
test('get saved options for etherum connections', () => { | ||
const state = defaultState(); | ||
state.ethereumConnectionOptions['test_connection'] = { option: 'test' }; | ||
|
||
expect(getters.getEthereumConnectionOptions(state)('test_connection')).toMatchObject({ | ||
option: 'test', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters