|
6 | 6 | content: ''
|
7 | 7 | ---
|
8 | 8 |
|
9 |
| -# EIP-6963 |
| 9 | +# EIP-6963 Multi Injected Provider Discovery |
10 | 10 |
|
11 |
| -Decentralize injected wallet providers |
| 11 | +Using window events to announce [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193){:target="_blank"} providers instead of `window.ethereum`. |
12 | 12 |
|
| 13 | + |
| 14 | +- [EIP-6963](https://eips.ethereum.org/EIPS/eip-6963){:target="_blank"} |
| 15 | + |
| 16 | + |
| 17 | +## Provider details |
| 18 | + |
| 19 | + |
| 20 | +::Eip6963 |
| 21 | +:: |
| 22 | + |
| 23 | + |
| 24 | +## Source code |
| 25 | + |
| 26 | +```ts [setup script] |
| 27 | +import { useVueDapp, shortenAddress, type ConnectorName, RDNS } from '@vue-dapp/core' |
| 28 | +import { useVueDappModal } from '@vue-dapp/modal' |
| 29 | + |
| 30 | +const { providerDetails, wallet, address, status, connectTo, disconnect, error, isConnected } = useVueDapp() |
| 31 | + |
| 32 | +const providerList = computed(() => { |
| 33 | + return providerDetails.value.slice().sort((a, b) => { |
| 34 | + if (a.info.rdns === RDNS.rabby) return -1 |
| 35 | + if (b.info.rdns === RDNS.rabby) return 1 |
| 36 | + if (a.info.rdns === RDNS.metamask) return -1 |
| 37 | + if (b.info.rdns === RDNS.metamask) return 1 |
| 38 | + return 0 |
| 39 | + }) |
| 40 | +}) |
| 41 | + |
| 42 | +async function onClickWallet(connName: ConnectorName, rdns?: RDNS | string) { |
| 43 | + useVueDappModal().close() |
| 44 | + await connectTo(connName, { rdns }) |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +```vue [template] |
| 49 | +<template> |
| 50 | + <div class="flex flex-col gap-2"> |
| 51 | + <div class="flex flex-wrap gap-2"> |
| 52 | + <n-button |
| 53 | + v-for="detail in providerList" |
| 54 | + :key="detail.info.uuid" |
| 55 | + @click="onClickWallet('BrowserWallet', detail.info.rdns)" |
| 56 | + size="medium" |
| 57 | + :disabled="status === 'connecting' || wallet.providerInfo?.rdns === detail.info.rdns" |
| 58 | + > |
| 59 | + <div>{{ detail.info.name }}</div> |
| 60 | + </n-button> |
| 61 | + <p v-if="!providerList.length">No provider was found in this browser.</p> |
| 62 | + </div> |
| 63 | +
|
| 64 | + <div |
| 65 | + :class="{ |
| 66 | + 'h-[200px]': status !== 'idle', |
| 67 | + }" |
| 68 | + > |
| 69 | + <div class="flex flex-col gap-1"> |
| 70 | + <div v-if="status === 'connecting'">Connecting...</div> |
| 71 | + <div v-if="isConnected" class="flex flex-col gap-1"> |
| 72 | + <div>uuid: {{ wallet.providerInfo?.uuid }}</div> |
| 73 | + <div>name: {{ wallet.providerInfo?.name }}</div> |
| 74 | +
|
| 75 | + <div class="flex items-center gap-2"> |
| 76 | + <span class="">icon:</span> |
| 77 | + <img |
| 78 | + class="w-5 h-5 m-0 p-0" |
| 79 | + :src="wallet.providerInfo?.icon" |
| 80 | + :alt="wallet.providerInfo?.name" |
| 81 | + /> |
| 82 | + </div> |
| 83 | + <div>rdns: {{ wallet.providerInfo?.rdns }}</div> |
| 84 | +
|
| 85 | + <div class="mt-5 flex items-center gap-2"> |
| 86 | + <n-button @click="disconnect">Disconnect</n-button> |
| 87 | + <div>{{ shortenAddress(address || '') }}</div> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | +
|
| 92 | + <p class="text-red-500">{{ error }}</p> |
| 93 | + </div> |
| 94 | + </div> |
| 95 | +</template> |
| 96 | +``` |
0 commit comments