Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: components from jsx to tsx #509

Merged
merged 8 commits into from
Sep 26, 2022
29 changes: 0 additions & 29 deletions src/components/ActivityIndicators.jsx

This file was deleted.

44 changes: 44 additions & 0 deletions src/components/ActivityIndicators.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { PropsWithChildren } from 'react'
import classNames from 'classnames'
import Sprite from './Sprite'

interface ActivityIndicatorProps {
isOn: boolean
}

function ActivityIndicator({ isOn, children }: PropsWithChildren<ActivityIndicatorProps>) {
return (
<span className={`activity-indicator ${isOn ? 'activity-indicator-on' : 'activity-indicator-off'}`}>
{children}
</span>
)
}

interface JoiningIndicatorProps {
isOn: boolean
size: number
className?: string
}

export function JoiningIndicator({ isOn, size = 30, className = '', ...props }: JoiningIndicatorProps) {
return (
<span className="joining-indicator">
<ActivityIndicator isOn={isOn}>
{isOn && <Sprite symbol="joining" width={size} height={size} className={`p-1 ${className}`} {...props} />}
</ActivityIndicator>
</span>
)
}

interface TabActivityIndicatorProps {
isOn: boolean
className?: string
}

export function TabActivityIndicator({ isOn, className }: TabActivityIndicatorProps) {
return (
<span className={classNames('earn-indicator', className)}>
<ActivityIndicator isOn={isOn} />
</span>
)
}
22 changes: 0 additions & 22 deletions src/components/Alert.jsx

This file was deleted.

22 changes: 22 additions & 0 deletions src/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useState } from 'react'
import { Alert as BsAlert, AlertProps as BsAlertProps } from 'react-bootstrap'

export type SimpleMessageAlertProps = BsAlertProps & { message: string }

