123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.detectEthereumProvider = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
- "use strict";
- /**
- * Returns a Promise that resolves to the value of window.ethereum if it is
- * set within the given timeout, or null.
- * The Promise will not reject, but an error will be thrown if invalid options
- * are provided.
- *
- * @param options - Options bag.
- * @param options.mustBeMetaMask - Whether to only look for MetaMask providers.
- * Default: false
- * @param options.silent - Whether to silence console errors. Does not affect
- * thrown errors. Default: false
- * @param options.timeout - Milliseconds to wait for 'ethereum#initialized' to
- * be dispatched. Default: 3000
- * @returns A Promise that resolves with the Provider if it is detected within
- * given timeout, otherwise null.
- */
- function detectEthereumProvider({ mustBeMetaMask = false, silent = false, timeout = 3000, } = {}) {
- _validateInputs();
- let handled = false;
- return new Promise((resolve) => {
- if (window.ethereum) {
- handleEthereum();
- }
- else {
- window.addEventListener('ethereum#initialized', handleEthereum, { once: true });
- setTimeout(() => {
- handleEthereum();
- }, timeout);
- }
- function handleEthereum() {
- if (handled) {
- return;
- }
- handled = true;
- window.removeEventListener('ethereum#initialized', handleEthereum);
- const { ethereum } = window;
- if (ethereum && (!mustBeMetaMask || ethereum.isMetaMask)) {
- resolve(ethereum);
- }
- else {
- const message = mustBeMetaMask && ethereum
- ? 'Non-MetaMask window.ethereum detected.'
- : 'Unable to detect window.ethereum.';
- !silent && console.error('@metamask/detect-provider:', message);
- resolve(null);
- }
- }
- });
- function _validateInputs() {
- if (typeof mustBeMetaMask !== 'boolean') {
- throw new Error(`@metamask/detect-provider: Expected option 'mustBeMetaMask' to be a boolean.`);
- }
- if (typeof silent !== 'boolean') {
- throw new Error(`@metamask/detect-provider: Expected option 'silent' to be a boolean.`);
- }
- if (typeof timeout !== 'number') {
- throw new Error(`@metamask/detect-provider: Expected option 'timeout' to be a number.`);
- }
- }
- }
- module.exports = detectEthereumProvider;
- },{}]},{},[1])(1)
- });
|