Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace webbtcProviders with btc_providers #81

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/provider/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type BitcoinProvider, type WebbtcProvider } from './types';
import { type BitcoinProvider, type Provider } from './types';

export async function getProviderOrThrow(
getProvider?: () => Promise<BitcoinProvider | undefined>
Expand All @@ -13,17 +13,17 @@ export async function getProviderOrThrow(
return provider;
}

export function getProviders(): WebbtcProvider[] {
if (!window.webbtc_providers) window.webbtc_providers = [];
return window.webbtc_providers;
export function getProviders(): Provider[] {
if (!window.btc_providers) window.btc_providers = [];
return window.btc_providers;
}

export function getProviderById(providerId: string) {
if (Array.isArray(window.webbtc_providers)) {
const provider = window.webbtc_providers.find((provider) => provider.id === providerId);
if (Array.isArray(window.btc_providers)) {
const provider = window.btc_providers.find((provider) => provider.id === providerId);
return provider?.id?.split('.').reduce((acc: any, part) => acc?.[part], window);
} else {
console.log('window.webbtc_providers is not defined or not an array');
console.log('window.btc_providers is not defined or not an array');
return undefined;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/provider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface BitcoinProvider extends BaseBitcoinProvider {
getCapabilities?: (request: string) => Promise<GetCapabilitiesResponse>;
}

export interface WebbtcProvider {
export interface Provider {
id: string;
name: string;
icon: string;
Expand All @@ -50,6 +50,6 @@ declare global {
interface Window {
BitcoinProvider?: BitcoinProvider;
XverseProviders?: XverseProviders;
webbtc_providers?: WebbtcProvider[];
btc_providers?: Provider[];
}
}
Loading