diff --git a/package.json b/package.json index 62a95cc..c29a9e5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "namespace": "multiplechain", "name": "@multiplechain/solana", - "version": "0.1.8", + "version": "0.1.9", "description": "Solana has ready-made methods to connect to wallets and perform many transactions.", "scripts": { "serve": "parcel test.html --no-cache --dist-dir test", diff --git a/src/adapters/phantom.js b/src/adapters/phantom.js index e8a2eff..94f7507 100644 --- a/src/adapters/phantom.js +++ b/src/adapters/phantom.js @@ -6,8 +6,13 @@ module.exports = phantom = (provider) => { return { key: 'phantom', name: 'Phantom', - type: 'browser', + supports: [ + 'browser', + 'mobile' + ], wallet, - download: 'https://phantom.app/' + download: 'https://phantom.app/download', + deepLink: 'https://phantom.app/ul/browse/{siteUrl}?ref={siteUrl}', + detected: Boolean(window.phantom?.solana?.isPhantom) } } diff --git a/src/adapters/slope.js b/src/adapters/slope.js index 21f7223..bd84d27 100644 --- a/src/adapters/slope.js +++ b/src/adapters/slope.js @@ -6,7 +6,11 @@ module.exports = slope = (provider) => { return { key: 'slope', name: 'Slope', - type: 'browser', - wallet + supports: [ + 'browser' + ], + wallet, + download: 'https://www.slope.finance/', + detected: Boolean(window.Slope) } } \ No newline at end of file diff --git a/src/adapters/solflare.js b/src/adapters/solflare.js index 0f36556..2c05008 100644 --- a/src/adapters/solflare.js +++ b/src/adapters/solflare.js @@ -7,6 +7,13 @@ module.exports = solflare = (provider) => { key: 'solflare', name: 'Solflare', type: 'browser', - wallet + supports: [ + 'browser', + 'mobile' + ], + wallet, + download: 'https://solflare.com/download#extension', + deepLink: 'https://solflare.com/ul/v1/browse/{siteUrl}?ref={siteUrl}', + detected: Boolean(window.solflare?.isSolflare) } } diff --git a/src/provider.js b/src/provider.js index 2430121..dfae65c 100644 --- a/src/provider.js +++ b/src/provider.js @@ -74,7 +74,6 @@ class Provider { * @param {Object} options */ constructor(options) { - this.wsUrl = options.customWs; this.testnet = options.testnet; this.network = this.networks[this.testnet ? 'devnet' : 'mainnet']; @@ -82,6 +81,10 @@ class Provider { this.network.host = options.customRpc; } + if (!this.testnet && options.customWs) { + this.wsUrl = options.customWs; + } + if (this.wsUrl) { this.qrPayments = true; } @@ -241,12 +244,31 @@ class Provider { } /** - * @param {Array} filter + * @param {Array|null} filter + * @returns {Array} + */ + getSupportedWallets(filter) { + + const Wallet = require('./wallet'); + + const wallets = { + phantom: new Wallet('phantom', this), + solflare: new Wallet('solflare', this), + slope: new Wallet('slope', this), + }; + + return Object.fromEntries(Object.entries(wallets).filter(([key]) => { + return !filter ? true : filter.includes(key); + })); + } + + /** + * @param {Array|null} filter * @returns {Array} */ getDetectedWallets(filter) { return Object.fromEntries(Object.entries(this.detectedWallets).filter(([key]) => { - return filter.includes(key); + return !filter ? true : filter.includes(key); })); } diff --git a/src/wallet.js b/src/wallet.js index 7240ae5..68f1654 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -71,8 +71,8 @@ class Wallet { /** * @returns {String} */ - getType() { - return this.adapter.type; + getSupports() { + return this.adapter.supports; } /** @@ -89,6 +89,13 @@ class Wallet { return this.adapter.download; } + /** + * @returns {Boolean} + */ + isDetected() { + return this.adapter.detected; + } + getConnectedPublicKey() { return this.solWalletAdapter.publicKey.value || this.solWalletAdapter.publicKey; } @@ -101,23 +108,12 @@ class Wallet { this.wallet.addListener('error', (error) => { utils.rejectMessage(error, reject); }); - - let time = 0; - let timeout = 15; - let timer = setInterval(async () => { - time += 1; - if (time > timeout) { - clearInterval(timer); - reject('timeout'); - } - }, 1000); await this.solWalletAdapter.connect(this.wallet.name); this.provider.setConnectedWallet(this); this.connectedAccount = this.getConnectedAccount(); - clearInterval(timer); resolve(this.connectedAccount); } catch (error) { utils.rejectMessage(error, reject);