Skip to content

Commit ad97c38

Browse files
committed
implemented: wallet_watchAsset RPC Method
1 parent ac823de commit ad97c38

File tree

7 files changed

+49
-6
lines changed

7 files changed

+49
-6
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
Simple WalletConnect Web3Modal v2 integration package for Vue3 apps.
99

1010
### Versions
11-
| package version | web3modal |
12-
|-----------------|-------------------|
13-
| [2.x.x](https://github.com/kolirt/vue-web3-auth/tree/v2) | [v2](https://github.com/WalletConnect/web3modal/tree/V2) |
1411

12+
| package version | web3modal |
13+
| -------------------------------------------------------- | -------------------------------------------------------- |
14+
| [2.x.x](https://github.com/kolirt/vue-web3-auth/tree/v2) | [v2](https://github.com/WalletConnect/web3modal/tree/V2) |
1515

1616
### Table of Contents
1717

@@ -39,6 +39,7 @@ Simple WalletConnect Web3Modal v2 integration package for Vue3 apps.
3939
- [EstimateWriteContractGas](#estimatewritecontractgas)
4040
- [ParseEvents](#parseevents)
4141
- [WatchContractEvent](#watchcontractevent)
42+
- [WatchAsset](#watchasset)
4243
- [Composable](#composable)
4344
- [UseFetchBalance](#usefetchbalance)
4445
- [Demo](#demo)
@@ -420,6 +421,18 @@ const unwatch = watchContractEvent(
420421
)
421422
```
422423
424+
### WatchAsset
425+
426+
```js
427+
import { watchAsset } from '@kolirt/vue-web3-auth'
428+
429+
const unwatch = watchAsset({
430+
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
431+
decimals: 18,
432+
symbol: 'DAI'
433+
})
434+
```
435+
423436
## Composable
424437
425438
### UseFetchBalance

lib/actions/asset.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { getWalletClient } from '@wagmi/core'
2+
3+
import { chain } from '../chain'
4+
import type { WatchAsset } from '../types'
5+
6+
export async function watchAsset(options: WatchAsset) {
7+
const walletClient = await getWalletClient({ chainId: options.chainId || chain.value.id })
8+
9+
if (walletClient) {
10+
return await walletClient.watchAsset({
11+
type: 'ERC20',
12+
options: {
13+
address: options.address,
14+
symbol: options.symbol,
15+
decimals: options.decimals,
16+
image: options.image
17+
}
18+
})
19+
}
20+
21+
return false
22+
}

lib/actions/event.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { watchContractEvent as masterWatchContractEvent } from '@wagmi/core'
2-
import { decodeEventLog } from 'viem'
32
import type { TransactionReceipt } from 'viem/src/types/transaction'
3+
import { decodeEventLog } from 'viem/utils'
44

55
import { chain } from '../chain'
66
import type { DecodedEvent, ParseEvents, WatchContractEvent } from '../types'

lib/actions/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export { watchAsset } from './asset'
2+
13
export { fetchBalance, useFetchBalance } from './balance'
24

35
export { fetchBlockNumber } from './block'

lib/actions/multicall.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { multicall as masterMulticall } from '@wagmi/core'
2-
import { type ContractFunctionConfig, type MulticallParameters } from 'viem'
2+
import { type MulticallParameters } from 'viem/actions'
3+
import { type ContractFunctionConfig } from 'viem/src/types/contract'
34

45
import type { MulticallArgs } from '../types'
56

lib/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Chain, Unit } from '@wagmi/core'
22
import type { ThemeCtrlState } from '@web3modal/core'
33
import type { EthereumClient } from '@web3modal/ethereum'
4+
import type { WatchAssetParams } from 'viem/src/types/eip1193'
45

56
type BlockTag = 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
67

@@ -131,6 +132,10 @@ export type FetchBalance = {
131132
token?: `0x${string}`
132133
}
133134

135+
export type WatchAsset = {
136+
chainId?: number
137+
} & WatchAssetParams['options']
138+
134139
export type FetchBalanceOptions = {
135140
disableAutoFetch?: boolean
136141
autoReloadTime?: number

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kolirt/vue-web3-auth",
3-
"version": "2.0.1",
3+
"version": "2.1.1",
44
"description": "Web3 authentication for Vue3 apps based on WalletConnect Web3Modal v2",
55
"author": "kolirt",
66
"license": "MIT",

0 commit comments

Comments
 (0)