Skip to content

Commit 6d39c65

Browse files
committed
prettier format
1 parent f29ae9d commit 6d39c65

33 files changed

+1662
-1028
lines changed

.eslintrc.cjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ module.exports = {
66
'extends': [
77
'plugin:vue/vue3-essential',
88
'eslint:recommended',
9-
'@vue/eslint-config-typescript'
9+
'@vue/eslint-config-typescript',
10+
'@vue/eslint-config-prettier/skip-formatting',
1011
],
1112
parserOptions: {
1213
ecmaVersion: 'latest'
13-
}
14+
},
15+
rules: {
16+
'vue/multi-word-component-names': 'off'
17+
},
18+
ignorePatterns: [
19+
'dist/**/*',
20+
'demo/**/*',
21+
'examples/**/*'
22+
]
1423
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ lerna-debug.log*
99

1010
node_modules
1111
.DS_Store
12-
#dist
12+
dist
1313
dist-ssr
14+
demo
1415
coverage
1516
*.local
1617

.prettierrc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"bracketSpacing": true,
3+
"trailingComma": "none",
4+
"tabWidth": 2,
5+
"printWidth": 120,
6+
"semi": false,
7+
"singleQuote": true,
8+
"endOfLine": "auto",
9+
"plugins": [
10+
"@trivago/prettier-plugin-sort-imports",
11+
"prettier-plugin-organize-attributes",
12+
"prettier-plugin-tailwindcss"
13+
],
14+
"importOrder": [
15+
"^./App.vue$",
16+
"<THIRD_PARTY_MODULES>",
17+
"^@/(.*)$",
18+
"^[./]"
19+
],
20+
"importOrderSeparation": true,
21+
"importOrderSortSpecifiers": true,
22+
"attributeGroups": [
23+
"^ref",
24+
"^v-if",
25+
"^v-else",
26+
"^v-show",
27+
"^v-for",
28+
"^:?is$",
29+
"^@",
30+
"^:",
31+
"$DEFAULT",
32+
"^aria-",
33+
"^:?key$"
34+
]
35+
}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
dev:
22
yarn dev-demo
3+
format:
4+
yarn format
5+
check:
6+
yarn type-check-lib && yarn lint
37
build:
48
yarn build-lib && yarn build-demo
59
build-demo:

lib/account.ts

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,57 @@
1-
import type {AccountState, ConnectedAccount, Chain} from './types'
2-
import {reactive, watchEffect} from 'vue'
3-
import {disconnect as masterDisconnect} from '@wagmi/core'
4-
import {web3Modal} from './web3Modal'
5-
import {init} from './wc'
6-
import {state as optionsState} from './options'
1+
import { disconnect as masterDisconnect } from '@wagmi/core'
2+
import { reactive, watchEffect } from 'vue'
3+
4+
import { state as optionsState } from './options'
5+
import type { AccountState, Chain, ConnectedAccount } from './types'
6+
import { init } from './wc'
7+
import { web3Modal } from './web3Modal'
78

89
export const state = reactive<AccountState>({
9-
bufferAccount: null,
10-
currentAccount: null
10+
bufferAccount: null,
11+
currentAccount: null
1112
})
1213

1314
export const account = reactive<ConnectedAccount>({
14-
connected: false,
15-
address: undefined,
16-
shortAddress: undefined
15+
connected: false,
16+
address: undefined,
17+
shortAddress: undefined
1718
})
1819

1920
export async function disconnect() {
20-
await masterDisconnect()
21+
await masterDisconnect()
2122
}
2223

2324
export async function connect(chain?: Chain) {
24-
if (!web3Modal.value) init()
25+
if (!web3Modal.value) init()
2526

26-
if (chain instanceof Event) chain = optionsState.chains[0]
27-
web3Modal.value?.setDefaultChain(chain || optionsState.chains[0])
27+
if (chain instanceof Event) chain = optionsState.chains[0]
28+
web3Modal.value?.setDefaultChain(chain || optionsState.chains[0])
2829

29-
await web3Modal.value?.openModal({
30-
route: 'ConnectWallet'
31-
})
30+
await web3Modal.value?.openModal({
31+
route: 'ConnectWallet'
32+
})
3233
}
3334

