Skip to content

Commit

Permalink
refactor: improve class
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e committed Jan 26, 2025
1 parent 7f28479 commit 62491d8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 123 deletions.
14 changes: 7 additions & 7 deletions apps/ui/src/composables/useConnectors.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import connectorsClass from '@/helpers/connectors/index';
import { APP_NAME } from '@/helpers/constants';
import { InjectedWalletProvider } from '@/helpers/injectedWalletProvider';
import Eip6963 from '@/helpers/eip6963';
import { Connector, ConnectorType } from '@/networks/types';

type ConnectorDetail = Partial<
Pick<Connector, 'id' | 'info' | 'options' | 'provider'> & { hidden?: boolean }
>;

const injectedWalletProvider = new InjectedWalletProvider();
const eip6963 = new Eip6963();

injectedWalletProvider.subscribe();
injectedWalletProvider.requestProviders();
eip6963.subscribe();
eip6963.requestProviders();

const injectedProviders = ref(injectedWalletProvider.providerDetails);
const injectedProviders = ref(eip6963.providerDetails);

const CONNECTOR_DETAILS: Record<ConnectorType, ConnectorDetail> = {
injected: {},
Expand Down Expand Up @@ -57,9 +57,9 @@ const CONNECTOR_DETAILS: Record<ConnectorType, ConnectorDetail> = {
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA0NpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDkuMS1jMDAyIDc5LmI3YzY0Y2NmOSwgMjAyNC8wNy8xNi0xMjozOTowNCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy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Ww9/nSR37pozKLEy0/UzAXsBL5Wflt4+QhSmb2dIOIogbwjdhBEn3lJTLshu4McwAkIKvdy8nv/wpz/if8/UFhG3kFGhbzczXhGbZ+hXDfSNjEew7PF1wW6yeld5AIl/BUfK3V8SUiLj63fYjIX0X27OxXXbA4kVMW0jZM5PFZ8T7EF4h4G3X9t6qqjBW5fVGF0QHwtyKVe4CEGEvJ+CWMbwkHq4m5Hybi4xhwzud5S9Hwl5bOPU3hwOiiaJI+ZlVVTzpPf0Zrfm5zNa/9q6Lo4t3DyUXCyBBWER9PCze8Pr1OunVv4hqv4Ip74mvzNEzi89nTeYNB+XqcC2/gohuMV9ZxIS9N4nE674yE8VG02FcrkcG80cROq9ikbeW4Azwe5bMbYXw9XjOYuvT/AgwARpcUpIPamJIAAAAASUVORK5CYII='
},
options: {
dappName: 'Snapshot',
dappName: APP_NAME,
argentMobileOptions: {
dappName: 'Snapshot',
dappName: APP_NAME,
url: 'https://snapshot.box',
icons: ['https://snapshot.box/favicon.svg']
}
Expand Down
64 changes: 64 additions & 0 deletions apps/ui/src/helpers/eip6963.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import EventEmitter from 'events';

declare global {
interface WindowEventMap {
'eip6963:announceProvider': EIP6963AnnounceProviderEvent;
}
}

class EIP6963RequestProviderEvent extends Event {
constructor() {
super('eip6963:requestProvider');
}
}

interface EIP6963AnnounceProviderEvent extends Event {
type: 'eip6963:announceProvider';
detail: EIP6963ProviderDetail;
}

interface EIP6963ProviderDetail {
info: EIP6963ProviderInfo;
provider: EIP1193Provider;
}

interface EIP6963ProviderInfo {
uuid: string;
name: string;
icon: string;
rdns: string;
}

interface EIP1193Provider {
request(request: {
method: string;
params?: Array<any> | Record<string, any>;
}): Promise<any>;
}

export default class Eip6963 extends EventEmitter {
providerDetails: EIP6963ProviderDetail[];

constructor() {
super();
this.providerDetails = [];
}

private providerReceived(providerDetail: EIP6963ProviderDetail): void {
this.providerDetails.push(providerDetail);
}

subscribe(): void {
window.addEventListener(
'eip6963:announceProvider',
(event: EIP6963AnnounceProviderEvent) => {
this.providerReceived(event.detail);
}
);
}

requestProviders(): void {
this.providerDetails = [];
window.dispatchEvent(new EIP6963RequestProviderEvent());
}
}
116 changes: 0 additions & 116 deletions apps/ui/src/helpers/injectedWalletProvider.ts

This file was deleted.

0 comments on commit 62491d8

Please sign in to comment.