diff --git a/src/adapters/BaseAdapter.ts b/src/adapters/BaseAdapter.ts index 7232ddc..2b358c4 100644 --- a/src/adapters/BaseAdapter.ts +++ b/src/adapters/BaseAdapter.ts @@ -6,27 +6,16 @@ import { Provider, getProviderById } from '../provider'; class BaseAdapter extends SatsConnectAdapter { id = ''; - name = ''; - url = ''; - supportedMethods: (keyof StxRequests | keyof BtcRequests)[] = []; - - constructor(providerInfo: Provider) { + constructor(providerId: string) { super(); - this.id = providerInfo.id; - this.name = providerInfo.name; - this.url = providerInfo.webUrl || ''; - this.supportedMethods = providerInfo.methods || []; + this.id = providerId; } request = async ( method: Method, params: Params ): Promise | undefined> => { - if (!this.supportedMethods.includes(method)) { - console.error('Method not supported by the selected wallet'); - } - return request(method, params, this.id); }; } diff --git a/src/adapters/index.ts b/src/adapters/index.ts index 5cc129d..fd2b342 100644 --- a/src/adapters/index.ts +++ b/src/adapters/index.ts @@ -25,5 +25,5 @@ export const defaultAdapters: Record SatsConnectAdapter> = { [DefaultAdaptersInfo.unisat.id]: UnisatAdapter, }; -export * from './persistence'; export * from './satsConnectAdapter'; +export * from './baseAdapter'; diff --git a/src/adapters/persistence.ts b/src/adapters/persistence.ts deleted file mode 100644 index 92956e8..0000000 --- a/src/adapters/persistence.ts +++ /dev/null @@ -1,11 +0,0 @@ -export function setDefaultProvider(providerId: string) { - localStorage.setItem('sats-connect_defaultProvider', providerId); -} - -export function getDefaultProvider() { - return localStorage.getItem('sats-connect_defaultProvider'); -} - -export function removeDefaultProvider() { - localStorage.removeItem('sats-connect_defaultProvider'); -} diff --git a/src/adapters/satsConnectAdapter.ts b/src/adapters/satsConnectAdapter.ts index d87b698..c7b6c3b 100644 --- a/src/adapters/satsConnectAdapter.ts +++ b/src/adapters/satsConnectAdapter.ts @@ -3,10 +3,6 @@ import { RpcResult } from '../types'; abstract class SatsConnectAdapter { abstract readonly id: string; - abstract readonly name: string; - abstract url: string; - - supportedMethods: (StxRequestMethod | BtcRequestMethod)[] = []; abstract request( method: Method, diff --git a/src/adapters/unisat.ts b/src/adapters/unisat.ts index 0d9c54d..1de3a11 100644 --- a/src/adapters/unisat.ts +++ b/src/adapters/unisat.ts @@ -46,22 +46,12 @@ declare global { class UnisatAdapter extends SatsConnectAdapter { id = 'unisat'; - name = 'Unisat'; - url = 'https://unisat.io/'; - - supportedMethods: (keyof StxRequests | keyof BtcRequests)[] = [ - 'getAccounts', - 'sendTransfer', - 'signMessage', - 'signPsbt', - ]; private async getAccounts(): Promise> { const [accounts, publickKey] = await Promise.all([ window.unisat.requestAccounts(), window.unisat.getPublicKey(), ]); - // to-do: create a generic purpose type for the response const response: Return<'getAccounts'> = accounts.map((address) => ({ address, publicKey: publickKey, @@ -108,11 +98,6 @@ class UnisatAdapter extends SatsConnectAdapter { address, index: indexes[0], sighashTypes: allowedSignHash ? [allowedSignHash] : undefined, - /** - * to-do: get the public key from the address - */ - // disableTweakSigner: true, - // publicKey: '', })), }); if (broadcast) { @@ -131,9 +116,6 @@ class UnisatAdapter extends SatsConnectAdapter { method: Method, params: Params ): Promise | undefined> => { - if (!this.supportedMethods.includes(method)) { - console.error('Method not supported by the selected wallet'); - } try { switch (method) { case 'getAccounts': { diff --git a/src/adapters/xverse.ts b/src/adapters/xverse.ts index 4f6519d..6b9bf36 100644 --- a/src/adapters/xverse.ts +++ b/src/adapters/xverse.ts @@ -5,24 +5,11 @@ import { RpcResult } from '../types'; class XverseAdapter extends SatsConnectAdapter { id = 'XverseProviders.BitcoinProvider'; - name = 'Xverse'; - url = 'xverse.app'; - - supportedMethods: (keyof StxRequests | keyof BtcRequests)[] = [ - 'getAccounts', - 'sendTransfer', - 'signMessage', - 'signPsbt', - ]; request = async ( method: Method, params: Params ): Promise | undefined> => { - if (!this.supportedMethods.includes(method)) { - console.error('Method not supported by the selected wallet'); - } - return request(method, params, this.id); }; } diff --git a/src/provider/index.ts b/src/provider/index.ts index 444414a..9069d6f 100644 --- a/src/provider/index.ts +++ b/src/provider/index.ts @@ -27,6 +27,18 @@ export function isProviderInstalled(providerId: string) { return !!getProviderById(providerId); } +export function setDefaultProvider(providerId: string) { + localStorage.setItem('sats-connect_defaultProvider', providerId); +} + +export function getDefaultProvider() { + return localStorage.getItem('sats-connect_defaultProvider'); +} + +export function removeDefaultProvider() { + localStorage.removeItem('sats-connect_defaultProvider'); +} + export function getSupportedWallets(): SupportedWallet[] { const btc_providers = getProviders(); for (let key in DefaultAdaptersInfo) {