Skip to content

Commit

Permalink
feat(keychain): expose clear method instead of clearing in plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura committed Jan 23, 2024
1 parent d7e3711 commit c04181c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 35 deletions.
16 changes: 1 addition & 15 deletions features/keychain/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import memoizedKeychainDefinition from './module/memoized-keychain'
import keychainDefinition from './module/keychain'
import keychainPluginDefinition from './plugin'

const storageOpts = {
storage: { namespace: 'keychain' },
}

const keychain = ({ cachePublicKeys }) => {
return {
id: 'keychain',
definitions: cachePublicKeys
? [
{
definition: memoizedKeychainDefinition,
...storageOpts,
},
{
definition: keychainPluginDefinition,
...storageOpts,
},
]
? [{ definition: memoizedKeychainDefinition, storage: { namespace: 'keychain' } }]
: [{ definition: keychainDefinition }],
}
}
Expand Down
9 changes: 7 additions & 2 deletions features/keychain/module/keychain.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,19 @@ export class Keychain extends ExodusModule {
clone() {
return new Keychain({ legacyPrivToPub: this.#legacyPrivToPub })
}

clear = async () => {
// noop
}
}

const createKeychain = (args = {}) => new Keychain({ ...args })

// eslint-disable-next-line @exodus/export-default/named
export default {
const keychainDefinition = {
id: MODULE_ID,
type: 'module',
factory: createKeychain,
dependencies: ['legacyPrivToPub', 'logger'],
}

export default keychainDefinition
8 changes: 6 additions & 2 deletions features/keychain/module/memoized-keychain.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MemoizedKeychain extends Keychain {
#storage
#publicKeys = {}
#cloneOpts

constructor({ storage, logger }) {
super({ id: MODULE_ID, logger })

Expand Down Expand Up @@ -49,12 +50,15 @@ class MemoizedKeychain extends Keychain {
}

clone = () => new MemoizedKeychain(this.#cloneOpts)

clear = async () => this.#storage.delete(CACHE_KEY)
}

// eslint-disable-next-line @exodus/export-default/named
export default {
const memoizedKeychainDefinition = {
id: 'keychain',
type: 'module',
factory: (opts) => new MemoizedKeychain(opts),
dependencies: ['storage', 'logger'],
}

export default memoizedKeychainDefinition
1 change: 0 additions & 1 deletion features/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"index.js",
"atoms",
"module",
"plugin",
"README.md",
"CHANGELOG.md",
"!**/__tests__/**"
Expand Down
15 changes: 0 additions & 15 deletions features/keychain/plugin/index.js

This file was deleted.

0 comments on commit c04181c

Please sign in to comment.