3435
export async function accountDetails() {
35-
if (!web3Modal.value) init()
36+
if (!web3Modal.value) init()
3637

37-
await web3Modal.value?.openModal({
38-
route: 'Account'
39-
})
38+
await web3Modal.value?.openModal({
39+
route: 'Account'
40+
})
4041
}
4142

4243
export function shortAddressFilter(value = '') {
43-
return `${value.slice(0, 5)}...${value.slice(-4)}`
44+
return `${value.slice(0, 5)}...${value.slice(-4)}`
4445
}
4546

4647
watchEffect(() => {
47-
if (state.currentAccount) {
48-
account.connected = true
49-
account.address = state.currentAccount.address
50-
account.shortAddress = shortAddressFilter(state.currentAccount.address)
51-
} else {
52-
account.connected = false
53-
account.address = undefined
54-
account.shortAddress = undefined
55-
}
48+
if (state.currentAccount) {
49+
account.connected = true
50+
account.address = state.currentAccount.address
51+
account.shortAddress = shortAddressFilter(state.currentAccount.address)
52+
} else {
53+
account.connected = false
54+
account.address = undefined
55+
account.shortAddress = undefined
56+
}
5657
})

lib/actions/balance.ts

Lines changed: 94 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,113 @@
1-
import type {FetchBalance, FetchBalanceOptions} from '../types'
2-
import type {FetchBalanceResult} from '@wagmi/core'
3-
import {reactive, ref, watch} from 'vue'
4-
import {fetchBalance as masterFetchBalance} from '@wagmi/core'
5-
import {chain} from '../chain'
1+
import type { FetchBalanceResult } from '@wagmi/core'
2+
import { fetchBalance as masterFetchBalance } from '@wagmi/core'
3+
import { reactive, ref, watch } from 'vue'
4+
5+
import { chain } from '../chain'
6+
import type { FetchBalance, FetchBalanceOptions } from '../types'
67

78
export function fetchBalance(data: FetchBalance) {
8-
return masterFetchBalance({
9-
chainId: data.chainId || chain.value.id,
10-
address: data.address,
11-
token: data.token,
12-
formatUnits: data.formatUnits
13-
})
9+
return masterFetchBalance({
10+
chainId: data.chainId || chain.value.id,
11+
address: data.address,
12+
token: data.token,
13+
formatUnits: data.formatUnits
14+
})
1415
}
1516

