This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose peer discovery to plugins (#1808)
- Loading branch information
Showing
6 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
__tests__/unit/services/plugin-manager/sandbox/peer-all-sandbox.spec.js
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,35 @@ | ||
import { create as createPeerAllSandbox } from '@/services/plugin-manager/sandbox/peer-all-sandbox' | ||
|
||
class PeerDiscoveryStub { | ||
withLatency () { | ||
return this | ||
} | ||
|
||
sortBy () { | ||
return this | ||
} | ||
} | ||
|
||
const mockDispatch = jest.fn(() => new PeerDiscoveryStub()) | ||
|
||
let walletApi | ||
let app | ||
let peerAllSandbox | ||
|
||
describe('Peer All Sandbox', () => { | ||
beforeEach(() => { | ||
walletApi = {} | ||
app = { | ||
$store: { | ||
dispatch: mockDispatch | ||
} | ||
} | ||
peerAllSandbox = createPeerAllSandbox(walletApi, app) | ||
peerAllSandbox() | ||
}) | ||
|
||
it('should expose functions', () => { | ||
expect(mockDispatch).toHaveBeenCalled() | ||
expect(walletApi.peers.all).toBeTruthy() | ||
}) | ||
}) |
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
13 changes: 13 additions & 0 deletions
13
src/renderer/services/plugin-manager/sandbox/peer-all-sandbox.js
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,13 @@ | ||
export function create (walletApi, app) { | ||
return async () => { | ||
if (!walletApi.peers) { | ||
walletApi.peers = {} | ||
} | ||
|
||
const peerDiscovery = (await app.$store.dispatch('peer/getPeerDiscovery')) | ||
.withLatency(300) | ||
.sortBy('latency') | ||
|
||
walletApi.peers.all = peerDiscovery | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/renderer/services/plugin-manager/sandbox/peer-current-sandbox.js
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