@onekeyfe/onekey-nostr-provider
Advanced tools
Comparing version 1.1.51 to 1.1.52
@@ -14,2 +14,11 @@ "use strict"; | ||
const ProviderNostrBase_1 = require("./ProviderNostrBase"); | ||
function isWalletEventMethodMatch(method, name) { | ||
return method === `metamask_${name}` || method === `wallet_events_${name}`; | ||
} | ||
const PROVIDER_EVENTS = { | ||
'connect': 'connect', | ||
'disconnect': 'disconnect', | ||
'accountChanged': 'accountChanged', | ||
'message_low_level': 'message_low_level', | ||
}; | ||
class ProviderNostr extends ProviderNostrBase_1.ProviderNostrBase { | ||
@@ -32,21 +41,30 @@ constructor(props) { | ||
}; | ||
this._registerEvents(); | ||
} | ||
setExecuting(executing) { | ||
this.states.executing = executing; | ||
_registerEvents() { | ||
window.addEventListener('onekey_bridge_disconnect', () => { | ||
this._handleDisconnected(); | ||
}); | ||
this.on(PROVIDER_EVENTS.message_low_level, (payload) => { | ||
const { method } = payload; | ||
if (isWalletEventMethodMatch(method, PROVIDER_EVENTS.accountChanged)) { | ||
this._handleAccountChange(); | ||
} | ||
}); | ||
} | ||
checkEnabled(method) { | ||
if (!this.states.enabled) { | ||
const message = `Please allow the connection request of webln before calling the ${method} method`; | ||
alert(message); | ||
throw new Error(message); | ||
_handleDisconnected(options = { emit: true }) { | ||
if (options.emit && this.isConnectionStatusChanged('disconnected')) { | ||
this.emit('disconnect'); | ||
this.emit('accountChanged'); | ||
} | ||
if (this.states.executing) { | ||
const message = `window.webln call already executing`; | ||
alert(message); | ||
throw new Error(message); | ||
} | ||
} | ||
_handleAccountChange() { | ||
this.emit('accountChanged'); | ||
} | ||
on(event, listener) { | ||
return super.on(event, listener); | ||
} | ||
off(event, listener) { | ||
return super.off(event, listener); | ||
} | ||
emit(event, ...args) { | ||
@@ -53,0 +71,0 @@ return super.emit(event, ...args); |
@@ -7,5 +7,7 @@ import { IInpageProviderConfig } from "@onekeyfe/cross-inpage-provider-core"; | ||
constructor(props: IInpageProviderConfig); | ||
setExecuting(executing: boolean): void; | ||
private checkEnabled; | ||
private _registerEvents; | ||
private _handleDisconnected; | ||
private _handleAccountChange; | ||
on<E extends keyof NostrProviderEventsMap>(event: E, listener: NostrProviderEventsMap[E]): this; | ||
off<E extends keyof NostrProviderEventsMap>(event: E, listener: NostrProviderEventsMap[E]): this; | ||
emit<E extends keyof NostrProviderEventsMap>(event: E, ...args: Parameters<NostrProviderEventsMap[E]>): boolean; | ||
@@ -12,0 +14,0 @@ private _callBridge; |
@@ -11,2 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { ProviderNostrBase } from "./ProviderNostrBase"; | ||
function isWalletEventMethodMatch(method, name) { | ||
return method === `metamask_${name}` || method === `wallet_events_${name}`; | ||
} | ||
const PROVIDER_EVENTS = { | ||
'connect': 'connect', | ||
'disconnect': 'disconnect', | ||
'accountChanged': 'accountChanged', | ||
'message_low_level': 'message_low_level', | ||
}; | ||
class ProviderNostr extends ProviderNostrBase { | ||
@@ -29,21 +38,30 @@ constructor(props) { | ||
}; | ||
this._registerEvents(); | ||
} | ||
setExecuting(executing) { | ||
this.states.executing = executing; | ||
_registerEvents() { | ||
window.addEventListener('onekey_bridge_disconnect', () => { | ||
this._handleDisconnected(); | ||
}); | ||
this.on(PROVIDER_EVENTS.message_low_level, (payload) => { | ||
const { method } = payload; | ||
if (isWalletEventMethodMatch(method, PROVIDER_EVENTS.accountChanged)) { | ||
this._handleAccountChange(); | ||
} | ||
}); | ||
} | ||
checkEnabled(method) { | ||
if (!this.states.enabled) { | ||
const message = `Please allow the connection request of webln before calling the ${method} method`; | ||
alert(message); | ||
throw new Error(message); | ||
_handleDisconnected(options = { emit: true }) { | ||
if (options.emit && this.isConnectionStatusChanged('disconnected')) { | ||
this.emit('disconnect'); | ||
this.emit('accountChanged'); | ||
} | ||
if (this.states.executing) { | ||
const message = `window.webln call already executing`; | ||
alert(message); | ||
throw new Error(message); | ||
} | ||
} | ||
_handleAccountChange() { | ||
this.emit('accountChanged'); | ||
} | ||
on(event, listener) { | ||
return super.on(event, listener); | ||
} | ||
off(event, listener) { | ||
return super.off(event, listener); | ||
} | ||
emit(event, ...args) { | ||
@@ -50,0 +68,0 @@ return super.emit(event, ...args); |
@@ -67,5 +67,5 @@ import { IJsonRpcRequest } from '@onekeyfe/cross-inpage-provider-types'; | ||
[PROVIDER_EVENTS.disconnect]: () => void; | ||
[PROVIDER_EVENTS.accountChanged]: (account: string | null) => void; | ||
[PROVIDER_EVENTS.accountChanged]: () => void; | ||
[PROVIDER_EVENTS.message_low_level]: (payload: IJsonRpcRequest) => void; | ||
}; | ||
export {}; |
{ | ||
"name": "@onekeyfe/onekey-nostr-provider", | ||
"version": "1.1.51", | ||
"version": "1.1.52", | ||
"keywords": [ | ||
@@ -31,8 +31,8 @@ "cross-inpage-provider" | ||
"dependencies": { | ||
"@onekeyfe/cross-inpage-provider-core": "1.1.51", | ||
"@onekeyfe/cross-inpage-provider-errors": "1.1.51", | ||
"@onekeyfe/cross-inpage-provider-types": "1.1.51", | ||
"@onekeyfe/extension-bridge-injected": "1.1.51" | ||
"@onekeyfe/cross-inpage-provider-core": "1.1.52", | ||
"@onekeyfe/cross-inpage-provider-errors": "1.1.52", | ||
"@onekeyfe/cross-inpage-provider-types": "1.1.52", | ||
"@onekeyfe/extension-bridge-injected": "1.1.52" | ||
}, | ||
"gitHead": "dc579c5d16a7d2c8abac2c7c7e431e3a8e7d2d84" | ||
"gitHead": "795ee2fb501fbd6fc88f1a91d77d8d6b33db3c30" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28952
421
+ Added@onekeyfe/cross-inpage-provider-core@1.1.52(transitive)
+ Added@onekeyfe/cross-inpage-provider-errors@1.1.52(transitive)
+ Added@onekeyfe/cross-inpage-provider-events@1.1.52(transitive)
+ Added@onekeyfe/cross-inpage-provider-types@1.1.52(transitive)
+ Added@onekeyfe/extension-bridge-injected@1.1.52(transitive)
- Removed@onekeyfe/cross-inpage-provider-core@1.1.51(transitive)
- Removed@onekeyfe/cross-inpage-provider-errors@1.1.51(transitive)
- Removed@onekeyfe/cross-inpage-provider-events@1.1.51(transitive)
- Removed@onekeyfe/cross-inpage-provider-types@1.1.51(transitive)
- Removed@onekeyfe/extension-bridge-injected@1.1.51(transitive)