1617
export function useFetchBalance(params: FetchBalance, options?: FetchBalanceOptions) {
17-
const loaded = ref(false)
18-
const fetching = ref(false)
19-
const data = reactive<FetchBalanceResult>({
20-
decimals: 0,
21-
formatted: '',
22-
symbol: '',
23-
value: 0n
24-
})
18+
const loaded = ref(false)
19+
const fetching = ref(false)
20+
const data = reactive<FetchBalanceResult>({
21+
decimals: 0,
22+
formatted: '',
23+
symbol: '',
24+
value: 0n
25+
})
2526

26-
let timeoutHandler: number
27-
let updateHandler: number
28-
let currentChain = params.chainId || chain.value.id
29-
const fetchOptions: FetchBalanceOptions = {
30-
disableAutoFetch: options?.disableAutoFetch || false,
31-
autoReloadTime: options?.autoReloadTime || 30000,
32-
disableAutoReload: options?.disableAutoReload || false
33-
}
27+
let timeoutHandler: number
28+
let updateHandler: number
29+
let currentChain = params.chainId || chain.value.id
30+
const fetchOptions: FetchBalanceOptions = {
31+
disableAutoFetch: options?.disableAutoFetch || false,
32+
autoReloadTime: options?.autoReloadTime || 30000,
33+
disableAutoReload: options?.disableAutoReload || false
34+
}
3435

35-
async function fetch() {
36-
if (!fetching.value || !loaded.value) {
37-
fetching.value = true
36+
async function fetch() {
37+
if (!fetching.value || !loaded.value) {
38+
fetching.value = true
3839

39-
await fetchBalance(params)
40-
.then(fetchData => {
41-
if (fetchData.value !== data.value || !loaded.value) {
42-
data.decimals = fetchData.decimals
43-
data.formatted = fetchData.formatted
44-
data.symbol = fetchData.symbol
45-
data.value = fetchData.value
46-
}
47-
})
48-
.finally(() => {
49-
loaded.value = true
50-
fetching.value = false
40+
await fetchBalance(params)
41+
.then((fetchData) => {
42+
if (fetchData.value !== data.value || !loaded.value) {
43+
data.decimals = fetchData.decimals
44+
data.formatted = fetchData.formatted
45+
data.symbol = fetchData.symbol
46+
data.value = fetchData.value
47+
}
48+
})
49+
.finally(() => {
50+
loaded.value = true
51+
fetching.value = false
5152

52-
runTimeout()
53-
})
54-
}
53+
runTimeout()
54+
})
5555
}
56+
}
5657

57-
function reload() {
58-
clearTimeout(timeoutHandler)
59-
return fetch()
60-
}
58+
function reload() {
59+
clearTimeout(timeoutHandler)
60+
return fetch()
61+
}
6162

62-
function disableAutoReload() {
63-
fetchOptions.disableAutoReload = true
64-
}
63+
function disableAutoReload() {
64+
fetchOptions.disableAutoReload = true
65+
}
6566

66-
function runTimeout() {
67-
if (fetchOptions.disableAutoReload !== true) {
68-
// @ts-ignore
69-
timeoutHandler = setTimeout(reload, fetchOptions.autoReloadTime || 30000)
70-
}
67+
function runTimeout() {
68+
if (fetchOptions.disableAutoReload !== true) {
69+
// @ts-ignore
70+
timeoutHandler = setTimeout(reload, fetchOptions.autoReloadTime || 30000)
7171
}
72+
}
7273

73-
function resetData() {
74-
loaded.value = false
75-
data.decimals = 0
76-
data.formatted = ''
77-
data.symbol = ''
78-
data.value = 0n
79-
}
74+
function resetData() {
75+
loaded.value = false
76+
data.decimals = 0
77+
data.formatted = ''
78+
data.symbol = ''
79+
data.value = 0n
80+
}
8081

81-
function update() {
82-
clearTimeout(updateHandler)
83-
currentChain = chain.value.id
84-
resetData()
85-
reload()
86-
}
82+
function update() {
83+
clearTimeout(updateHandler)
84+
currentChain = chain.value.id
85+
resetData()
86+
reload()
87+
}
8788

88-
if (fetchOptions.disableAutoFetch !== true) {
89-
fetch()
90-
}
89+
if (fetchOptions.disableAutoFetch !== true) {
90+
fetch()
91+
}
9192

92-
if (params.chainId === undefined) {
93-
watch(() => chain.value.id, (newChainId) => {
94-
if (newChainId !== currentChain) {
95-
// @ts-ignore
96-
updateHandler = setTimeout(update)
97-
}
98-
})
99-
}
93+
if (params.chainId === undefined) {
94+
watch(
95+
() => chain.value.id,
96+
(newChainId) => {
97+
if (newChainId !== currentChain) {
98+
// @ts-ignore
99+
updateHandler = setTimeout(update)
100+
}
101+
}
102+
)
103+
}
100104

101-
return {
102-
loaded,
103-
fetching,
104-
data,
105-
fetch,
106-
reload,
107-
disableAutoReload
108-
}
109-
}
105+
return {
106+
loaded,
107+
fetching,
108+
data,
109+
fetch,
110+
reload,
111+
disableAutoReload
112+
}
113+
}

lib/actions/block.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import type {FetchBlockNumber} from '../types'
2-
import {fetchBlockNumber as masterFetchBlockNumber} from '@wagmi/core'
3-
import {chain} from '../chain'
1+
import { fetchBlockNumber as masterFetchBlockNumber } from '@wagmi/core'
2+
3+
import { chain } from '../chain'
4+
import type { FetchBlockNumber } from '../types'
45

56
export function fetchBlockNumber(data?: FetchBlockNumber) {
6-
return masterFetchBlockNumber({
7-
chainId: data?.chainId || chain.value.id
8-
})
7+
return masterFetchBlockNumber({
8+
chainId: data?.chainId || chain.value.id
9+
})
910
}

0 commit comments

Comments
 (0)