Skip to content

Commit

Permalink
refactor ui config to use adapter info
Browse files Browse the repository at this point in the history
  • Loading branch information
m-aboelenein committed Mar 28, 2024
1 parent aede59f commit 993cfae
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const DefaultAdaptersInfo: Record<string, Provider> = {
id: 'XverseProviders.BitcoinProvider',
name: 'Xverse',
webUrl: 'https://www.xverse.app/',
googlePlayStoreUrl: 'https://play.google.com/store/apps/details?id=com.secretkeylabs.xverse',
iOSAppStoreUrl: 'https://apps.apple.com/app/xverse-bitcoin-web3-wallet/id1552272513',
chromeWebStoreUrl:
'https://chromewebstore.google.com/detail/xverse-wallet/idnnbdplmphpflfnlkomgpfbpcgelopg',
icon: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgdmlld0JveD0iMCAwIDEwMiAxMDIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGlkPSJJY29uX0FydCAoRWRpdCBNZSkiPgo8cmVjdCB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgZmlsbD0iIzE4MTgxOCIvPgo8ZyBpZD0iTG9nby9FbWJsZW0iIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8yMF8xMjIzKSI+CjxwYXRoIGlkPSJWZWN0b3IiIGQ9Ik03NC42NTQyIDczLjg4ODNWNjUuMjMxMkM3NC42NTQyIDY0Ljg4OCA3NC41MTc3IDY0LjU2MDYgNzQuMjc0NSA2NC4zMTc0TDM3LjQzOTcgMjcuNDgyNUMzNy4xOTY1IDI3LjIzOTIgMzYuODY5MSAyNy4xMDI4IDM2LjUyNTggMjcuMTAyOEgyNy44NjlDMjcuNDQxNiAyNy4xMDI4IDI3LjA5MzggMjcuNDUwNiAyNy4wOTM4IDI3Ljg3O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iAyNy40ODkyIDc0LjUzMzQgMjcuMTM5MSA3NC4xMDE3IDI3LjEzOTFMNjUuMjUzOCAyNy4xMjc3QzY1LjA0NyAyNy4xMjc3IDY0Ljg0OTIgMjcuMjA5NiA2NC43MDE0IDI3LjM1NTFMNTQuODA1NiAzNy4yMzVDNTQuMzE0NSAzNy43MjYgNTQuNjYyMyAzOC41NjcyIDU1LjM1NTcgMzguNTY3Mkg1NS4zNThaIiBmaWxsPSIjRUU3QTMwIi8+CjwvZz4KPC9nPgo8ZGVmcz4KPGNsaXBQYXRoIGlkPSJjbGlwMF8yMF8xMjIzIj4KPHJlY3Qgd2lkdGg9IjQ3LjgxMjUiIGhlaWdodD0iNDcuODEyNSIgZmlsbD0id2hpdGUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDI3LjA5MzggMjcuMDkzOCkiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K',
Expand Down
3 changes: 2 additions & 1 deletion src/adapters/unisat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SatsConnectAdapter } from './satsConnectAdapter';
import { RpcErrorCode, RpcResult } from '../types';
import { AddressType, getAddressInfo } from 'bitcoin-address-validation';
import { Address, AddressPurpose } from '../addresses';
import { DefaultAdaptersInfo } from '.';

