From d6b779d074a02a60c997b070b8cc548d3ad140b5 Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Fri, 29 Mar 2024 09:18:36 -0400 Subject: [PATCH 1/8] fix: Add biome settings --- biome.json | 14 ++ src/components/endpoints/SendTransaction.vue | 72 ++++++++- src/components/shared/ContractFunction.vue | 146 ++++++++++++++----- src/components/shared/ParamField.vue | 96 ++++++++++-- src/compositions/useWeb3Connection.ts | 24 +-- src/helpers/functionUtils.ts | 13 +- src/helpers/tokenUtils.ts | 19 ++- 7 files changed, 298 insertions(+), 86 deletions(-) create mode 100644 biome.json diff --git a/biome.json b/biome.json new file mode 100644 index 00000000..93897a3f --- /dev/null +++ b/biome.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.6.1/schema.json", + "linter": { + "enabled": true, + "rules": { + "suspicious": { + "noExplicitAny": "off" + }, + "performance": { + "noDelete": "off" + } + } + } +} diff --git a/src/components/endpoints/SendTransaction.vue b/src/components/endpoints/SendTransaction.vue index 3112c011..5da57473 100644 --- a/src/components/endpoints/SendTransaction.vue +++ b/src/components/endpoints/SendTransaction.vue @@ -1,7 +1,7 @@ - + {{ methodInfo.label @@ -367,6 +407,7 @@ const hasError = (index: number) => { }} @@ -399,18 +440,20 @@ const hasError = (index: number) => { gether tether{{ !props.custom && methodInfo.isWei ? methodInfo.isWei : '' - }} Decode LSPKey Encode LSP DataKey) handleSelected(index, e)" /> @@ -418,6 +461,7 @@ const hasError = (index: number) => { { > handleChange(index, e)" /> {{ @@ -453,15 +498,36 @@ const hasError = (index: number) => { actual value {{ makeWei(item.value) }} ({{ makeWei(item.value, true) }}) + + + LSP Decoder handleLSP(index, e)" + /> + + {{ + item.decoded + }} + + {{ item.decodedError }} + + {{ hasError(index) }} - + Add Remove - + {{ methodInfo.label ? methodInfo.label diff --git a/src/compositions/useWeb3Connection.ts b/src/compositions/useWeb3Connection.ts index c96317ec..244f94f2 100644 --- a/src/compositions/useWeb3Connection.ts +++ b/src/compositions/useWeb3Connection.ts @@ -1,4 +1,4 @@ -import { AbiItem, isAddress as baseIsAddress } from 'web3-utils' +import { type AbiItem, isAddress as baseIsAddress } from 'web3-utils' import { UP_CONNECTED_ADDRESS, WALLET_CONNECT, @@ -7,13 +7,13 @@ import { import useWalletConnectV2 from './useWalletConnectV2' import useWeb3Onboard from './useWeb3Onboard' import { ref } from 'vue' -import { TransactionConfig, TransactionReceipt } from 'web3-core' +import type { TransactionConfig, TransactionReceipt } from 'web3-core' import { resetNetworkConfig, setNetworkConfig } from '@/helpers/config' import { getState, useState } from '@/stores' -import EthereumProvider from '@walletconnect/ethereum-provider/dist/types/EthereumProvider' +import type EthereumProvider from '@walletconnect/ethereum-provider/dist/types/EthereumProvider' import Web3 from 'web3' -import { ContractOptions, Contract } from 'web3-eth-contract' -import { EthereumProviderError } from 'eth-rpc-errors' +import type { ContractOptions, Contract } from 'web3-eth-contract' +import type { EthereumProviderError } from 'eth-rpc-errors' const web3Onboard = useWeb3Onboard() const web3WalletConnectV2 = useWalletConnectV2() @@ -81,9 +81,9 @@ const setupProvider = async ( } const disconnect = async () => { - if (getState('channel') == WALLET_CONNECT) { + if (getState('channel') === WALLET_CONNECT) { await provider.value?.disconnect() - } else if (getState('channel') == WEB3_ONBOARD) { + } else if (getState('channel') === WEB3_ONBOARD) { await web3Onboard.disconnect() } else { localStorage.removeItem(UP_CONNECTED_ADDRESS) @@ -123,12 +123,16 @@ const estimateGas = async (transaction: TransactionConfig) => { return Number(await web3.eth.estimateGas(transaction)) } +const call = async (transaction: TransactionConfig) => { + return await web3.eth.call(transaction) +} + const sendTransaction = async ( transaction: TransactionConfig ): Promise => { return await web3.eth .sendTransaction(transaction) - .on('receipt', function (receipt: any) { + .on('receipt', (receipt: any) => { console.log(receipt) }) .once('sending', payload => { @@ -139,9 +143,8 @@ const sendTransaction = async ( const sendRequest = async (request: any): Promise => { if (provider.value) { return await provider.value.request(request) - } else { - console.warn('Provider is not set up or not connected.') } + console.warn('Provider is not set up or not connected.') } const accounts = async () => { @@ -187,6 +190,7 @@ export default function useWeb3Connection() { getBalance, sendTransaction, defaultMaxPriorityFeePerGas, + call, accounts, requestAccounts, estimateGas, diff --git a/src/helpers/functionUtils.ts b/src/helpers/functionUtils.ts index 10f7adad..6cfa2009 100644 --- a/src/helpers/functionUtils.ts +++ b/src/helpers/functionUtils.ts @@ -1,7 +1,7 @@ -import { LSPType } from '@/helpers/tokenUtils' +import type { LSPType } from '@/helpers/tokenUtils' import { SIGNATURE_LOOKUP_URL } from '@/helpers/config' -import Web3 from 'web3' -import { Unit, isAddress } from 'web3-utils' +import type Web3 from 'web3' +import { type Unit, isAddress } from 'web3-utils' export type MethodType = { label?: string @@ -77,8 +77,9 @@ export function getSelectorLookupURL(selector: string) { export const decodeData = async ( eth: Web3['eth'], - data: string + _data: string ): Promise => { + let data = _data if (/^0x/i.test(data)) { data = data.substring(2) } @@ -108,7 +109,7 @@ export const decodeData = async ( .map((_val, index) => { if (params[index] === 'bool') { const val = args[`${index}`] - if (val != 1 && val != 0) { + if (val !== 1 && val !== 0) { // Due to javascript truthyness any non-empty or non-zero value is encoded as true without a problem. // The output packet won't match but there is really no reason to even try. throw new Error('Invalid boolean value') @@ -151,5 +152,5 @@ export const decodeData = async ( } } } - throw new Error(`Unable to decode data`) + throw new Error('Unable to decode data') } diff --git a/src/helpers/tokenUtils.ts b/src/helpers/tokenUtils.ts index e370aa69..a49c3bd0 100644 --- a/src/helpers/tokenUtils.ts +++ b/src/helpers/tokenUtils.ts @@ -1,5 +1,5 @@ import BN from 'bn.js' -import ERC725, { ERC725JSONSchema } from '@erc725/erc725.js' +import ERC725, { type ERC725JSONSchema } from '@erc725/erc725.js' import { INTERFACE_IDS } from '@lukso/lsp-smart-contracts' import LSP3ProfileMetadata from '@erc725/erc725.js/schemas/LSP3ProfileMetadata.json' import LSP4DigitalAsset from '@erc725/erc725.js/schemas/LSP4DigitalAsset.json' @@ -10,9 +10,9 @@ import { erc20ABI } from '@/abis/erc20ABI' import { store, setState } from '@/stores/index' import { getSelectedNetworkConfig } from '@/helpers/config' import useWeb3Connection from '@/compositions/useWeb3Connection' -import { rightPad, fromUtf8, leftPad } from 'web3-utils' +import { rightPad, fromUtf8, isHex, leftPad, toNumber } from 'web3-utils' import { LSP8_TOKEN_ID_FORMAT } from '@lukso/lsp-smart-contracts' -import { LSP4MetadataUrlForEncoding } from '@lukso/lsp-factory.js/build/main/src/lib/interfaces/lsp4-digital-asset' +import type { LSP4MetadataUrlForEncoding } from '@lukso/lsp-factory.js/build/main/src/lib/interfaces/lsp4-digital-asset' const { lsp7TokenDivisible, lsp7TokenNonDivisible } = getSelectedNetworkConfig() @@ -161,7 +161,7 @@ export const detectLSP = async ( if (currentDecimals !== '0') { const _balance = await contract.methods - .balanceOf(store['address']) + .balanceOf(store.address) .call() .catch(() => undefined) balance = _balance @@ -255,7 +255,7 @@ export function addTokenToLocalStore(address: string) { export async function recalculateAssets() { const { getInstance } = useErc725() - const address = store['address'] + const address = store.address if (!address) { return } @@ -270,11 +270,11 @@ export async function recalculateAssets() { return all }, {}) const tokens = getTokensCreated() - tokens.forEach(address => { + for (const address of tokens) { if (!(address in mapAssets)) { mapAssets[address] = false } - }) + } if (!(lsp7TokenDivisible in mapAssets)) { mapAssets[lsp7TokenDivisible] = false } @@ -328,10 +328,13 @@ export async function recalculateAssets() { export const padTokenId = (tokenIdType: number, tokenId: string) => { switch (tokenIdType) { case LSP8_TOKEN_ID_FORMAT.NUMBER: - return `0x${leftPad(tokenId, 64)}` + return leftPad(toNumber(tokenId), 64) case LSP8_TOKEN_ID_FORMAT.STRING: return rightPad(fromUtf8(tokenId), 64) case LSP8_TOKEN_ID_FORMAT.UNIQUE_ID: + if (!isHex(tokenId)) { + throw new Error('Token ID is not a valid hex value') + } return rightPad(tokenId, 64) case LSP8_TOKEN_ID_FORMAT.HASH: return tokenId // it's 32 bytes already From 358919f662266f7b7c84a7b22c98b2cba64f7e53 Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Fri, 29 Mar 2024 09:38:17 -0400 Subject: [PATCH 2/8] fix: Repair lint error decodeData does actually return an array (need to fix in erc725) --- src/components/shared/ParamField.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/shared/ParamField.vue b/src/components/shared/ParamField.vue index 81a51237..2bd1078e 100644 --- a/src/components/shared/ParamField.vue +++ b/src/components/shared/ParamField.vue @@ -306,7 +306,8 @@ const handleLSP = (index: number, e: Event) => { [{ keyName, value: item.value }], schemas as ERC725JSONSchema[] ) - const decoded = output.find(({ name }) => name === keyName)?.value + const decoded = (output as any[]).find(({ name }) => name === keyName) + ?.value if (decoded) { if (typeof decoded === 'object') { item.decoded = JSON.stringify(decoded, null, 2) From 9bdf10e280269d8dd9bb3e29c1f5e67d139d6c0b Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:37:51 -0400 Subject: [PATCH 3/8] fix: Repair cloudflare script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 82a64b22..48cb1f0c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "vite --mode development", "build": "vue-tsc --noEmit && vite build", - "build:cloudflare": "yarn lint:js && yarn lint:css && yarn lint:format && yarn lint:types && yarn test:unit && yarn build", + "build:cloudflare": "yarn lint:js && yarn lint:css && yarn lint:format && yarn lint:types && yarn test && yarn build", "preview": "vite preview", "test": "jest", "lint": "npm-run-all --aggregate-output --continue-on-error --parallel 'lint:*!(fix)'", From 07dde5b365d55969e55c53d8c4e9e15cf389af0e Mon Sep 17 00:00:00 2001 From: Andreas Richter <708186+richtera@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:01:56 -0400 Subject: [PATCH 4/8] fix: Simplify and cleanup and try again --- biome.json | 3 + src/components/endpoints/SendTransaction.vue | 87 +++++++++++--------- src/components/shared/ContractFunction.vue | 11 ++- src/components/shared/ParamField.vue | 8 +- src/compositions/useWeb3Connection.ts | 25 +++--- src/helpers/functionUtils.ts | 6 +- src/helpers/tokenUtils.ts | 4 +- 7 files changed, 79 insertions(+), 65 deletions(-) diff --git a/biome.json b/biome.json index 93897a3f..ab0a1f73 100644 --- a/biome.json +++ b/biome.json @@ -8,6 +8,9 @@ }, "performance": { "noDelete": "off" + }, + "style": { + "useImportType": "off" } } } diff --git a/src/components/endpoints/SendTransaction.vue b/src/components/endpoints/SendTransaction.vue index 5da57473..6ca41945 100644 --- a/src/components/endpoints/SendTransaction.vue +++ b/src/components/endpoints/SendTransaction.vue @@ -1,7 +1,7 @@
actual value {{ makeWei(item.value) }} ({{ makeWei(item.value, true) }})
{{ + item.decoded + }}
+ {{ item.decodedError }} +
{{ hasError(index) }}