Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadowfiend committed Jul 25, 2023
1 parent 6e58639 commit 81e5de9
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 45 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/pledge-signer-sync/pledge-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ if (!GALXE_ACCESS_TOKEN || !FIRESTORE_USER || !FIRESTORE_PASSWORD) {
// Limit sync range to last 4 days ( 2 days from last sync + 2 days from now )
const TARGET_DATE = new Date(Date.now() - 4 * 24 * 60 * 60_000)

const wait = (ms) => new Promise((r) => setTimeout(r, ms))
const wait = (ms) =>
new Promise((r) => {
setTimeout(r, ms)
})

const getAddresses = async () => {
const app = initializeApp({
Expand Down
3 changes: 2 additions & 1 deletion __mocks__/@ethersproject/web.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
// Fixing this here requires digging into Jest a bit, kicking for now.
// eslint-disable-next-line import/no-import-module-exports
import sinon from "sinon"

const mock =
Expand Down
2 changes: 2 additions & 0 deletions __mocks__/webextension-polyfill.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Fixing this here requires digging into Jest a bit, kicking for now.
// eslint-disable-next-line import/no-import-module-exports
import { Tabs } from "webextension-polyfill"

const browserMock = jest.createMockFromModule<
Expand Down
4 changes: 2 additions & 2 deletions background/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const reduxCache: Middleware = (store) => (next) => (action) => {

// Declared out here so ReduxStoreType can be used in Main.store type
// declaration.
const initializeStore = (preloadedState = {}, main: Main) =>
const initializeStore = (main: Main, preloadedState = {}) =>
configureStore({
preloadedState,
reducer: rootReducer,
Expand Down Expand Up @@ -506,7 +506,7 @@ export default class Main extends BaseService<never> {
})

// Start up the redux store and set it up for proxying.
this.store = initializeStore(savedReduxState, this)
this.store = initializeStore(this, savedReduxState)

const queueUpdate = debounce(
(lastState, newState, updateFn) => {
Expand Down
2 changes: 1 addition & 1 deletion background/services/chain/serial-fallback-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export default class SerialFallbackProvider extends JsonRpcProvider {
private subscriptions: {
tag: string
param: unknown[]
processFunc: (result: unknown) => void
processFunc: (_: unknown) => void
}[] = []

// Information on event subscriptions, which can be restored on non-WebSocket
Expand Down
3 changes: 2 additions & 1 deletion background/services/chain/tests/index.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ describe("Chain Service", () => {
it("should get block prices if the NETWORK_POLLING_TIMEOUT has been exceeded", async () => {
// Set last activity time to 10 minutes ago
const externalized = chainService as unknown as ChainServiceExternalized
externalized.lastUserActivityOnNetwork[ETHEREUM.chainID] = Date.now() - 10 * MINUTE
externalized.lastUserActivityOnNetwork[ETHEREUM.chainID] =
Date.now() - 10 * MINUTE
const getBlockPricesStub = sandbox
.stub(gas, "default")
.callsFake(async () => createBlockPrices())
Expand Down
2 changes: 1 addition & 1 deletion background/services/provider-bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export type AddChainRequestData = ValidatedAddEthereumChainParameter & {
*/
export default class ProviderBridgeService extends BaseService<Events> {
#pendingPermissionsRequests: {
[origin: string]: (value: unknown) => void
[origin: string]: (_: unknown) => void
} = {}

#pendingAddNetworkRequests: {
Expand Down
2 changes: 1 addition & 1 deletion ui/__mocks__/IntersectionObserver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default class IntersectionObserverMock {
callbackMap: Map<HTMLElement, (...args: unknown[]) => void> = new Map()
callbackMap: Map<HTMLElement, (..._: unknown[]) => void> = new Map()

constructor(
protected callback: (entry: [Partial<IntersectionObserverEntry>]) => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ type Props = {

export default function AccountsNotificationPanelAccounts({
onCurrentAddressChange,
}: Props): ReactElement {
}: Props): ReactElement | null {
const { t } = useTranslation()
const dispatch = useBackgroundDispatch()
const history = useHistory()
Expand Down Expand Up @@ -362,7 +362,7 @@ export default function AccountsNotificationPanelAccounts({

// If there are no account totals for the given type, skip the section.
if (accountTypeTotals === undefined || accountTypeTotals.length <= 0) {
return <></>
return null
}

const accountTotalsByType = accountTypeTotals.reduce(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React, { ReactElement } from "react"
import AccountsNotificationPanelNotificationItem from "./AccountsNotificationPanelNotificationItem"
import SharedButton from "../Shared/SharedButton"

// This file is currently still a stub, so using sample data.
/* eslint-disable react/no-array-index-key */

export default function AccountsNotificationPanelNotifications(): ReactElement {
return (
<>
Expand Down
4 changes: 2 additions & 2 deletions ui/components/Onboarding/OnboardingOpenClaimFlowBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function IneligibleCTAContent({
)
}

export default function OnboardingOpenClaimFlowBanner(): ReactElement {
export default function OnboardingOpenClaimFlowBanner(): ReactElement | null {
const claimAmount = useBackgroundSelector(selectEligibility).toString()
const isClaimLoading = useBackgroundSelector(selectEligibilityLoading)

Expand Down Expand Up @@ -266,7 +266,7 @@ export default function OnboardingOpenClaimFlowBanner(): ReactElement {
((!hasSomethingToClaim || isClaimLoading) &&
addresHasNothingToClaimClosed.split(";").includes(currentAddress))
)
return <></>
return null

if (isClaimLoading)
return (
Expand Down
24 changes: 19 additions & 5 deletions ui/components/Shared/SharedDropDown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { ReactElement, useRef, useState } from "react"
import React, {
ReactElement,
useCallback,
useMemo,
useRef,
useState,
} from "react"
import { useTranslation } from "react-i18next"
import { useOnClickOutside } from "../../hooks"
import AccountitemOptionLabel from "../AccountItem/AccountItemOptionLabel"
Expand Down Expand Up @@ -39,11 +45,19 @@ type ContentProps = {

function DropdownContainer({ children }: DropdownContainerProps): ReactElement {
const [isOpen, setIsOpen] = useState(false)
const dropdownToggle = useCallback(
(value?: boolean) =>
setIsOpen(value ?? ((existingValue) => !existingValue)),
[setIsOpen]
)

const contextValue: DropdownContextValue = {
isOpen,
toggle: (value) => setIsOpen(value ?? ((p) => !p)),
}
const contextValue: DropdownContextValue = useMemo<DropdownContextValue>(
() => ({
isOpen,
toggle: dropdownToggle,
}),
[isOpen, dropdownToggle]
)

return (
<DropdownContext.Provider value={contextValue}>
Expand Down
7 changes: 5 additions & 2 deletions ui/components/Shared/SharedSkeletonLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ export default function SharedSkeletonLoader(props: {
children?: ReactNode
isLoaded?: boolean
customStyles?: string
}): ReactElement | ReactNode {
}): ReactElement {
const { width, height, borderRadius, isLoaded, customStyles, children } =
props

if (isLoaded) return children
// Want to return a ReactElement to make this maximally easy to integrate,
// whereas children can be a ReactNode; Fragment will let us achieve that.
// eslint-disable-next-line react/jsx-no-useless-fragment
if (isLoaded) return <>{children}</>

return (
<div className={classNames("skeleton")} data-testid="loading_skeleton">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function TransactionDataPanelSwitcher({
transactionRequest,
}: {
transactionRequest: EnrichedEVMTransactionRequest
}): ReactElement {
}): ReactElement | null {
const switchablePanels = useSwitchablePanels([
{
name: "Details",
Expand All @@ -24,5 +24,5 @@ export default function TransactionDataPanelSwitcher({
},
])

return <>{switchablePanels}</>
return switchablePanels
}
28 changes: 16 additions & 12 deletions ui/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isAllowedQueryParamPage } from "@tallyho/provider-bridge-shared"

import { useState, useEffect, ReactElement, ReactNode } from "react"
import React, { useState, useEffect, ReactElement } from "react"
import { getAllAddresses } from "@tallyho/tally-background/redux-slices/selectors/accountsSelectors"
import SharedPanelSwitcher from "../components/Shared/SharedPanelSwitcher"
import { useBackgroundSelector } from "./redux-hooks"
Expand Down Expand Up @@ -41,7 +41,7 @@ type PanelDescriptor = {
* interchange between several screens exclusively from each other.
*
* The underlying component is a `SharedPanelSwitcher`, and the hook returns
* the switcher element and current panel being displayed as siblings for
* the switcher element and current panel being displayed as a fragment for
* adding to a JSX component.
*
* @example
Expand All @@ -65,20 +65,24 @@ type PanelDescriptor = {
* },
* ])
* return <>{switchablePanels}</>
* return switchablePanels
* ```
*/
export function useSwitchablePanels(panels: PanelDescriptor[]): ReactNode {
export function useSwitchablePanels(
panels: PanelDescriptor[]
): ReactElement | null {
const [panelNumber, setPanelNumber] = useState(0)

return [
SharedPanelSwitcher({
setPanelNumber,
panelNumber,
panelNames: panels.map(({ name }) => name),
}),
panels[panelNumber].panelElement(),
]
return React.Fragment({
children: [
SharedPanelSwitcher({
setPanelNumber,
panelNumber,
panelNames: panels.map(({ name }) => name),
}),
panels[panelNumber].panelElement(),
],
})
}

export function useIsOnboarding(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions ui/pages/Earn/DepositCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export const getDisplayAPR = (
}
return `${data.low} - ${data.high}`
}
return data.totalAPR
return data.totalAPR ?? ""
}

export default function EarnDepositedCard({
vault,
}: {
vault: AvailableVault
}): ReactElement {
}): ReactElement | null {
const { vaultAddress, icons, userDeposited, asset } = vault
const userDepositedAmount = fromFixedPointNumber(
{
Expand Down
2 changes: 1 addition & 1 deletion ui/pages/EarnDeposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
AccordionPoolInfoContent,
} from "./Earn/AccordionPoolInfo"

export default function EarnDeposit(): ReactElement {
export default function EarnDeposit(): ReactElement | null {
const storedInput = useBackgroundSelector(selectEarnInputAmount)
const account = useBackgroundSelector(selectCurrentAccount)
const accountBalances = useBackgroundSelector(selectCurrentAccountBalances)
Expand Down
14 changes: 6 additions & 8 deletions ui/pages/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,17 +212,15 @@ export function Main(): ReactElement {
.hide {
opacity: 0;
}
`}
</style>
{isDappPopup && (
<style jsx global>
{`
${isDappPopup &&
`
body {
height: 100%;
}
`}
</style>
)}
`}
`}
</style>
</>
)
}
Expand Down
2 changes: 1 addition & 1 deletion ui/routes/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type PageList = {
// Tricky to handle all props components are
// accepting here.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Component: (...args: any[]) => ReactElement
Component: (...args: any[]) => ReactElement | null
hasTabBar: boolean
hasTopBar: boolean
persistOnClose: boolean
Expand Down

0 comments on commit 81e5de9

Please sign in to comment.