Skip to content

Commit

Permalink
add removeProvidet to providerDetector
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteNik16 committed Sep 26, 2024
1 parent 8083964 commit 7a5b443
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0-rc.17] - 2024-09-26
### Added
- `@distributedlab/w3p` - `removeProvider` method to `ProviderDetector`

## [1.0.0-rc.16] - 2024-05-03
### Fixed
- `@distributedlab/w3p` - `ProviderDetector` resets pure providers list on init
Expand Down
2 changes: 1 addition & 1 deletion packages/fetcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/fetcher",
"version": "1.0.0-rc.16",
"version": "1.0.0-rc.17",
"description": "Fetch API wrapper with the extended functionality and simple interface",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/jac/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/jac",
"version": "1.0.0-rc.16",
"version": "1.0.0-rc.17",
"description": "A library for constructing JSON-API compliant requests and responses",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/reactivity",
"version": "1.0.0-rc.16",
"version": "1.0.0-rc.17",
"description": "Implementation of the reactivity connections to propagate changes between objects",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/tools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/tools",
"version": "1.0.0-rc.16",
"version": "1.0.0-rc.17",
"description": "Collection of common utility functions and classes",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/w3p/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@distributedlab/w3p",
"version": "1.0.0-rc.16",
"version": "1.0.0-rc.17",
"description": "Wrapper for Web3 Providers",
"repository": {
"type": "git",
Expand Down
20 changes: 19 additions & 1 deletion packages/w3p/src/provider-detector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ describe('performs provider detector unit test', () => {
expect(providerDetector.isEnabled).toBeTruthy()
})
})
describe('performs get and add providers', () => {

describe('performs get, add, and remove providers', () => {
let providerDetector: ProviderDetector<keyof Record<string, string>>

beforeEach(() => {
Expand Down Expand Up @@ -49,5 +50,22 @@ describe('performs provider detector unit test', () => {
name: PROVIDERS.Metamask,
})
})

test('should remove a provider', async () => {
mockWindow({ ethereum: { providers: [MetamaskProvider] } })
providerDetector.addProvider({ name: PROVIDERS.Metamask })
providerDetector.addProvider({ name: PROVIDERS.Coinbase })

expect(providerDetector.providers).toEqual({
metamask: { name: PROVIDERS.Metamask },
coinbase: { name: PROVIDERS.Coinbase },
})

providerDetector.removeProvider({ name: PROVIDERS.Metamask })

expect(providerDetector.providers).toEqual({
coinbase: { name: PROVIDERS.Coinbase },
})
})
})
})
6 changes: 6 additions & 0 deletions packages/w3p/src/provider-detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ export class ProviderDetector<T extends keyof Record<string, string>> {
this.pureProviders.push(provider)
}

public removeProvider(providerToRemove: ProviderInstance<T>): void {
this.pureProviders = this.pureProviders.filter(
provider => provider.name !== providerToRemove.name,
)
}

detectRawProviders(): void {
const ethProviders = window?.ethereum
? window?.ethereum?.providers || [window?.ethereum]
Expand Down

0 comments on commit 7a5b443

Please sign in to comment.