@1001-digital/components.evm 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -4
- package/src/client-only.ts +14 -0
- package/src/components/EvmAccount.vue +2 -4
- package/src/components/EvmAvatar.vue +4 -8
- package/src/components/EvmConnect.vue +2 -4
- package/src/components/EvmConnectDialog.vue +3 -7
- package/src/components/EvmConnectorQR.vue +2 -3
- package/src/components/EvmInAppWalletSetup.vue +3 -7
- package/src/components/EvmMetaMaskQR.vue +3 -6
- package/src/components/EvmProfile.vue +6 -10
- package/src/components/EvmSeedPhraseInput.vue +3 -9
- package/src/components/EvmSiwe.vue +4 -15
- package/src/components/EvmSiweDialog.vue +3 -16
- package/src/components/EvmSwitchNetwork.vue +3 -7
- package/src/components/EvmTransactionFlow.vue +5 -22
- package/src/components/EvmWalletConnectQR.vue +2 -3
- package/src/components/EvmWalletConnectWallets.vue +3 -6
- package/src/composables/uri.ts +37 -8
- package/src/index.ts +35 -3
- package/src/types.ts +148 -0
- package/src/utils/uri.ts +0 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1001-digital/components.evm",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"*.css"
|
|
@@ -13,13 +13,15 @@
|
|
|
13
13
|
"src"
|
|
14
14
|
],
|
|
15
15
|
"peerDependencies": {
|
|
16
|
+
"@vueuse/core": ">=14.0.0",
|
|
16
17
|
"@wagmi/core": ">=3.0.0",
|
|
17
18
|
"@wagmi/vue": ">=0.5.0",
|
|
18
19
|
"viem": ">=2.0.0",
|
|
19
20
|
"vue": "^3.5.0",
|
|
20
|
-
"@1001-digital/components": "^1.
|
|
21
|
+
"@1001-digital/components": "^1.5.0"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
24
|
+
"@1001-digital/dweb-fetch": "^0.1.5",
|
|
23
25
|
"@1001-digital/wagmi-in-app-wallet": "^0.1.0",
|
|
24
26
|
"@types/qrcode": "^1.5.6",
|
|
25
27
|
"qrcode": "^1.5.4"
|
|
@@ -27,7 +29,7 @@
|
|
|
27
29
|
"devDependencies": {
|
|
28
30
|
"@wagmi/core": "^3.4.0",
|
|
29
31
|
"@wagmi/vue": "^0.5.0",
|
|
30
|
-
"viem": "^2.
|
|
31
|
-
"vue": "^3.5.
|
|
32
|
+
"viem": "^2.47.1",
|
|
33
|
+
"vue": "^3.5.30"
|
|
32
34
|
}
|
|
33
35
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Components that require browser APIs and must be rendered client-only
|
|
2
|
+
export const clientOnlyComponents = [
|
|
3
|
+
'EvmAccount',
|
|
4
|
+
'EvmConnect',
|
|
5
|
+
'EvmConnectDialog',
|
|
6
|
+
'EvmConnectionStatus',
|
|
7
|
+
'EvmConnectorQR',
|
|
8
|
+
'EvmMetaMaskQR',
|
|
9
|
+
'EvmInAppWalletSetup',
|
|
10
|
+
'EvmTransactionFlow',
|
|
11
|
+
'EvmWalletConnectQR',
|
|
12
|
+
'EvmSiwe',
|
|
13
|
+
'EvmSiweDialog',
|
|
14
|
+
]
|
|
@@ -9,13 +9,11 @@
|
|
|
9
9
|
|
|
10
10
|
<script setup lang="ts">
|
|
11
11
|
import { computed } from 'vue'
|
|
12
|
-
import type { Address } from 'viem'
|
|
13
12
|
import { useConnection } from '@wagmi/vue'
|
|
14
13
|
import { shortAddress } from '../utils/addresses'
|
|
14
|
+
import type { EvmAccountProps } from '../types'
|
|
15
15
|
|
|
16
|
-
const props = defineProps<
|
|
17
|
-
address?: Address
|
|
18
|
-
}>()
|
|
16
|
+
const props = defineProps<EvmAccountProps>()
|
|
19
17
|
const address = computed(() => props.address)
|
|
20
18
|
|
|
21
19
|
const { address: currentAddress } = useConnection()
|
|
@@ -21,16 +21,13 @@
|
|
|
21
21
|
|
|
22
22
|
<script setup lang="ts">
|
|
23
23
|
import { computed } from 'vue'
|
|
24
|
-
import type { Address } from 'viem'
|
|
25
24
|
import { useConnection } from '@wagmi/vue'
|
|
26
25
|
import { useEnsWithAvatar } from '../composables/ens'
|
|
27
|
-
import {
|
|
26
|
+
import { useResolvedUrl } from '../composables/uri'
|
|
28
27
|
import { Opepicon } from '@1001-digital/components'
|
|
28
|
+
import type { EvmAvatarProps } from '../types'
|
|
29
29
|
|
|
30
|
-
const props = defineProps<
|
|
31
|
-
address?: Address
|
|
32
|
-
large?: boolean
|
|
33
|
-
}>()
|
|
30
|
+
const props = defineProps<EvmAvatarProps>()
|
|
34
31
|
const address = computed(() => props.address)
|
|
35
32
|
|
|
36
33
|
const { address: currentAddress } = useConnection()
|
|
@@ -40,10 +37,9 @@ const isCurrent = computed<boolean>(
|
|
|
40
37
|
)
|
|
41
38
|
|
|
42
39
|
const { data: ensData } = useEnsWithAvatar(address)
|
|
43
|
-
const resolve = useResolveUri()
|
|
44
40
|
|
|
45
41
|
const ens = computed(() => ensData.value?.ens || null)
|
|
46
|
-
const src =
|
|
42
|
+
const src = useResolvedUrl(() => ensData.value?.data?.avatar)
|
|
47
43
|
</script>
|
|
48
44
|
|
|
49
45
|
<style scoped>
|
|
@@ -97,6 +97,7 @@ import { Button, Icon, Alert, Loading } from '@1001-digital/components'
|
|
|
97
97
|
import EvmMetaMaskQR from './EvmMetaMaskQR.vue'
|
|
98
98
|
import EvmWalletConnectWallets from './EvmWalletConnectWallets.vue'
|
|
99
99
|
import EvmInAppWalletSetup from './EvmInAppWalletSetup.vue'
|
|
100
|
+
import type { EvmConnectEmits } from '../types'
|
|
100
101
|
|
|
101
102
|
import coinbaseIcon from '../assets/wallets/coinbase.svg'
|
|
102
103
|
import metamaskIcon from '../assets/wallets/metamask.svg'
|
|
@@ -123,10 +124,7 @@ const PRIORITY: Record<string, number> = {
|
|
|
123
124
|
'Base Account': 10,
|
|
124
125
|
}
|
|
125
126
|
|
|
126
|
-
const emit = defineEmits<
|
|
127
|
-
connecting: []
|
|
128
|
-
connected: []
|
|
129
|
-
}>()
|
|
127
|
+
const emit = defineEmits<EvmConnectEmits>()
|
|
130
128
|
|
|
131
129
|
const chainId = useChainId()
|
|
132
130
|
const connectors = useConnectors()
|
|
@@ -33,15 +33,11 @@ import { useConnection } from '@wagmi/vue'
|
|
|
33
33
|
import { Button, Dialog } from '@1001-digital/components'
|
|
34
34
|
import EvmAccount from './EvmAccount.vue'
|
|
35
35
|
import EvmConnect from './EvmConnect.vue'
|
|
36
|
+
import type { EvmConnectDialogProps, EvmConnectDialogEmits } from '../types'
|
|
36
37
|
|
|
37
|
-
defineProps<
|
|
38
|
-
className?: string
|
|
39
|
-
}>()
|
|
38
|
+
defineProps<EvmConnectDialogProps>()
|
|
40
39
|
|
|
41
|
-
const emit = defineEmits<
|
|
42
|
-
connected: [{ address: `0x${string}` | undefined }]
|
|
43
|
-
disconnected: []
|
|
44
|
-
}>()
|
|
40
|
+
const emit = defineEmits<EvmConnectDialogEmits>()
|
|
45
41
|
|
|
46
42
|
const { address, isConnected } = useConnection()
|
|
47
43
|
|
|
@@ -21,10 +21,9 @@ import { ref, watch, onMounted } from 'vue'
|
|
|
21
21
|
import QRCode from 'qrcode'
|
|
22
22
|
import { useClipboard } from '@vueuse/core'
|
|
23
23
|
import { Button, Icon } from '@1001-digital/components'
|
|
24
|
+
import type { EvmConnectorQRProps } from '../types'
|
|
24
25
|
|
|
25
|
-
const props = defineProps<
|
|
26
|
-
uri: string
|
|
27
|
-
}>()
|
|
26
|
+
const props = defineProps<EvmConnectorQRProps>()
|
|
28
27
|
|
|
29
28
|
const qrCanvas = ref<HTMLCanvasElement | null>(null)
|
|
30
29
|
const { copy, copied: isCopied } = useClipboard()
|
|
@@ -127,20 +127,16 @@ import { useConnect, useConnectors } from '@wagmi/vue'
|
|
|
127
127
|
import { Button, Icon, Alert, FormCheckbox, Loading } from '@1001-digital/components'
|
|
128
128
|
import EvmSeedPhraseInput from './EvmSeedPhraseInput.vue'
|
|
129
129
|
import { prepareInAppWallet } from '../connectors/inAppWallet'
|
|
130
|
+
import type { EvmInAppWalletSetupProps, EvmInAppWalletSetupEmits } from '../types'
|
|
130
131
|
|
|
131
132
|
const props = withDefaults(
|
|
132
|
-
defineProps<
|
|
133
|
-
note?: string
|
|
134
|
-
}>(),
|
|
133
|
+
defineProps<EvmInAppWalletSetupProps>(),
|
|
135
134
|
{
|
|
136
135
|
note: 'Create a browser-based wallet stored locally on this device. Only you have access to your keys.',
|
|
137
136
|
},
|
|
138
137
|
)
|
|
139
138
|
|
|
140
|
-
const emit = defineEmits<
|
|
141
|
-
connected: []
|
|
142
|
-
back: []
|
|
143
|
-
}>()
|
|
139
|
+
const emit = defineEmits<EvmInAppWalletSetupEmits>()
|
|
144
140
|
|
|
145
141
|
const connectors = useConnectors()
|
|
146
142
|
const { mutateAsync: connectAsync } = useConnect()
|
|
@@ -16,14 +16,11 @@
|
|
|
16
16
|
<script setup lang="ts">
|
|
17
17
|
import EvmConnectorQR from './EvmConnectorQR.vue'
|
|
18
18
|
import { Button, Icon } from '@1001-digital/components'
|
|
19
|
+
import type { EvmMetaMaskQRProps, EvmMetaMaskQREmits } from '../types'
|
|
19
20
|
|
|
20
|
-
defineProps<
|
|
21
|
-
uri: string
|
|
22
|
-
}>()
|
|
21
|
+
defineProps<EvmMetaMaskQRProps>()
|
|
23
22
|
|
|
24
|
-
defineEmits<
|
|
25
|
-
back: []
|
|
26
|
-
}>()
|
|
23
|
+
defineEmits<EvmMetaMaskQREmits>()
|
|
27
24
|
</script>
|
|
28
25
|
|
|
29
26
|
<style scoped>
|
|
@@ -81,18 +81,15 @@ import { useConnection, useDisconnect } from '@wagmi/vue'
|
|
|
81
81
|
import { useClipboard } from '@vueuse/core'
|
|
82
82
|
import { useConfirm, Button, Dialog, Icon } from '@1001-digital/components'
|
|
83
83
|
import { useEnsProfile } from '../composables/ens'
|
|
84
|
-
import {
|
|
84
|
+
import { useResolvedUrl } from '../composables/uri'
|
|
85
85
|
import { shortAddress } from '../utils/addresses'
|
|
86
86
|
import EvmAvatar from './EvmAvatar.vue'
|
|
87
87
|
import EvmSwitchNetwork from './EvmSwitchNetwork.vue'
|
|
88
|
+
import type { EvmProfileProps, EvmProfileEmits } from '../types'
|
|
88
89
|
|
|
89
|
-
defineProps<
|
|
90
|
-
className?: string
|
|
91
|
-
}>()
|
|
90
|
+
defineProps<EvmProfileProps>()
|
|
92
91
|
|
|
93
|
-
const emit = defineEmits<
|
|
94
|
-
disconnected: []
|
|
95
|
-
}>()
|
|
92
|
+
const emit = defineEmits<EvmProfileEmits>()
|
|
96
93
|
|
|
97
94
|
const { address } = useConnection()
|
|
98
95
|
const { mutate: disconnectWallet } = useDisconnect()
|
|
@@ -100,11 +97,10 @@ const { confirm } = useConfirm()
|
|
|
100
97
|
const { data: ensData } = useEnsProfile(address)
|
|
101
98
|
|
|
102
99
|
const { copy, copied } = useClipboard()
|
|
103
|
-
const resolve = useResolveUri()
|
|
104
100
|
|
|
105
101
|
const ensName = computed(() => ensData.value?.ens || null)
|
|
106
|
-
const ensAvatar =
|
|
107
|
-
const ensHeader =
|
|
102
|
+
const ensAvatar = useResolvedUrl(() => ensData.value?.data?.avatar)
|
|
103
|
+
const ensHeader = useResolvedUrl(() => ensData.value?.data?.header)
|
|
108
104
|
|
|
109
105
|
const shortAddr = computed(() =>
|
|
110
106
|
address.value ? shortAddress(address.value) : '',
|
|
@@ -33,17 +33,11 @@
|
|
|
33
33
|
<script setup lang="ts">
|
|
34
34
|
import { ref, watch, computed, onMounted } from 'vue'
|
|
35
35
|
import { english } from 'viem/accounts'
|
|
36
|
+
import type { EvmSeedPhraseInputProps, EvmSeedPhraseInputEmits } from '../types'
|
|
36
37
|
|
|
37
|
-
const props = defineProps<
|
|
38
|
-
modelValue?: string
|
|
39
|
-
disabled?: boolean
|
|
40
|
-
}>()
|
|
38
|
+
const props = defineProps<EvmSeedPhraseInputProps>()
|
|
41
39
|
|
|
42
|
-
const emit = defineEmits<
|
|
43
|
-
'update:modelValue': [value: string]
|
|
44
|
-
valid: [isValid: boolean]
|
|
45
|
-
submit: []
|
|
46
|
-
}>()
|
|
40
|
+
const emit = defineEmits<EvmSeedPhraseInputEmits>()
|
|
47
41
|
|
|
48
42
|
const wordSet = new Set(english)
|
|
49
43
|
|
|
@@ -51,24 +51,13 @@ import type { Config } from '@wagmi/vue'
|
|
|
51
51
|
import { Button, Alert, Loading } from '@1001-digital/components'
|
|
52
52
|
import { createSiweMessage } from '../utils/siwe'
|
|
53
53
|
import { useSiwe } from '../composables/siwe'
|
|
54
|
+
import type { EvmSiweProps, EvmSiweEmits } from '../types'
|
|
54
55
|
|
|
55
56
|
type Step = 'idle' | 'signing' | 'verifying' | 'complete' | 'error'
|
|
56
57
|
|
|
57
|
-
const props = defineProps<
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
domain?: string
|
|
61
|
-
statement?: string
|
|
62
|
-
uri?: string
|
|
63
|
-
resources?: string[]
|
|
64
|
-
requestId?: string
|
|
65
|
-
expirationTime?: string
|
|
66
|
-
}>()
|
|
67
|
-
|
|
68
|
-
const emit = defineEmits<{
|
|
69
|
-
authenticated: [{ address: `0x${string}`; chainId: number }]
|
|
70
|
-
error: [error: string]
|
|
71
|
-
}>()
|
|
58
|
+
const props = defineProps<EvmSiweProps>()
|
|
59
|
+
|
|
60
|
+
const emit = defineEmits<EvmSiweEmits>()
|
|
72
61
|
|
|
73
62
|
function isUserRejection(e: unknown): boolean {
|
|
74
63
|
const re = /reject|denied|cancel/i
|
|
@@ -45,24 +45,11 @@ import { ref, watch } from 'vue'
|
|
|
45
45
|
import { Button, Dialog } from '@1001-digital/components'
|
|
46
46
|
import EvmSiwe from './EvmSiwe.vue'
|
|
47
47
|
import { useSiwe } from '../composables/siwe'
|
|
48
|
+
import type { EvmSiweDialogProps, EvmSiweDialogEmits } from '../types'
|
|
48
49
|
|
|
49
|
-
const props = defineProps<
|
|
50
|
-
className?: string
|
|
51
|
-
getNonce: () => Promise<string>
|
|
52
|
-
verify: (message: string, signature: string) => Promise<boolean>
|
|
53
|
-
domain?: string
|
|
54
|
-
statement?: string
|
|
55
|
-
uri?: string
|
|
56
|
-
resources?: string[]
|
|
57
|
-
requestId?: string
|
|
58
|
-
expirationTime?: string
|
|
59
|
-
}>()
|
|
50
|
+
const props = defineProps<EvmSiweDialogProps>()
|
|
60
51
|
|
|
61
|
-
const emit = defineEmits<
|
|
62
|
-
authenticated: [{ address: `0x${string}`; chainId: number }]
|
|
63
|
-
signedOut: []
|
|
64
|
-
error: [error: string]
|
|
65
|
-
}>()
|
|
52
|
+
const emit = defineEmits<EvmSiweDialogEmits>()
|
|
66
53
|
|
|
67
54
|
const { isAuthenticated, session, signOut } = useSiwe()
|
|
68
55
|
|
|
@@ -56,15 +56,11 @@ import { ref, computed } from 'vue'
|
|
|
56
56
|
import type { Chain } from 'viem'
|
|
57
57
|
import { useConfig, useConnection, useSwitchChain } from '@wagmi/vue'
|
|
58
58
|
import { Button, Dialog, Icon, Alert, Loading } from '@1001-digital/components'
|
|
59
|
+
import type { EvmSwitchNetworkProps, EvmSwitchNetworkEmits } from '../types'
|
|
59
60
|
|
|
60
|
-
defineProps<
|
|
61
|
-
className?: string
|
|
62
|
-
}>()
|
|
61
|
+
defineProps<EvmSwitchNetworkProps>()
|
|
63
62
|
|
|
64
|
-
const emit = defineEmits<
|
|
65
|
-
switched: [{ chainId: number; name: string }]
|
|
66
|
-
error: [{ message: string }]
|
|
67
|
-
}>()
|
|
63
|
+
const emit = defineEmits<EvmSwitchNetworkEmits>()
|
|
68
64
|
|
|
69
65
|
const config = useConfig()
|
|
70
66
|
const { chainId: currentChainId } = useConnection()
|
|
@@ -80,12 +80,7 @@ import { useConfig, useConnection, type Config } from '@wagmi/vue'
|
|
|
80
80
|
import type { TransactionReceipt, Hash } from 'viem'
|
|
81
81
|
import { Dialog, Loading, Alert, Button, useToast, delay } from '@1001-digital/components'
|
|
82
82
|
import { useEnsureChainIdCheck, useBlockExplorer } from '../composables/chainId'
|
|
83
|
-
|
|
84
|
-
interface TextConfig {
|
|
85
|
-
title?: Record<string, string>
|
|
86
|
-
lead?: Record<string, string>
|
|
87
|
-
action?: Record<string, string>
|
|
88
|
-
}
|
|
83
|
+
import type { TransactionFlowText, EvmTransactionFlowProps, EvmTransactionFlowEmits } from '../types'
|
|
89
84
|
|
|
90
85
|
type Step =
|
|
91
86
|
| 'idle'
|
|
@@ -116,19 +111,10 @@ const defaultText = {
|
|
|
116
111
|
confirm: 'Execute',
|
|
117
112
|
error: 'Try Again',
|
|
118
113
|
},
|
|
119
|
-
} satisfies
|
|
114
|
+
} satisfies TransactionFlowText
|
|
120
115
|
|
|
121
116
|
const props = withDefaults(
|
|
122
|
-
defineProps<
|
|
123
|
-
chain?: string
|
|
124
|
-
text?: TextConfig
|
|
125
|
-
request?: () => Promise<Hash>
|
|
126
|
-
delayAfter?: number
|
|
127
|
-
delayAutoclose?: number
|
|
128
|
-
skipConfirmation?: boolean
|
|
129
|
-
autoCloseSuccess?: boolean
|
|
130
|
-
dismissable?: boolean
|
|
131
|
-
}>(),
|
|
117
|
+
defineProps<EvmTransactionFlowProps>(),
|
|
132
118
|
{
|
|
133
119
|
delayAfter: 2000,
|
|
134
120
|
delayAutoclose: 2000,
|
|
@@ -156,12 +142,9 @@ const { connector } = useConnection()
|
|
|
156
142
|
const blockExplorer = useBlockExplorer(props.chain)
|
|
157
143
|
const toast = useToast()
|
|
158
144
|
|
|
159
|
-
const emit = defineEmits<
|
|
160
|
-
complete: [receipt: TransactionReceipt]
|
|
161
|
-
cancel: []
|
|
162
|
-
}>()
|
|
145
|
+
const emit = defineEmits<EvmTransactionFlowEmits>()
|
|
163
146
|
|
|
164
|
-
const text = computed<Required<
|
|
147
|
+
const text = computed<Required<TransactionFlowText>>(() => ({
|
|
165
148
|
title: { ...defaultText.title, ...props.text?.title },
|
|
166
149
|
lead: { ...defaultText.lead, ...props.text?.lead },
|
|
167
150
|
action: { ...defaultText.action, ...props.text?.action },
|
|
@@ -75,14 +75,11 @@ import {
|
|
|
75
75
|
useWalletExplorer,
|
|
76
76
|
type ExplorerWallet,
|
|
77
77
|
} from '../composables/walletExplorer'
|
|
78
|
+
import type { EvmWalletConnectWalletsProps, EvmWalletConnectWalletsEmits } from '../types'
|
|
78
79
|
|
|
79
|
-
const props = defineProps<
|
|
80
|
-
uri: string
|
|
81
|
-
}>()
|
|
80
|
+
const props = defineProps<EvmWalletConnectWalletsProps>()
|
|
82
81
|
|
|
83
|
-
defineEmits<
|
|
84
|
-
back: []
|
|
85
|
-
}>()
|
|
82
|
+
defineEmits<EvmWalletConnectWalletsEmits>()
|
|
86
83
|
|
|
87
84
|
const explorer = useWalletExplorer()
|
|
88
85
|
const searchQuery = ref('')
|
package/src/composables/uri.ts
CHANGED
|
@@ -1,12 +1,41 @@
|
|
|
1
|
+
import { ref, watch, toValue, type MaybeRefOrGetter, type Ref } from 'vue'
|
|
2
|
+
import { createDwebFetch, type DwebClient } from '@1001-digital/dweb-fetch'
|
|
1
3
|
import { useEvmConfig } from '../config'
|
|
2
|
-
import { resolveUri } from '../utils/uri'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
function toBaseUrl(gateway: string): string {
|
|
6
|
+
return gateway.replace(/\/(ipfs|ipns)\/?$/, '').replace(/\/+$/, '')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function useDwebClient(): DwebClient {
|
|
10
|
+
const config = useEvmConfig()
|
|
11
|
+
|
|
12
|
+
return createDwebFetch({
|
|
13
|
+
ipfs: config.ipfsGateway
|
|
14
|
+
? { gateways: [toBaseUrl(config.ipfsGateway)] }
|
|
15
|
+
: undefined,
|
|
16
|
+
arweave: config.arweaveGateway
|
|
17
|
+
? { gateways: [toBaseUrl(config.arweaveGateway)] }
|
|
18
|
+
: undefined,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useResolvedUrl(
|
|
23
|
+
uri: MaybeRefOrGetter<string | undefined>,
|
|
24
|
+
): Ref<string> {
|
|
25
|
+
const dweb = useDwebClient()
|
|
26
|
+
const resolved = ref('')
|
|
27
|
+
|
|
28
|
+
watch(
|
|
29
|
+
() => toValue(uri),
|
|
30
|
+
async (val) => {
|
|
31
|
+
if (!val) {
|
|
32
|
+
resolved.value = ''
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
resolved.value = await dweb.resolveUrl(val)
|
|
36
|
+
},
|
|
37
|
+
{ immediate: true },
|
|
38
|
+
)
|
|
6
39
|
|
|
7
|
-
return
|
|
8
|
-
resolveUri(uri, {
|
|
9
|
-
ipfsGateway: evmConfig.ipfsGateway,
|
|
10
|
-
arweaveGateway: evmConfig.arweaveGateway,
|
|
11
|
-
})
|
|
40
|
+
return resolved
|
|
12
41
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,36 @@
|
|
|
2
2
|
export { EvmConfigKey, defaultEvmConfig, useEvmConfig } from './config'
|
|
3
3
|
export type { EvmConfig, EvmChainConfig } from './config'
|
|
4
4
|
|
|
5
|
+
// Component types
|
|
6
|
+
export type {
|
|
7
|
+
EvmAccountProps,
|
|
8
|
+
EvmAvatarProps,
|
|
9
|
+
EvmConnectEmits,
|
|
10
|
+
EvmConnectDialogProps,
|
|
11
|
+
EvmConnectDialogEmits,
|
|
12
|
+
EvmProfileProps,
|
|
13
|
+
EvmProfileEmits,
|
|
14
|
+
EvmSwitchNetworkProps,
|
|
15
|
+
EvmSwitchNetworkEmits,
|
|
16
|
+
EvmConnectorQRProps,
|
|
17
|
+
EvmMetaMaskQRProps,
|
|
18
|
+
EvmMetaMaskQREmits,
|
|
19
|
+
EvmWalletConnectQRProps,
|
|
20
|
+
EvmWalletConnectWalletsProps,
|
|
21
|
+
EvmWalletConnectWalletsEmits,
|
|
22
|
+
TransactionFlowText,
|
|
23
|
+
EvmTransactionFlowProps,
|
|
24
|
+
EvmTransactionFlowEmits,
|
|
25
|
+
EvmSeedPhraseInputProps,
|
|
26
|
+
EvmSeedPhraseInputEmits,
|
|
27
|
+
EvmInAppWalletSetupProps,
|
|
28
|
+
EvmInAppWalletSetupEmits,
|
|
29
|
+
EvmSiweProps,
|
|
30
|
+
EvmSiweEmits,
|
|
31
|
+
EvmSiweDialogProps,
|
|
32
|
+
EvmSiweDialogEmits,
|
|
33
|
+
} from './types'
|
|
34
|
+
|
|
5
35
|
// Utils
|
|
6
36
|
export { createCache } from './utils/cache'
|
|
7
37
|
export { shortAddress } from './utils/addresses'
|
|
@@ -16,8 +46,8 @@ export {
|
|
|
16
46
|
} from './utils/ens'
|
|
17
47
|
export type { EnsProfile } from './utils/ens'
|
|
18
48
|
export { stringifyJSON, parseJSON, formatPrice } from './utils/price'
|
|
19
|
-
export {
|
|
20
|
-
export type {
|
|
49
|
+
export { createDwebFetch } from '@1001-digital/dweb-fetch'
|
|
50
|
+
export type { DwebClient, DwebFetchConfig } from '@1001-digital/dweb-fetch'
|
|
21
51
|
export { createSiweMessage } from './utils/siwe'
|
|
22
52
|
export type { SiweMessageParams } from './utils/siwe'
|
|
23
53
|
|
|
@@ -30,7 +60,7 @@ export {
|
|
|
30
60
|
useEnsureChainIdCheck,
|
|
31
61
|
} from './composables/chainId'
|
|
32
62
|
export { useEns, useEnsWithAvatar, useEnsProfile } from './composables/ens'
|
|
33
|
-
export {
|
|
63
|
+
export { useDwebClient, useResolvedUrl } from './composables/uri'
|
|
34
64
|
export { useGasPrice } from './composables/gasPrice'
|
|
35
65
|
export { usePriceFeed } from './composables/priceFeed'
|
|
36
66
|
export { useWalletExplorer } from './composables/walletExplorer'
|
|
@@ -41,6 +71,8 @@ export type { SiweSession, UseSiweOptions } from './composables/siwe'
|
|
|
41
71
|
// Connectors
|
|
42
72
|
export { inAppWallet, prepareInAppWallet } from './connectors/inAppWallet'
|
|
43
73
|
|
|
74
|
+
export { clientOnlyComponents } from './client-only'
|
|
75
|
+
|
|
44
76
|
// Components
|
|
45
77
|
export { default as EvmAccount } from './components/EvmAccount.vue'
|
|
46
78
|
export { default as EvmAvatar } from './components/EvmAvatar.vue'
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { Address, Hash, TransactionReceipt } from 'viem'
|
|
2
|
+
|
|
3
|
+
// EvmAccount
|
|
4
|
+
export interface EvmAccountProps {
|
|
5
|
+
address?: Address
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// EvmAvatar
|
|
9
|
+
export interface EvmAvatarProps {
|
|
10
|
+
address?: Address
|
|
11
|
+
large?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// EvmConnect
|
|
15
|
+
export interface EvmConnectEmits {
|
|
16
|
+
connecting: []
|
|
17
|
+
connected: []
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// EvmConnectDialog
|
|
21
|
+
export interface EvmConnectDialogProps {
|
|
22
|
+
className?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface EvmConnectDialogEmits {
|
|
26
|
+
connected: [{ address: `0x${string}` | undefined }]
|
|
27
|
+
disconnected: []
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// EvmProfile
|
|
31
|
+
export interface EvmProfileProps {
|
|
32
|
+
className?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface EvmProfileEmits {
|
|
36
|
+
disconnected: []
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// EvmSwitchNetwork
|
|
40
|
+
export interface EvmSwitchNetworkProps {
|
|
41
|
+
className?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface EvmSwitchNetworkEmits {
|
|
45
|
+
switched: [{ chainId: number; name: string }]
|
|
46
|
+
error: [{ message: string }]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// EvmConnectorQR
|
|
50
|
+
export interface EvmConnectorQRProps {
|
|
51
|
+
uri: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// EvmMetaMaskQR
|
|
55
|
+
export interface EvmMetaMaskQRProps {
|
|
56
|
+
uri: string
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface EvmMetaMaskQREmits {
|
|
60
|
+
back: []
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// EvmWalletConnectQR
|
|
64
|
+
export interface EvmWalletConnectQRProps {
|
|
65
|
+
uri: string
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// EvmWalletConnectWallets
|
|
69
|
+
export interface EvmWalletConnectWalletsProps {
|
|
70
|
+
uri: string
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface EvmWalletConnectWalletsEmits {
|
|
74
|
+
back: []
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// EvmTransactionFlow
|
|
78
|
+
export interface TransactionFlowText {
|
|
79
|
+
title?: Record<string, string>
|
|
80
|
+
lead?: Record<string, string>
|
|
81
|
+
action?: Record<string, string>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface EvmTransactionFlowProps {
|
|
85
|
+
chain?: string
|
|
86
|
+
text?: TransactionFlowText
|
|
87
|
+
request?: () => Promise<Hash>
|
|
88
|
+
delayAfter?: number
|
|
89
|
+
delayAutoclose?: number
|
|
90
|
+
skipConfirmation?: boolean
|
|
91
|
+
autoCloseSuccess?: boolean
|
|
92
|
+
dismissable?: boolean
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface EvmTransactionFlowEmits {
|
|
96
|
+
complete: [receipt: TransactionReceipt]
|
|
97
|
+
cancel: []
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// EvmSeedPhraseInput
|
|
101
|
+
export interface EvmSeedPhraseInputProps {
|
|
102
|
+
modelValue?: string
|
|
103
|
+
disabled?: boolean
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface EvmSeedPhraseInputEmits {
|
|
107
|
+
'update:modelValue': [value: string]
|
|
108
|
+
valid: [isValid: boolean]
|
|
109
|
+
submit: []
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// EvmInAppWalletSetup
|
|
113
|
+
export interface EvmInAppWalletSetupProps {
|
|
114
|
+
note?: string
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface EvmInAppWalletSetupEmits {
|
|
118
|
+
connected: []
|
|
119
|
+
back: []
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// EvmSiwe
|
|
123
|
+
export interface EvmSiweProps {
|
|
124
|
+
getNonce: () => Promise<string>
|
|
125
|
+
verify: (message: string, signature: string) => Promise<boolean>
|
|
126
|
+
domain?: string
|
|
127
|
+
statement?: string
|
|
128
|
+
uri?: string
|
|
129
|
+
resources?: string[]
|
|
130
|
+
requestId?: string
|
|
131
|
+
expirationTime?: string
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface EvmSiweEmits {
|
|
135
|
+
authenticated: [{ address: `0x${string}`; chainId: number }]
|
|
136
|
+
error: [error: string]
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// EvmSiweDialog
|
|
140
|
+
export interface EvmSiweDialogProps extends EvmSiweProps {
|
|
141
|
+
className?: string
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface EvmSiweDialogEmits {
|
|
145
|
+
authenticated: [{ address: `0x${string}`; chainId: number }]
|
|
146
|
+
signedOut: []
|
|
147
|
+
error: [error: string]
|
|
148
|
+
}
|
package/src/utils/uri.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export interface ResolveUriOptions {
|
|
2
|
-
ipfsGateway?: string
|
|
3
|
-
arweaveGateway?: string
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const DEFAULT_IPFS_GATEWAY = 'https://ipfs.io/ipfs/'
|
|
7
|
-
const DEFAULT_ARWEAVE_GATEWAY = 'https://arweave.net/'
|
|
8
|
-
|
|
9
|
-
export const resolveUri = (
|
|
10
|
-
uri?: string,
|
|
11
|
-
options?: ResolveUriOptions,
|
|
12
|
-
): string => {
|
|
13
|
-
if (!uri) return ''
|
|
14
|
-
|
|
15
|
-
const ipfs = options?.ipfsGateway || DEFAULT_IPFS_GATEWAY
|
|
16
|
-
const ar = options?.arweaveGateway || DEFAULT_ARWEAVE_GATEWAY
|
|
17
|
-
|
|
18
|
-
if (uri.startsWith('data:')) return uri
|
|
19
|
-
if (uri.startsWith('ipfs://')) return ipfs + uri.replace('ipfs://', '')
|
|
20
|
-
if (uri.startsWith('ar://')) return ar + uri.replace('ar://', '')
|
|
21
|
-
if (uri.startsWith('Qm') || uri.startsWith('baf')) return ipfs + uri
|
|
22
|
-
|
|
23
|
-
return uri
|
|
24
|
-
}
|