Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add removeProvidet to providerDetector #54

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading