Skip to content

Commit

Permalink
Merge pull request #1228 from DarkFlorist/lint
Browse files Browse the repository at this point in the history
lint
  • Loading branch information
KillariDev authored Dec 13, 2024
2 parents c530822 + a546eb4 commit 35ff8c7
Show file tree
Hide file tree
Showing 32 changed files with 57 additions and 127 deletions.
6 changes: 3 additions & 3 deletions app/ts/AddressBook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export function AddressBook() {
? <DynamicScroller
items = { addressBookEntries }
renderItem = { addressBookEntry => (
<AddressBookEntryCard { ...addressBookEntry } category = { addressBookEntriesWithFilter.value.activeFilter } removeEntry = { () => modalState.value = { page: 'confirmaddressBookEntryToBeRemoved', addressBookEntry } } renameAddressCallBack = { renameAddressCallBack } />
<AddressBookEntryCard { ...addressBookEntry } category = { addressBookEntriesWithFilter.value.activeFilter } removeEntry = { () => { modalState.value = { page: 'confirmaddressBookEntryToBeRemoved', addressBookEntry } } } renameAddressCallBack = { renameAddressCallBack } />
) }
/>
: <GetNoResultsError/>
Expand All @@ -371,7 +371,7 @@ export function AddressBook() {
<AddNewAddress
setActiveAddressAndInformAboutIt = { undefined }
modifyAddressWindowState = { modifyAddressSignal }
close = { () => modalState.value = { page: 'noModal' } }
close = { () => { modalState.value = { page: 'noModal' } } }
activeAddress = { undefined }
rpcEntries = { rpcEntries }
modifyStateCallBack = { (newState: ModifyAddressWindowState) => {
Expand All @@ -385,7 +385,7 @@ export function AddressBook() {
category = { viewFilter.value.activeFilter }
addressBookEntry = { modalState.value.addressBookEntry }
removeEntry = { removeAddressBookEntry }
close = { () => modalState.value = { page: 'noModal' } }
close = { () => { modalState.value = { page: 'noModal' } } }
renameAddressCallBack = { renameAddressCallBack }
/>
: <></> }
Expand Down
2 changes: 1 addition & 1 deletion app/ts/background/metadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const addNewEnsNameEntry = async (name: string) => {
await addEnsNodeHash(name)
}

export const getAndCacheEnsNodeHash = async (ethereumClientService: EthereumClientService, ensNameHash: EthereumBytes32, extraNameHashes: ENSNameHashes) => {
const getAndCacheEnsNodeHash = async (ethereumClientService: EthereumClientService, ensNameHash: EthereumBytes32, extraNameHashes: ENSNameHashes) => {
const currentHashes = [ENS_ADDR_REVERSE_NODE, ...await getEnsNodeHashes()]
const entry = currentHashes.find((entry) => entry.nameHash === ensNameHash)
if (entry !== undefined) return entry
Expand Down
4 changes: 2 additions & 2 deletions app/ts/components/pages/InterceptorAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export function InterceptorAccess() {
? <AddNewAddress
setActiveAddressAndInformAboutIt = { (address: bigint | 'signer') => setActiveAddressAndInformAboutIt(appPage.value.accessRequestId, address) }
modifyAddressWindowState = { modifyAddressSignal }
close = { () => appPage.value = { page: { page: 'Home' }, accessRequestId: '' } }
close = { () => { appPage.value = { page: { page: 'Home' }, accessRequestId: '' } } }
activeAddress = { pendingAccessRequest.requestAccessToAddress?.address }
rpcEntries = { rpcEntries }
modifyStateCallBack = { (newState: ModifyAddressWindowState) => {
Expand All @@ -340,7 +340,7 @@ export function InterceptorAccess() {
? <ChangeActiveAddress
setActiveAddressAndInformAboutIt = { (address: bigint | 'signer') => setActiveAddressAndInformAboutIt(appPage.value.accessRequestId, address) }
signerAccounts = { pendingAccessRequest.signerAccounts }
close = { () => appPage.value = { page: { page: 'Home' }, accessRequestId: '' } }
close = { () => { appPage.value = { page: { page: 'Home' }, accessRequestId: '' } } }
activeAddresses = { activeAddresses }
signerName = { pendingAccessRequest.signerName }
renameAddressCallBack = { (entry: AddressBookEntry) => renameAddressCallBack(appPage.value.accessRequestId, entry) }
Expand Down
2 changes: 1 addition & 1 deletion app/ts/components/pages/WebsiteAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ const BlockRequestSetting = ({ websiteAccess }: { websiteAccess: Signal<WebsiteA

const DisableProtectionSetting = ({ websiteAccess }: { websiteAccess: Signal<WebsiteAccess> }) => {

const disableWebsiteProtection = async (shouldDisable: boolean = true) => {
const disableWebsiteProtection = async (shouldDisable = true) => {
if (!websiteAccess.value) return
sendPopupMessageToBackgroundPage({ method: 'popup_setDisableInterceptor', data: { website: websiteAccess.value.website, interceptorDisabled: shouldDisable } })
}
Expand Down
2 changes: 1 addition & 1 deletion app/ts/components/simulationExplaining/Transactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ function NonTokenLogEvent(params: NonTokenLogEventParams) {
return <>
<p style = { textStyle } class = 'paragraph'> { `${ arg.paramName } = [` }</p>
<StringElement text = { params.nonTokenLog.logInformation.fuses.join(', ') } />
<p style = { textStyle } class = 'paragraph'> { `]` }</p>
<p style = { textStyle } class = 'paragraph'>]</p>
</>
}
return <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { UniqueRequestIdentifier } from '../../utils/requests.js'
import { findDeadEnds } from '../../utils/findDeadEnds.js'
import { EthereumAddress, EthereumQuantity } from '../../types/wire-types.js'
import { extractTokenEvents } from '../../background/metadataUtils.js'
import { TokenVisualizerErc1155Event, TokenVisualizerErc20Event, TokenVisualizerErc721Event } from '../../types/EnrichedEthereumData.js'

type IdentifiedTransactionBase = {
title: string
Expand Down Expand Up @@ -146,9 +145,6 @@ function isSimpleTokenApproval(simTx: SimulatedAndVisualizedTransaction): simTx
}
const getSimpleTokenApprovalOrUndefined = createGuard<SimulatedAndVisualizedTransaction, SimulatedAndVisualizedSimpleApprovalTransaction>((simTx) => isSimpleTokenApproval(simTx) ? simTx : undefined)

export type TokenResult = funtypes.Static<typeof TokenResult>
export const TokenResult = funtypes.Intersect(funtypes.Union(TokenVisualizerErc20Event, TokenVisualizerErc721Event, TokenVisualizerErc1155Event), funtypes.ReadonlyObject({ isApproval: funtypes.Literal(false) }))

export type SimulatedAndVisualizedSimpleTokenTransferTransaction = funtypes.Static<typeof SimulatedAndVisualizedSimpleTokenTransferTransaction>
export const SimulatedAndVisualizedSimpleTokenTransferTransaction = funtypes.Intersect(
SimulatedAndVisualizedTransactionBase,
Expand Down
4 changes: 2 additions & 2 deletions app/ts/components/subcomponents/AutosizingInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function ParsedInput<T>(model: ParsedInputModel<T>) {
// we want to pass through all model values *except* the rawValue, which may contain a password
const inputModel = { ...model }
delete inputModel.rawValue
return <input { ...inputModel } class = 'autosizing-input' value = { internalValue } onInput = { event => internalValue.value = event.currentTarget.value } onChange = { onChange }/>
return <input { ...inputModel } class = 'autosizing-input' value = { internalValue } onInput = { event => { internalValue.value = event.currentTarget.value } } onChange = { onChange }/>
}

function Input<T>(model: UnparsedInputModel | ParsedInputModel<T>) {
Expand All @@ -73,7 +73,7 @@ interface BaseAutosizingInputModel extends Pick<JSX.HTMLAttributes<HTMLSpanEleme
interface UnparsedAutosizingInputModel extends BaseAutosizingInputModel, Pick<UnparsedInputModel, 'value' | 'sanitize' | 'tryParse' | 'serialize'> {}
interface ParsedAutosizingInputModel<T> extends BaseAutosizingInputModel, Pick<ParsedInputModel<T>, 'value' | 'sanitize' | 'tryParse' | 'serialize'> {}

export function AutosizingInput<T>(model: UnparsedAutosizingInputModel | ParsedAutosizingInputModel<T>) {
function AutosizingInput<T>(model: UnparsedAutosizingInputModel | ParsedAutosizingInputModel<T>) {
const internalValue = model.rawValue || useSignal(model.serialize ? model.serialize(model.value.deepPeek()) : model.value.peek())
const inputModel = {
rawValue: internalValue,
Expand Down
8 changes: 4 additions & 4 deletions app/ts/components/subcomponents/ConfigureRpcConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ const RpcUrlField = ({ defaultValue }: { defaultValue?: string }) => {
return <TextInput ref = { inputRef } label = 'RPC URL *' name = 'httpsRpc' defaultValue = { defaultValue } onInput = { (e) => deferredQueryAnRpcUrl(e.currentTarget.value) } statusIcon = { <StatusIcon state = { rpcQuery.value.state } /> } style = '--area: 1 / span 2' required autoComplete = 'off' autoFocus = { defaultValue === undefined } readOnly = { defaultValue !== undefined } />
}

export const StatusIcon = ({ state }: { state: AsyncStates }) => {
const StatusIcon = ({ state }: { state: AsyncStates }) => {
switch (state) {
case 'inactive': return <></>
case 'pending': return <SpinnerIcon />
Expand All @@ -322,19 +322,19 @@ export const StatusIcon = ({ state }: { state: AsyncStates }) => {
}
}

export const SpinnerIcon = () => (
const SpinnerIcon = () => (
<svg class = 'spin' width = '1em' height = '1em' viewBox = '0 0 16 16' fill = 'none' xmlns = 'http://www.w3.org/2000/svg'>
<circle cx = '8' cy = '8' r = '6.5' stroke = 'var(--text-color, currentColor)' stroke-opacity = '.5' stroke-width = '3' />
<path d = 'M8 0a8 8 0 1 0 8 8h-3a5 5 0 1 1-5-5z' fill = 'var(--text-color, currentColor)' fill-opacity = '.4' />
</svg>
)

export const CheckIcon = () => (
const CheckIcon = () => (
<svg width = '1em' height = '1em' viewBox = '0 0 16 16' fill = 'none' xmlns = 'http://www.w3.org/2000/svg' >
<path d = 'M15 3L5.64686 12.5524L1 7.84615' stroke = 'var(--positive-color, currentColor)' strokeWidth = { 2 } />
</svg>
)

export const Trash = () => (
const Trash = () => (
<svg xmlns = 'http://www.w3.org/2000/svg' width = '1em' height = '1em' viewBox = '0 0 32 32'><path fill = 'currentColor' d = 'M15 4c-.522 0-1.06.185-1.438.563S13 5.478 13 6v1H7v2h1v16c0 1.645 1.355 3 3 3h12c1.645 0 3-1.355 3-3V9h1V7h-6V6c0-.522-.185-1.06-.563-1.438C20.06 4.186 19.523 4 19 4zm0 2h4v1h-4zm-5 3h14v16c0 .555-.445 1-1 1H11c-.555 0-1-.445-1-1zm2 3v11h2V12zm4 0v11h2V12zm4 0v11h2V12z' /></svg>
)
2 changes: 1 addition & 1 deletion app/ts/components/subcomponents/InlineCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { clipboardCopy } from './clipboardcopy.js'
import { CopyIcon, EditIcon } from './icons.js'
import { Tooltip, TooltipConfig } from './Tooltip.js'

export type InlineCardProps = {
type InlineCardProps = {
icon: () => JSX.Element
label: string
copyValue?: string
Expand Down
2 changes: 1 addition & 1 deletion app/ts/components/subcomponents/MultilineCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Tooltip, TooltipConfig } from './Tooltip.js'
import { clipboardCopy } from './clipboardcopy.js'
import { CopyIcon } from './icons.js'

export type MultilineCardProps = {
type MultilineCardProps = {
icon: ActionableIconProps
label: ActionableTextProps
note: ActionableTextProps
Expand Down
2 changes: 1 addition & 1 deletion app/ts/components/subcomponents/SVGBlockie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function generateIdenticon(options: { address: bigint; size?: number }) {
return { imageData, color, bgcolor, spotcolor }
}

export type SVGBlockieProps = {
type SVGBlockieProps = {
style?: JSX.CSSProperties
address: bigint
}
Expand Down
2 changes: 1 addition & 1 deletion app/ts/components/subcomponents/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function Tooltip({ config }: { config: Signal<TooltipConfig | undefined>
}

popoverRef.current?.showPopover()
setTimeout(() => config.value = undefined, config.value.duration || 1500)
setTimeout(() => { config.value = undefined }, config.value.duration || 1500)
})

return (
Expand Down
2 changes: 0 additions & 2 deletions app/ts/components/subcomponents/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,4 @@ export const CopyIcon = () => <svg width = '1em' height = '1em' viewBox = '0 0 2

export const EditIcon = () => <svg width = '1em' height = '1em' viewBox = '0 0 24 24' fill = 'none' xmlns = 'http://www.w3.org/2000/svg'><path fill-rule = 'evenodd' clip-rule = 'evenodd' d = 'M10 3H7v2H4a3 3 0 0 0-3 3v8a3 3 0 0 0 3 3h3v2h3zM7 8v8H5a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z' fill = 'currentColor' /><path d = 'M19 16h-7v3h8a3 3 0 0 0 3-3V8a3 3 0 0 0-3-3h-8v3h7a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1' fill = 'currentColor' /></svg>

export const CheckIcon = () => <svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M22.08 6.04 8.478 20.163l-6.558-6.81 2.16-2.081 4.398 4.566L19.92 3.959z" fill="currentColor"/></svg>

export const ChevronIcon = () => <svg role = 'img' aria-label = 'chevron-icon' width = '1em' height = '1em' viewBox = '0 0 16 16' fill = 'none' xmlns = 'http://www.w3.org/2000/svg'><path d = 'm2 5.333 6 6 6-6' stroke = 'currentColor' strokeWidth = { 1.5 } /></svg>
2 changes: 1 addition & 1 deletion app/ts/simulation/logHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ function decodeENSName(encodedName: Uint8Array): string {
const length = encodedName[i]
if (length === 0 || length === undefined) break
i++
let label = new TextDecoder().decode(encodedName.slice(i, i + length))
const label = new TextDecoder().decode(encodedName.slice(i, i + length))
decodedName += label + '.'
i += length
}
Expand Down
2 changes: 1 addition & 1 deletion app/ts/simulation/services/EtherScanAbiFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function isValidAbi(abi: string) {
}
}

export function getBlockExplorer(chainId: ChainIdWithUniversal, rpcEntries: RpcEntries) {
function getBlockExplorer(chainId: ChainIdWithUniversal, rpcEntries: RpcEntries) {
if (chainId === 'AllChains') return undefined
const primaryRpc = rpcEntries.find((rpc) => rpc.chainId === chainId && rpc.primary)
if (primaryRpc !== undefined && primaryRpc.blockExplorer !== undefined) return primaryRpc.blockExplorer
Expand Down
2 changes: 1 addition & 1 deletion app/ts/simulation/services/LogSummarizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AddressBookEntry, Erc1155Entry, Erc721Entry } from '../../types/address
import { ETHEREUM_LOGS_LOGGER_ADDRESS } from '../../utils/constants.js'
import { extractTokenEvents } from '../../background/metadataUtils.js'
import { TokenVisualizerResultWithMetadata } from '../../types/EnrichedEthereumData.js'
export type BalanceChangeSummary = {
type BalanceChangeSummary = {
erc20TokenBalanceChanges: Map<string, bigint>, // token address, amount
erc20TokenApprovalChanges: Map<string, Map<string, bigint > > // token address, approved address, amount

Expand Down
19 changes: 2 additions & 17 deletions app/ts/simulation/services/SimulationModeEthereumClientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EthereumUnsignedTransaction, EthereumSignedTransactionWithBlockData, Et
import { addressString, bigintToUint8Array, bytes32String, calculateWeightedPercentile, dataStringWith0xStart, max, min, stringToUint8Array } from '../../utils/bigint.js'
import { CANNOT_SIMULATE_OFF_LEGACY_BLOCK, ERROR_INTERCEPTOR_GAS_ESTIMATION_FAILED, ETHEREUM_LOGS_LOGGER_ADDRESS, ETHEREUM_EIP1559_BASEFEECHANGEDENOMINATOR, ETHEREUM_EIP1559_ELASTICITY_MULTIPLIER, MOCK_ADDRESS, MULTICALL3, Multicall3ABI, DEFAULT_CALL_ADDRESS, GAS_PER_BLOB, MAKE_YOU_RICH_TRANSACTION } from '../../utils/constants.js'
import { Interface, ethers, hashMessage, keccak256, } from 'ethers'
import { SimulatedTransaction, SimulationState, TokenBalancesAfter, EstimateGasError, SignedMessageTransaction, WebsiteCreatedEthereumUnsignedTransactionOrFailed, TransactionStack, PreSimulationTransaction } from '../../types/visualizer-types.js'
import { SimulatedTransaction, SimulationState, TokenBalancesAfter, EstimateGasError, WebsiteCreatedEthereumUnsignedTransactionOrFailed, TransactionStack, PreSimulationTransaction } from '../../types/visualizer-types.js'
import { EthereumUnsignedTransactionToUnsignedTransaction, IUnsignedTransaction1559, rlpEncode, serializeSignedTransactionToBytes } from '../../utils/ethereum.js'
import { EthGetLogsResponse, EthGetLogsRequest, EthTransactionReceiptResponse, DappRequestTransaction, EthGetFeeHistoryResponse, FeeHistory } from '../../types/JsonRpc-types.js'
import { handleERC1155TransferBatch, handleERC1155TransferSingle, handleERC20TransferLog } from '../logHandlers.js'
Expand Down Expand Up @@ -357,17 +357,6 @@ const getTransactionQueue = (simulationState: SimulationState | undefined) => {
return simulationState.simulatedTransactions.map((x) => x.preSimulationTransaction.signedTransaction)
}

export const getEmptySimulationStateWithRichAddress = (ethereumClientService: EthereumClientService, addressToMakeRich: EthereumAddress | undefined, oldSimulationState: SimulationState | undefined): SimulationState => ({
addressToMakeRich,
simulatedTransactions: [],
blockNumber: oldSimulationState?.blockNumber || 0n,
blockTimestamp: new Date(),
rpcNetwork: ethereumClientService.getRpcEntry(),
simulationConductedTimestamp: new Date(),
signedMessages: [],
baseFeePerGas: 0n,
})

export const getNonceFixedSimulatedTransactions = async(ethereumClientService: EthereumClientService, requestAbortController: AbortController | undefined, simulatedTransactions: readonly SimulatedTransaction[]) => {
const isFixableNonceError = (transaction: SimulatedTransaction) => {
return transaction.ethSimulateV1CallResult.status === 'failure'
Expand Down Expand Up @@ -726,7 +715,7 @@ const getSignedMessagesWithFakeSigner = (simulationState: SimulationState | unde
return simulationState === undefined ? [] : simulationState.signedMessages.map((x) => ({ fakeSignedFor: x.fakeSignedFor, originalRequestParameters: x.originalRequestParameters }))
}

const simulatedMulticall = async (ethereumClientService: EthereumClientService, requestAbortController: AbortController | undefined, simulationState: SimulationState | undefined, transactions: EthereumUnsignedTransaction[], blockNumber: bigint, extraAccountOverrides: StateOverrides = {}, simulateOnBlockAboveExistingSimulationStack: boolean = false) => {
const simulatedMulticall = async (ethereumClientService: EthereumClientService, requestAbortController: AbortController | undefined, simulationState: SimulationState | undefined, transactions: EthereumUnsignedTransaction[], blockNumber: bigint, extraAccountOverrides: StateOverrides = {}, simulateOnBlockAboveExistingSimulationStack = false) => {
const mergedTxs: EthereumUnsignedTransaction[] = getTransactionQueue(simulationState)
const makeMeRich = getMakeMeRichStateOverride(simulationState?.addressToMakeRich)
const transactionsInBlocks = simulateOnBlockAboveExistingSimulationStack ? [mergedTxs, transactions] : [mergedTxs.concat(transactions)]
Expand Down Expand Up @@ -957,10 +946,6 @@ export const getTokenBalancesAfter = async (
return await Promise.all(tokenBalancesAfter)
}

export const appendSignedMessage = async (simulationState: SimulationState, signedMessage: SignedMessageTransaction): Promise<SimulationState> => {
return modifyObject(simulationState, { signedMessages: simulationState.signedMessages.concat(signedMessage) })
}

// takes the most recent block that the application is querying and does the calculation based on that
export const getSimulatedFeeHistory = async (ethereumClientService: EthereumClientService, requestAbortController: AbortController | undefined, request: FeeHistory): Promise<EthGetFeeHistoryResponse> => {
//const numberOfBlocks = Number(request.params[0]) // number of blocks, not used atm as we just return one block
Expand Down
5 changes: 2 additions & 3 deletions app/ts/simulation/services/priceEstimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ interface CachedTokenPriceEstimate {
}
const IMulticall3 = new Interface(Multicall3ABI)

export type ITokenPriceService = Pick<TokenPriceService, keyof TokenPriceService>
export class TokenPriceService {
private cachedPrices = new Map<string, Map<string, CachedTokenPriceEstimate> > // quoteTokenAddress -> tokenAddress -> TokenPriceEstimate
public cacheAge: number
Expand All @@ -39,7 +38,7 @@ export class TokenPriceService {
if (quoteTokenAddressCache.size === 0) this.cachedPrices.delete(quoteTokenAddressString)
})
}

private async getTokenPrice(requestAbortController: AbortController | undefined, token: TokenDecimals, quoteToken: Erc20TokenEntry) {
const poolAddresses = calculateUniswapLikePools(token.address, quoteToken.address)
if (!poolAddresses) return undefined
Expand All @@ -50,7 +49,7 @@ export class TokenPriceService {
const callTransaction = { type: '1559', to: MULTICALL3, value: 0n, input: callData, }
const multicallReturnData: { success: boolean, returnData: string }[] = IMulticall3.decodeFunctionResult('aggregate3', await this.ethereumClientService.call(callTransaction, 'latest', requestAbortController))[0]
const prices = calculatePricesFromUniswapLikeReturnData(multicallReturnData, poolAddresses)
if (prices.length === 0) return undefined
if (prices.length === 0) return undefined
return {
token,
quoteToken,
Expand Down
Loading

0 comments on commit 35ff8c7

Please sign in to comment.