@solflare-wallet/metamask-sdk
Advanced tools
Comparing version 0.0.3 to 0.0.4
import { PublicKey, SendOptions } from '@solana/web3.js'; | ||
import { SolflareConfig, TransactionOrVersionedTransaction } from './types'; | ||
import { SolflareMetamaskConfig, TransactionOrVersionedTransaction } from './types'; | ||
import EventEmitter from 'eventemitter3'; | ||
export default class SolflareMetamask extends EventEmitter { | ||
private _network; | ||
private _iframeParams; | ||
private _element; | ||
@@ -13,3 +14,3 @@ private _iframe; | ||
private static IFRAME_URL; | ||
constructor(config?: SolflareConfig); | ||
constructor(config?: SolflareMetamaskConfig); | ||
get publicKey(): PublicKey | null; | ||
@@ -16,0 +17,0 @@ get isConnected(): boolean; |
@@ -89,2 +89,3 @@ "use strict"; | ||
_this._network = 'mainnet-beta'; | ||
_this._iframeParams = {}; | ||
_this._element = null; | ||
@@ -210,6 +211,7 @@ _this._iframe = null; | ||
_this._removeDanglingElements(); | ||
var network = encodeURIComponent(_this._network); | ||
var origin = encodeURIComponent(window.location.origin); | ||
var title = encodeURIComponent(document.title); | ||
var iframeUrl = "".concat(SolflareMetamask.IFRAME_URL, "?cluster=").concat(network, "&origin=").concat(origin, "&title=").concat(title); | ||
var params = __assign(__assign({}, _this._iframeParams), { cluster: _this._network || 'mainnet-beta', origin: window.location.origin || '', title: document.title || '' }); | ||
var queryString = Object.keys(params) | ||
.map(function (key) { return "".concat(key, "=").concat(encodeURIComponent(params[key])); }) | ||
.join('&'); | ||
var iframeUrl = "".concat(SolflareMetamask.IFRAME_URL, "?").concat(queryString); | ||
_this._element = document.createElement('div'); | ||
@@ -278,2 +280,8 @@ _this._element.className = 'solflare-metamask-wallet-adapter-iframe'; | ||
} | ||
if (window.SolflareMetamaskParams) { | ||
_this._iframeParams = __assign(__assign({}, _this._iframeParams), window.SolflareMetamaskParams); | ||
} | ||
if (config === null || config === void 0 ? void 0 : config.params) { | ||
_this._iframeParams = __assign(__assign({}, _this._iframeParams), config === null || config === void 0 ? void 0 : config.params); | ||
} | ||
return _this; | ||
@@ -280,0 +288,0 @@ } |
import { Cluster, Transaction, VersionedTransaction } from '@solana/web3.js'; | ||
export type TransactionOrVersionedTransaction = Transaction | VersionedTransaction; | ||
export interface SolflareConfig { | ||
export interface SolflareMetamaskConfig { | ||
network?: Cluster; | ||
params?: Record<string, any>; | ||
} | ||
@@ -56,1 +57,4 @@ export interface SolflareIframeEvent { | ||
}; | ||
export interface WindowWithParams extends Window { | ||
SolflareMetamaskParams?: Record<string, any>; | ||
} |
import { PublicKey, SendOptions } from '@solana/web3.js'; | ||
import { SolflareConfig, TransactionOrVersionedTransaction } from './types'; | ||
import { SolflareMetamaskConfig, TransactionOrVersionedTransaction } from './types'; | ||
import EventEmitter from 'eventemitter3'; | ||
export default class SolflareMetamask extends EventEmitter { | ||
private _network; | ||
private _iframeParams; | ||
private _element; | ||
@@ -13,3 +14,3 @@ private _iframe; | ||
private static IFRAME_URL; | ||
constructor(config?: SolflareConfig); | ||
constructor(config?: SolflareMetamaskConfig); | ||
get publicKey(): PublicKey | null; | ||
@@ -16,0 +17,0 @@ get isConnected(): boolean; |
@@ -84,2 +84,3 @@ var __extends = (this && this.__extends) || (function () { | ||
_this._network = 'mainnet-beta'; | ||
_this._iframeParams = {}; | ||
_this._element = null; | ||
@@ -205,6 +206,7 @@ _this._iframe = null; | ||
_this._removeDanglingElements(); | ||
var network = encodeURIComponent(_this._network); | ||
var origin = encodeURIComponent(window.location.origin); | ||
var title = encodeURIComponent(document.title); | ||
var iframeUrl = "".concat(SolflareMetamask.IFRAME_URL, "?cluster=").concat(network, "&origin=").concat(origin, "&title=").concat(title); | ||
var params = __assign(__assign({}, _this._iframeParams), { cluster: _this._network || 'mainnet-beta', origin: window.location.origin || '', title: document.title || '' }); | ||
var queryString = Object.keys(params) | ||
.map(function (key) { return "".concat(key, "=").concat(encodeURIComponent(params[key])); }) | ||
.join('&'); | ||
var iframeUrl = "".concat(SolflareMetamask.IFRAME_URL, "?").concat(queryString); | ||
_this._element = document.createElement('div'); | ||
@@ -273,2 +275,8 @@ _this._element.className = 'solflare-metamask-wallet-adapter-iframe'; | ||
} | ||
if (window.SolflareMetamaskParams) { | ||
_this._iframeParams = __assign(__assign({}, _this._iframeParams), window.SolflareMetamaskParams); | ||
} | ||
if (config === null || config === void 0 ? void 0 : config.params) { | ||
_this._iframeParams = __assign(__assign({}, _this._iframeParams), config === null || config === void 0 ? void 0 : config.params); | ||
} | ||
return _this; | ||
@@ -275,0 +283,0 @@ } |
import { Cluster, Transaction, VersionedTransaction } from '@solana/web3.js'; | ||
export type TransactionOrVersionedTransaction = Transaction | VersionedTransaction; | ||
export interface SolflareConfig { | ||
export interface SolflareMetamaskConfig { | ||
network?: Cluster; | ||
params?: Record<string, any>; | ||
} | ||
@@ -56,1 +57,4 @@ export interface SolflareIframeEvent { | ||
}; | ||
export interface WindowWithParams extends Window { | ||
SolflareMetamaskParams?: Record<string, any>; | ||
} |
{ | ||
"name": "@solflare-wallet/metamask-sdk", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/solflare-wallet/solflare-metamask-sdk", |
@@ -5,3 +5,3 @@ import { Cluster, PublicKey, SendOptions } from '@solana/web3.js'; | ||
PromiseCallback, | ||
SolflareConfig, | ||
SolflareMetamaskConfig, | ||
SolflareIframeEvent, | ||
@@ -12,3 +12,4 @@ SolflareIframeMessage, | ||
SolflareIframeResizeMessage, | ||
TransactionOrVersionedTransaction | ||
TransactionOrVersionedTransaction, | ||
WindowWithParams | ||
} from './types'; | ||
@@ -22,2 +23,3 @@ import EventEmitter from 'eventemitter3'; | ||
private _network: Cluster = 'mainnet-beta'; | ||
private _iframeParams: Record<string, any> = {}; | ||
private _element: HTMLElement | null = null; | ||
@@ -32,3 +34,3 @@ private _iframe: HTMLIFrameElement | null = null; | ||
constructor(config?: SolflareConfig) { | ||
constructor(config?: SolflareMetamaskConfig) { | ||
super(); | ||
@@ -39,2 +41,16 @@ | ||
} | ||
if ((window as WindowWithParams).SolflareMetamaskParams) { | ||
this._iframeParams = { | ||
...this._iframeParams, | ||
...(window as WindowWithParams).SolflareMetamaskParams | ||
}; | ||
} | ||
if (config?.params) { | ||
this._iframeParams = { | ||
...this._iframeParams, | ||
...config?.params | ||
}; | ||
} | ||
} | ||
@@ -298,8 +314,15 @@ | ||
const network = encodeURIComponent(this._network); | ||
const origin = encodeURIComponent(window.location.origin); | ||
const title = encodeURIComponent(document.title); | ||
const params = { | ||
...this._iframeParams, | ||
cluster: this._network || 'mainnet-beta', | ||
origin: window.location.origin || '', | ||
title: document.title || '' | ||
}; | ||
const iframeUrl = `${SolflareMetamask.IFRAME_URL}?cluster=${network}&origin=${origin}&title=${title}`; | ||
const queryString = Object.keys(params) | ||
.map((key) => `${key}=${encodeURIComponent(params[key])}`) | ||
.join('&'); | ||
const iframeUrl = `${SolflareMetamask.IFRAME_URL}?${queryString}`; | ||
this._element = document.createElement('div'); | ||
@@ -306,0 +329,0 @@ this._element.className = 'solflare-metamask-wallet-adapter-iframe'; |
@@ -5,4 +5,5 @@ import { Cluster, Transaction, VersionedTransaction } from '@solana/web3.js'; | ||
export interface SolflareConfig { | ||
export interface SolflareMetamaskConfig { | ||
network?: Cluster; | ||
params?: Record<string, any>; | ||
} | ||
@@ -74,1 +75,5 @@ | ||
}; | ||
export interface WindowWithParams extends Window { | ||
SolflareMetamaskParams?: Record<string, any>; | ||
} |
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
72545
1684