type InputType = {
index: number;
Expand Down Expand Up @@ -66,7 +67,7 @@ function convertSignInputsToInputType(
}

class UnisatAdapter extends SatsConnectAdapter {
id = 'unisat';
id = DefaultAdaptersInfo.unisat.id;

private async getAccounts(params: GetAccountsParams): Promise<Return<'getAccounts'>> {
const { purposes } = params;
Expand Down
3 changes: 2 additions & 1 deletion src/adapters/xverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { Params, Requests } from '../request';
import { SatsConnectAdapter } from './satsConnectAdapter';
import { request } from '../request';
import { RpcResult } from '../types';
import { DefaultAdaptersInfo } from '.';

class XverseAdapter extends SatsConnectAdapter {
id = 'XverseProviders.BitcoinProvider';
id = DefaultAdaptersInfo.xverse.id;

request = async <Method extends keyof Requests>(
method: Method,
Expand Down
20 changes: 5 additions & 15 deletions src/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
import { SupportedWallet } from 'src/provider';
import { DefaultAdaptersInfo } from '../adapters';
import { SupportedWallet } from '../provider';

export interface Config {
providers: SupportedWallet[];
}

export const xverseIcon =
'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgdmlld0JveD0iMCAwIDEwMiAxMDIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxnIGlkPSJJY29uX0FydCAoRWRpdCBNZSkiPgo8cmVjdCB3aWR0aD0iMTAyIiBoZWlnaHQ9IjEwMiIgZmlsbD0iIzE4MTgxOCIvPgo8ZyBpZD0iTG9nby9FbWJsZW0iIGNsaXAtcGF0aD0idXJsKCNjbGlwMF8yMF8xMjIzKSI+CjxwYXRoIGlkPSJWZWN0b3IiIGQ9Ik03NC42NTQyIDczLjg4ODNWNjUuMjMxMkM3NC42NTQyIDY0Ljg4OCA3NC41MTc3IDY0LjU2MDYgNzQuMjc0NSA2NC4zMTc0TDM3LjQzOTcgMjcuNDgyNUMzNy4xOTY1IDI3LjIzOTIgMzYuODY5MSAyNy4xMDI4IDM2LjUyNTggMjcuMTAyOEgyNy44NjlDMjcuNDQxNiAyNy4xMDI4IDI3LjA5MzggMjcuNDUwNiAyNy4wOTM4IDI3Ljg3OFYzNS45MjExQzI3LjA5MzggMzYuMjY0NCAyNy4yMzAyIDM2LjU5MTcgMjcuNDczNCAzNi44MzVMNDAuNjk1MiA1MC4wNTY3QzQwLjk5NzUgNTAuMzU5MSA0MC45OTc1IDUwLjg1MDEgNDAuNjk1MiA1MS4xNTI0TDI3LjMyMTEgNjQuNTI2NUMyNy4xNzU2IDY0LjY3MiAyNy4wOTM4IDY0Ljg2OTggMjcuMDkzOCA2NS4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xsPSIjRUU3QTMwIi8+CjwvZz4KPC9nPgo8ZGVmcz4KPGNsaXBQYXRoIGlkPSJjbGlwMF8yMF8xMjIzIj4KPHJlY3Qgd2lkdGg9IjQ3LjgxMjUiIGhlaWdodD0iNDcuODEyNSIgZmlsbD0id2hpdGUiIHRyYW5zZm9ybT0idHJhbnNsYXRlKDI3LjA5MzggMjcuMDkzOCkiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4K';

export function createDefaultConfig(providers: SupportedWallet[]): Config {
const config: Config = { providers: [] };
// Xverse
const xverseProvider = providers.find(
(provider) => provider.id === 'XverseProviders.BitcoinProvider'
(provider) => provider.id === DefaultAdaptersInfo.xverse.id
);
config.providers.push(
xverseProvider
? xverseProvider
: {
id: 'XverseProviders.BitcoinProvider',
name: 'Xverse',
icon: xverseIcon,
...DefaultAdaptersInfo.xverse,
isInstalled: false,
chromeWebStoreUrl:
'https://chromewebstore.google.com/detail/xverse-wallet/idnnbdplmphpflfnlkomgpfbpcgelopg',
googlePlayStoreUrl:
'https://play.google.com/store/apps/details?id=com.secretkeylabs.xverse',
iOSAppStoreUrl: 'https://apps.apple.com/app/xverse-bitcoin-web3-wallet/id1552272513',
webUrl: 'https://www.xverse.app/',
}
);

Expand All @@ -39,7 +29,7 @@ export function createDefaultConfig(providers: SupportedWallet[]): Config {
// Rest
config.providers.concat(
providers.filter((provider) => {
return provider.id !== 'xverseProviders.bitcoinProvider' && provider.id !== 'unisat';
return provider.id !== DefaultAdaptersInfo.xverse.id && provider.id !== 'unisat';
})
);

Expand Down

0 comments on commit 993cfae

Please sign in to comment.