UNPKG

@soundsright/connector

Version:

soundsright wallet connector

55 lines (54 loc) 2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WalletNetworkError = exports.WalletNotConnectedError = exports.AddressAccessFailedError = exports.NoEthereumProviderError = exports.Connection = exports.ConnectType = void 0; const events_1 = require("events"); var ConnectType; (function (ConnectType) { ConnectType["MetaMask"] = "MetaMask"; ConnectType["WalletConnect"] = "WalletConnect"; })(ConnectType = exports.ConnectType || (exports.ConnectType = {})); class Connection extends events_1.EventEmitter { constructor() { super(); this.state = {}; } emitChange(event, error) { const eventData = Object.assign(Object.assign({}, this.state), { error }); this.emit(event, eventData); this.emit('change', Object.assign({ event }, eventData)); } } exports.Connection = Connection; class NoEthereumProviderError extends Error { constructor() { super(); this.name = 'NoEthereumProviderError'; this.message = 'No Ethereum provider was found on window.ethereum.'; } } exports.NoEthereumProviderError = NoEthereumProviderError; class AddressAccessFailedError extends Error { constructor() { super(); this.name = 'AddressAccessFailedError'; this.message = 'Wallet address access failed'; } } exports.AddressAccessFailedError = AddressAccessFailedError; class WalletNotConnectedError extends Error { constructor() { super(); this.name = 'WalletNotConnectedError'; this.message = 'Wallet not connected.'; } } exports.WalletNotConnectedError = WalletNotConnectedError; class WalletNetworkError extends Error { constructor(network) { super(); this.name = 'WalletNetworkError'; this.message = `Wallet cannot switch to ${network.chainName} network.`; this.network = network; } } exports.WalletNetworkError = WalletNetworkError;