@instadapp/avocado-base 0.2.1 → 0.2.3
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/.vscode/settings.json +64 -65
- package/abi/avoFactoryProxy.json +1 -1
- package/abi/forwarder.json +1 -1
- package/abi/multisigAgnosticForwarder.json +936 -937
- package/abi/multisigForwarder.json +680 -680
- package/app.vue +5 -5
- package/components/ActionLogo.vue +15 -15
- package/components/AuthorityAvatar.vue +8 -6
- package/components/ChainLogo.vue +19 -15
- package/components/CopyClipboard.vue +1 -1
- package/components/metadata/Bridge.vue +22 -23
- package/components/metadata/GasTopup.vue +14 -15
- package/components/metadata/Permit2.vue +12 -13
- package/eslint.config.mjs +14 -0
- package/nuxt.config.ts +4 -0
- package/package.json +5 -5
- package/server/utils/index.ts +4 -4
- package/utils/avocado.ts +17 -17
- package/utils/bignumber.ts +47 -36
- package/utils/formatter.ts +54 -60
- package/utils/helper.ts +33 -30
- package/utils/metadata.ts +366 -403
- package/utils/network.ts +2 -2
- package/utils/services.ts +11 -13
package/utils/formatter.ts
CHANGED
|
@@ -1,94 +1,88 @@
|
|
|
1
1
|
export function formatPercent(
|
|
2
2
|
value?: number | string,
|
|
3
3
|
fractionDigits = 2,
|
|
4
|
-
maxValue = null
|
|
4
|
+
maxValue = null,
|
|
5
5
|
) {
|
|
6
|
-
if (!value || isZero(value))
|
|
6
|
+
if (!value || isZero(value))
|
|
7
|
+
return '0.00%'
|
|
7
8
|
|
|
8
|
-
const valueAsNumber = toBN(value).toNumber()
|
|
9
|
+
const valueAsNumber = toBN(value).toNumber()
|
|
9
10
|
|
|
10
|
-
if (maxValue && gt(times(valueAsNumber,
|
|
11
|
-
return `>${maxValue}
|
|
11
|
+
if (maxValue && gt(times(valueAsNumber, '100'), maxValue))
|
|
12
|
+
return `>${maxValue}%`
|
|
12
13
|
|
|
13
|
-
const formatter = new Intl.NumberFormat(
|
|
14
|
-
style:
|
|
14
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
15
|
+
style: 'percent',
|
|
15
16
|
minimumFractionDigits: fractionDigits,
|
|
16
17
|
maximumFractionDigits: fractionDigits,
|
|
17
|
-
})
|
|
18
|
+
})
|
|
18
19
|
|
|
19
|
-
return formatter.format(valueAsNumber)
|
|
20
|
+
return formatter.format(valueAsNumber)
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export function shortenHash(hash: string | `0x${string}`, length: number = 4) {
|
|
23
|
-
if (!hash)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
if (!hash)
|
|
25
|
+
return
|
|
26
|
+
if (hash.length < 12)
|
|
27
|
+
return hash
|
|
28
|
+
const beginningChars = hash.startsWith('0x') ? length + 2 : length
|
|
29
|
+
const shortened
|
|
30
|
+
= `${hash.substr(0, beginningChars)}...${hash.substr(-length)}`
|
|
31
|
+
return shortened
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
export function formatUsd(value: any, fractionDigits = 2) {
|
|
32
|
-
const formatter = new Intl.NumberFormat(
|
|
33
|
-
style:
|
|
34
|
-
currency:
|
|
35
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
36
|
+
style: 'currency',
|
|
37
|
+
currency: 'USD',
|
|
35
38
|
minimumFractionDigits: fractionDigits,
|
|
36
39
|
maximumFractionDigits: fractionDigits,
|
|
37
|
-
})
|
|
40
|
+
})
|
|
38
41
|
|
|
39
|
-
return formatter.format(value)
|
|
42
|
+
return formatter.format(value)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
export function signedNumber(numb: string | number) {
|
|
43
|
-
return new Intl.NumberFormat(
|
|
44
|
-
signDisplay:
|
|
45
|
-
}).format(toBN(numb).toNumber())
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function getFractionDigits(value: string | number) {
|
|
49
|
-
const absoluteValue = toBN(value).abs();
|
|
50
|
-
|
|
51
|
-
if (isZero(absoluteValue)) {
|
|
52
|
-
return 2;
|
|
53
|
-
} else if (lt(absoluteValue, 0.01)) {
|
|
54
|
-
return 6;
|
|
55
|
-
} else if (lt(absoluteValue, 1)) {
|
|
56
|
-
return 4;
|
|
57
|
-
} else if (lt(absoluteValue, 10000)) {
|
|
58
|
-
return 2;
|
|
59
|
-
} else {
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
46
|
+
return new Intl.NumberFormat('en-US', {
|
|
47
|
+
signDisplay: 'exceptZero',
|
|
48
|
+
}).format(toBN(numb).toNumber())
|
|
62
49
|
}
|
|
63
50
|
|
|
64
51
|
export function formatDecimal(value: string | number, fractionDigits?: number) {
|
|
65
52
|
if (!value) {
|
|
66
|
-
value =
|
|
53
|
+
value = '0'
|
|
54
|
+
}
|
|
55
|
+
if (lt(value, '0.0001') && gt(value, '0')) {
|
|
56
|
+
return '< 0.0001'
|
|
67
57
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const num = toBN(value);
|
|
72
|
-
let decimals;
|
|
58
|
+
else {
|
|
59
|
+
const num = toBN(value)
|
|
60
|
+
let decimals
|
|
73
61
|
|
|
74
62
|
if (num.lt(1)) {
|
|
75
|
-
decimals = 4
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
decimals =
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
decimals =
|
|
63
|
+
decimals = 4
|
|
64
|
+
}
|
|
65
|
+
else if (num.lt(10)) {
|
|
66
|
+
decimals = 6
|
|
67
|
+
}
|
|
68
|
+
else if (num.lt(100)) {
|
|
69
|
+
decimals = 4
|
|
70
|
+
}
|
|
71
|
+
else if (num.lt(1000)) {
|
|
72
|
+
decimals = 3
|
|
73
|
+
}
|
|
74
|
+
else if (num.lt(10000)) {
|
|
75
|
+
decimals = 2
|
|
76
|
+
}
|
|
77
|
+
else if (num.lt(100000)) {
|
|
78
|
+
decimals = 1
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
decimals = 0
|
|
88
82
|
}
|
|
89
83
|
|
|
90
|
-
const formattedNumber = num.toFixed(fractionDigits || decimals)
|
|
84
|
+
const formattedNumber = num.toFixed(fractionDigits || decimals)
|
|
91
85
|
|
|
92
|
-
return toBN(formattedNumber).toFormat()
|
|
86
|
+
return toBN(formattedNumber).toFormat()
|
|
93
87
|
}
|
|
94
88
|
}
|
package/utils/helper.ts
CHANGED
|
@@ -1,62 +1,65 @@
|
|
|
1
|
-
export
|
|
1
|
+
export function indexSorter(aIndex: number, bIndex: number) {
|
|
2
2
|
if (aIndex === -1 && bIndex === -1) {
|
|
3
|
-
return 0
|
|
4
|
-
} else if (aIndex === -1) {
|
|
5
|
-
return 1; // b comes first if a is not in the priority list
|
|
6
|
-
} else if (bIndex === -1) {
|
|
7
|
-
return -1; // a comes first if b is not in the priority list
|
|
8
|
-
} else {
|
|
9
|
-
return aIndex - bIndex; // sort by the index in the priority list
|
|
3
|
+
return 0 // fallback to other sorting criteria
|
|
10
4
|
}
|
|
11
|
-
|
|
5
|
+
else if (aIndex === -1) {
|
|
6
|
+
return 1 // b comes first if a is not in the priority list
|
|
7
|
+
}
|
|
8
|
+
else if (bIndex === -1) {
|
|
9
|
+
return -1 // a comes first if b is not in the priority list
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return aIndex - bIndex // sort by the index in the priority list
|
|
13
|
+
}
|
|
14
|
+
}
|
|
12
15
|
|
|
13
16
|
export function sortByMany<T>(
|
|
14
17
|
items: T[],
|
|
15
|
-
callback: ((a: T, b: T) => number)[]
|
|
18
|
+
callback: ((a: T, b: T) => number)[],
|
|
16
19
|
) {
|
|
17
|
-
return items.sort(
|
|
18
|
-
|
|
19
|
-
for (
|
|
20
|
-
|
|
21
|
-
result = func(a, b)
|
|
20
|
+
return items.sort((a, b) => {
|
|
21
|
+
let result = 0
|
|
22
|
+
for (let i = 0; i < callback.length; i++) {
|
|
23
|
+
const func = callback[i]
|
|
24
|
+
result = func(a, b)
|
|
22
25
|
if (result !== 0) {
|
|
23
|
-
break
|
|
26
|
+
break
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
|
-
return result
|
|
27
|
-
})
|
|
29
|
+
return result
|
|
30
|
+
})
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
export function cloneDeep<T>(value: T): T {
|
|
31
|
-
return JSON.parse(JSON.stringify(value))
|
|
34
|
+
return JSON.parse(JSON.stringify(value))
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
export function filterArray(array: any, filters: any) {
|
|
35
|
-
const filterKeys = Object.keys(filters)
|
|
38
|
+
const filterKeys = Object.keys(filters)
|
|
36
39
|
return array.filter((item: any) => {
|
|
37
40
|
// validates all filter criteria
|
|
38
41
|
return filterKeys.every((key) => {
|
|
39
42
|
// ignores non-function predicates
|
|
40
|
-
if (typeof filters[key] !==
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
if (typeof filters[key] !== 'function')
|
|
44
|
+
return true
|
|
45
|
+
return filters[key](item[key], item)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
export function onImageError(this: HTMLImageElement) {
|
|
47
|
-
const parentElement = this.parentElement
|
|
48
|
-
this.onerror = null
|
|
49
|
-
this.remove()
|
|
51
|
+
const parentElement = this.parentElement
|
|
52
|
+
this.onerror = null
|
|
53
|
+
this.remove()
|
|
50
54
|
|
|
51
55
|
if (parentElement) {
|
|
52
|
-
parentElement.classList.add(
|
|
56
|
+
parentElement.classList.add('bg-gray-300')
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
export function formatMultipleAddresses(addresses: string[], shorten = true) {
|
|
57
61
|
const formatter = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' })
|
|
58
62
|
const formattedString = formatter.format(addresses.map(i => shorten ? shortenHash(i) || '' : i))
|
|
59
|
-
|
|
63
|
+
|
|
60
64
|
return formattedString
|
|
61
65
|
}
|
|
62
|
-
|