export default function Alert({ message, onClose, ...props }: SimpleMessageAlertProps) {
const [show, setShow] = useState(true)

return (
<BsAlert
className="my-3"
onClose={(a: any, b: any) => {
setShow(false)
onClose && onClose(a, b)
}}
show={show}
{...props}
>
{message}
</BsAlert>
)
}
3 changes: 1 addition & 2 deletions src/components/App.test.jsx → src/components/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { render, screen } from '../testUtils'
import { act } from 'react-dom/test-utils'
import user from '@testing-library/user-event'
Expand All @@ -14,7 +13,7 @@ jest.mock('../libs/JmWalletApi', () => ({
describe('<App />', () => {
beforeEach(() => {
const neverResolvingPromise = new Promise(() => {})
apiMock.getSession.mockResolvedValue(neverResolvingPromise)
;(apiMock.getSession as jest.Mock).mockResolvedValue(neverResolvingPromise)
})

it('should display Onboarding screen initially', () => {
Expand Down
28 changes: 14 additions & 14 deletions src/components/App.jsx → src/components/App.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import React, { useCallback } from 'react'
import { Route, Routes, Navigate } from 'react-router-dom'
import { useCallback } from 'react'
import * as rb from 'react-bootstrap'
import { useTranslation } from 'react-i18next'
import Wallets from './Wallets'
import { Navigate, Route, Routes } from 'react-router-dom'
import { routes } from '../constants/routes'
import { useSessionConnectionError } from '../context/ServiceInfoContext'
import { useSettings } from '../context/SettingsContext'
import { useCurrentWallet, useSetCurrentWallet } from '../context/WalletContext'
import { clearSession, setSession } from '../session'
import CreateWallet from './CreateWallet'
import Jam from './Jam'
import Send from './Send'
import Earn from './Earn'
import Receive from './Receive'
import MainWalletView from './MainWalletView'
import Settings from './Settings'
import Footer from './Footer'
import Jam from './Jam'
import Layout from './Layout'
import MainWalletView from './MainWalletView'
import Navbar from './Navbar'
import Footer from './Footer'
import Onboarding from './Onboarding'
import { useSettings } from '../context/SettingsContext'
import { useCurrentWallet, useSetCurrentWallet } from '../context/WalletContext'
import { useSessionConnectionError } from '../context/ServiceInfoContext'
import { setSession, clearSession } from '../session'
import { routes } from '../constants/routes'
import Receive from './Receive'
import Send from './Send'
import Settings from './Settings'
import Wallets from './Wallets'

export default function App() {
const { t } = useTranslation()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
import React, { useState, useMemo } from 'react'
import { useState, useMemo } from 'react'
import * as rb from 'react-bootstrap'
import { useTranslation } from 'react-i18next'
import styles from './JarSelectorModal.module.css'
import { JarIndex, calculateFillLevel, SelectableJar } from './jars/Jar'
import { AccountBalances } from '../context/BalanceSummary'
import { BalanceString } from '../context/WalletContext'
import Sprite from './Sprite'
import { calculateFillLevel, SelectableJar } from './jars/Jar'
import styles from './JarSelectorModal.module.css'

interface JarSelectorModalProps {
isShown: boolean
title: string
accountBalances: AccountBalances
totalBalance: BalanceString
disabledJar?: JarIndex
onCancel: () => void
onConfirm: (jarIndex: JarIndex) => void
}

export default function JarSelectorModal({
isShown,
title,
accountBalances,
totalBalance,
disabledJar = undefined,
disabledJar,
onCancel,
onConfirm,
}) {
}: JarSelectorModalProps) {
const { t } = useTranslation()

const [selectedJar, setSelectedJar] = useState(null)
const [selectedJar, setSelectedJar] = useState<JarIndex | null>(null)

const sortedAccountBalances = useMemo(() => {
if (!accountBalances) return []
Expand All @@ -29,9 +41,10 @@ export default function JarSelectorModal({
}

const confirm = () => {
const jar = selectedJar
if (selectedJar === null) return

onConfirm(selectedJar)
setSelectedJar(null)
onConfirm(jar)
}

return (
Expand Down
16 changes: 13 additions & 3 deletions src/components/Layout.jsx → src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react'
import { PropsWithChildren } from 'react'
import * as rb from 'react-bootstrap'
import { Outlet } from 'react-router-dom'

const Col = ({ variant, children }) => {
type LayoutVariant = 'wide' | ''

interface ColProps {
variant?: LayoutVariant
}

const Col = ({ variant, children }: PropsWithChildren<ColProps>) => {
if (variant === 'wide') {
return <rb.Col>{children}</rb.Col>
}
Expand All @@ -14,7 +20,11 @@ const Col = ({ variant, children }) => {
)
}

const Layout = ({ variant }) => {
interface LayoutProps {
variant?: LayoutVariant
}

const Layout = ({ variant }: LayoutProps) => {
return (
<rb.Row className="justify-content-center">
<Col variant={variant}>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Send.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useEffect, useState, useMemo, useRef } from 'react'
import { useEffect, useState, useMemo, useRef } from 'react'
import { Link, useLocation } from 'react-router-dom'
import { Trans, useTranslation } from 'react-i18next'
import * as rb from 'react-bootstrap'
import classnames from 'classnames/bind'
import classNames from 'classnames'
import PageTitle from './PageTitle'
import ToggleSwitch from './ToggleSwitch'
import Sprite from './Sprite'
Expand Down Expand Up @@ -97,7 +97,7 @@ const CollaboratorsSelector = ({ numCollaborators, setNumCollaborators, minNumCo
<rb.Button
key={number}
variant={settings.theme === 'light' ? 'white' : 'dark'}
className={classnames(
className={classNames(
styles['collaborators-selector-button'],
'p-2',
'border',
Expand Down Expand Up @@ -128,7 +128,7 @@ const CollaboratorsSelector = ({ numCollaborators, setNumCollaborators, minNumCo
isInvalid={!isValidNumCollaborators(numCollaborators, minNumCollaborators)}
placeholder={t('send.input_num_collaborators_placeholder')}
defaultValue=""
className={classnames(
className={classNames(
styles['collaborators-selector-input'],
'p-2',
'border',
Expand Down Expand Up @@ -796,7 +796,7 @@ export default function Send() {
<rb.Form.Control
name="destination"
placeholder={t('send.placeholder_recipient')}
className={classnames('slashed-zeroes', styles['input'], {
className={classNames('slashed-zeroes', styles['input'], {
[styles['jar-input']]: destinationJar !== null,
})}
value={destinationJar !== null ? `${jarName(destinationJar)} (${destination})` : destination || ''}
Expand Down
8 changes: 4 additions & 4 deletions src/components/Wallets.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useMemo, useEffect, useCallback, useState } from 'react'
import { useMemo, useEffect, useCallback, useState } from 'react'
import { Link, useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import * as rb from 'react-bootstrap'
import classnames from 'classnames/bind'
import classNames from 'classnames'
import Sprite from './Sprite'
import Alert from './Alert'
import Wallet from './Wallet'
import PageTitle from './PageTitle'
import { useServiceInfo, useReloadServiceInfo } from '../context/ServiceInfoContext'
import { useTranslation } from 'react-i18next'
import { walletDisplayName } from '../utils'
import * as Api from '../libs/JmWalletApi'
import { routes } from '../constants/routes'
Expand Down Expand Up @@ -233,7 +233,7 @@ export default function Wallets({ currentWallet, startWallet, stopWallet }) {
<div className="d-flex justify-content-center">
<Link
to={routes.createWallet}
className={classnames('btn', 'mt-4', {
className={classNames('btn', 'mt-4', {
'btn-lg': walletList?.length === 0,
'btn-dark': walletList?.length === 0,
'btn-outline-dark': !walletList || walletList.length > 0,
Expand Down
4 changes: 2 additions & 2 deletions src/components/fb/CreateFidelityBond.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useMemo } from 'react'
import { useState, useEffect, useMemo } from 'react'
import * as rb from 'react-bootstrap'
import * as Api from '../../libs/JmWalletApi'
import { Trans, useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -509,7 +509,7 @@ const CreateFidelityBond = ({ otherFidelityBondExists, accountBalances, totalBal

return (
<div className={styles.container}>
{alert && <Alert {...alert} className="mt-0" onDismissed={() => setAlert(null)} />}
{alert && <Alert {...alert} className="mt-0" onClose={() => setAlert(null)} />}
{lockDate && (
<ConfirmModal
isShown={showConfirmInputsModal}
Expand Down
Loading