Skip to content

Commit

Permalink
feat: browser native web3 wallet support (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Oct 28, 2024
1 parent 0a032a8 commit 031c4c6
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/context/Web3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ declare global {
interface Navigator {
hid: {};
}

interface Window {
ethereum?: any;
}
}

type EIP6963AnnounceProviderEvent = {
Expand All @@ -46,6 +50,8 @@ enum HardwareRdns {
Trezor = "trezor",
}

const browserRdns = "browser";

const customDerivationPathRdns: string[] = [
HardwareRdns.Ledger,
HardwareRdns.Trezor,
Expand Down Expand Up @@ -78,7 +84,16 @@ const Web3SignerProvider = (props: {
const [providers, setProviders] = createSignal<
Record<string, EIP6963ProviderDetail>
>({
ledger: {
[browserRdns]: {
provider: window.ethereum,
info: {
name: "Browser native",
uuid: browserRdns,
rdns: browserRdns,
disabled: window.ethereum === undefined,
},
},
[HardwareRdns.Ledger]: {
provider: new LedgerSigner(t),
info: {
name: "Ledger",
Expand All @@ -89,7 +104,7 @@ const Web3SignerProvider = (props: {
disabled: navigator.hid === undefined,
},
},
trezor: {
[HardwareRdns.Trezor]: {
provider: new TrezorSigner(),
info: {
name: "Trezor",
Expand All @@ -111,8 +126,13 @@ const Web3SignerProvider = (props: {
log.debug(
`Found EIP-6963 wallet: ${event.detail.info.rdns}: ${event.detail.info.name}`,
);
const existingProviders = { ...providers() };

// We should not show the browser provider when an EIP-6963 provider is found
delete existingProviders[browserRdns];

setProviders({
...providers(),
...existingProviders,
[event.detail.info.rdns]: event.detail,
});
},
Expand Down

0 comments on commit 031c4c6

Please sign in to comment.