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: Consistent use of walletName vs walletFileName #671

Merged
merged 18 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ca21455
dev(auth): add Single- and RefreshTokenContext types
theborakompanioni Sep 22, 2023
ee24a09
dev(auth): save auth context to session
theborakompanioni Sep 22, 2023
c273704
dev(auth): refresh token periodically
theborakompanioni Sep 22, 2023
e6880bf
dev(auth): maintain CurrentWallet reference when renewing auth token
theborakompanioni Sep 22, 2023
2c9a15f
dev(auth): add distinct method to parse auth props
theborakompanioni Oct 4, 2023
8a0fee6
refactor: consistent use of displayName vs walletFileName
theborakompanioni Oct 4, 2023
94f0130
refactor: Settings component from jsx to tsx
theborakompanioni Oct 4, 2023
5fe58d9
fix: pass wallet props properly
theborakompanioni Oct 4, 2023
fab1500
refactor: Wallets component from jsx to tsx
theborakompanioni Oct 4, 2023
4e7ff0e
refactor: Onboarding component from jsx to tsx
theborakompanioni Oct 4, 2023
3eedba6
refactor: ScheduleProgress component from jsx to tsx
theborakompanioni Oct 4, 2023
6235584
chore(i18n): consistent use of global.errors.reason_unknown
theborakompanioni Oct 5, 2023
0c4287b
refactor: CreateWallet component from jsx to tsx
theborakompanioni Oct 5, 2023
79e2efd
refactor: BitcoinQR from jsx to tsx
theborakompanioni Oct 5, 2023
1762da3
refactor: Receive component from jsx to tsx
theborakompanioni Oct 5, 2023
9834c73
refactor: Earn component from jsx to tsx
theborakompanioni Oct 5, 2023
2c56940
dev(regtest): switch to python:3.11-slim-bookworm as base image
theborakompanioni Oct 8, 2023
841e120
chore(dev): do not log error when fetch was aborted
theborakompanioni Oct 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM debian:bullseye-20220801-slim
FROM python:3.11-slim-bookworm

RUN apt-get update \
&& apt-get install -qq --no-install-recommends gnupg tini procps vim git iproute2 supervisor \
# joinmarket dependencies
curl build-essential automake pkg-config libtool python3-dev python3-venv python3-pip python3-setuptools libltdl-dev \
curl build-essential automake pkg-config libtool libltdl-dev \
tor \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -14,7 +14,7 @@ ENV REPO_REF master
WORKDIR /src
RUN git clone "$REPO" . --depth=10 --branch "$REPO_BRANCH" && git checkout "$REPO_REF"

RUN ./install.sh --docker-install --disable-secp-check --without-qt
RUN ./install.sh --docker-install --disable-os-deps-check --disable-secp-check --without-qt

ENV DATADIR /root/.joinmarket
ENV CONFIG ${DATADIR}/joinmarket.cfg
Expand Down
6 changes: 3 additions & 3 deletions docker/regtest/dockerfile-deps/joinmarket/latest/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM debian:bullseye-20220801-slim
FROM python:3.11-slim-bookworm

RUN apt-get update \
&& apt-get install -qq --no-install-recommends gnupg tini procps vim git iproute2 supervisor \
# joinmarket dependencies
curl build-essential automake pkg-config libtool python3-dev python3-venv python3-pip python3-setuptools libltdl-dev \
curl build-essential automake pkg-config libtool libltdl-dev \
tor \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -14,7 +14,7 @@ ENV REPO_REF master
WORKDIR /src
RUN git clone "$REPO" . --depth=10 --branch "$REPO_BRANCH" && git checkout "$REPO_REF"

RUN ./install.sh --docker-install --disable-secp-check --without-qt
RUN ./install.sh --docker-install --disable-os-deps-check --disable-secp-check --without-qt

ENV DATADIR /root/.joinmarket
ENV CONFIG ${DATADIR}/joinmarket.cfg
Expand Down
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^29.0.3",
"@types/node": "^17.0.35",
"@types/qrcode": "^1.5.2",
"@types/react": "^17.0.43",
"@types/react-dom": "^17.0.14",
"conventional-changelog": "^3.1.25",
Expand Down
6 changes: 3 additions & 3 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export default function App() {
const isReloadingWalletInfo = useMemo(() => reloadingWalletInfoCounter > 0, [reloadingWalletInfoCounter])

const startWallet = useCallback(
(name: Api.WalletName, auth: Api.ApiAuthContext) => {
setSession({ name, auth })
setCurrentWallet({ name, token: auth.token })
(walletFileName: Api.WalletFileName, auth: Api.ApiAuthContext) => {
setSession({ walletFileName, auth })
setCurrentWallet({ walletFileName, token: auth.token })
},
[setCurrentWallet],
)
Expand Down
33 changes: 0 additions & 33 deletions src/components/BitcoinQR.jsx

This file was deleted.

41 changes: 41 additions & 0 deletions src/components/BitcoinQR.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useEffect, useState } from 'react'
import QRCode from 'qrcode'

import { satsToBtc } from '../utils'
import { AmountSats, BitcoinAddress } from '../libs/JmWalletApi'

interface BitcoinQRProps {
address: BitcoinAddress
amount?: AmountSats
errorCorrectionLevel?: QRCode.QRCodeErrorCorrectionLevel
width?: number
}

export const BitcoinQR = ({ address, amount, errorCorrectionLevel = 'H', width = 260 }: BitcoinQRProps) => {
const [data, setData] = useState<string>()
const [image, setImage] = useState<string>()

useEffect(() => {
const btc = amount ? satsToBtc(String(amount)) || 0 : 0
const uri = `bitcoin:${address}${btc > 0 ? `?amount=${btc.toFixed(8)}` : ''}`

QRCode.toDataURL(uri, {
errorCorrectionLevel,
width,
})
.then((val) => {
setImage(val)
setData(uri)
})
.catch(() => {
setImage(undefined)
setData(uri)
})
}, [address, amount, errorCorrectionLevel, width])

return (
<div>
<img src={image} alt={data} title={data} />
</div>
)
}
15 changes: 14 additions & 1 deletion src/components/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,25 @@ interface CopyableProps {
onSuccess?: () => void
onError?: (e: Error) => void
className?: string
disabled?: boolean
}

function Copyable({ value, onSuccess, onError, className, children, ...props }: PropsWithChildren<CopyableProps>) {
function Copyable({
value,
onSuccess,
onError,
className,
children,
disabled,
...props
}: PropsWithChildren<CopyableProps>) {
const valueFallbackInputRef = useRef(null)

return (
<>
<button
{...props}
disabled={disabled}
className={className}
onClick={() => copyToClipboard(value, valueFallbackInputRef.current!).then(onSuccess, onError)}
>
Expand All @@ -71,6 +81,7 @@ interface CopyButtonProps extends CopyableProps {
text: ReactNode
successText?: ReactNode
successTextTimeout?: number
disabled?: boolean
}

export function CopyButton({
Expand All @@ -81,6 +92,7 @@ export function CopyButton({
successText = text,
successTextTimeout = 1_500,
className,
disabled,
...props
}: CopyButtonProps) {
const [showValueCopiedConfirmation, setShowValueCopiedConfirmation] = useState(false)
Expand All @@ -100,6 +112,7 @@ export function CopyButton({
return (
<Copyable
{...props}
disabled={disabled}
className={`btn ${className || ''}`}
value={value}
onError={onError}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@ describe('<CreateWallet />', () => {
const testWalletName = 'wallet'
const testWalletPassword = 'correct horse battery staple'

const setup = (props) => {
const startWallet = props?.startWallet || NOOP
const setup = ({
startWallet = NOOP,
}: {
startWallet?: (name: apiMock.WalletFileName, auth: apiMock.ApiAuthContext) => void
}) => {
render(
<BrowserRouter>
<CreateWallet startWallet={startWallet} />
<CreateWallet startWallet={startWallet} parentRoute="home" />
</BrowserRouter>,
)
}

beforeEach(() => {
const neverResolvingPromise = new Promise(() => {})
apiMock.getGetinfo.mockResolvedValue(neverResolvingPromise)
apiMock.getSession.mockResolvedValue(neverResolvingPromise)
;(apiMock.getGetinfo as jest.Mock).mockResolvedValue(neverResolvingPromise)
;(apiMock.getSession as jest.Mock).mockResolvedValue(neverResolvingPromise)
})

it('should render without errors', () => {
act(setup)
act(() => setup({}))

expect(screen.getByText('create_wallet.title')).toBeVisible()
expect(screen.getByLabelText('create_wallet.label_wallet_name')).toBeVisible()
Expand All @@ -51,7 +54,7 @@ describe('<CreateWallet />', () => {
})

it('should show validation messages to user if form is invalid', async () => {
act(setup)
act(() => setup({}))

expect(await screen.findByText('create_wallet.button_create')).toBeVisible()

Expand All @@ -67,7 +70,7 @@ describe('<CreateWallet />', () => {
})

it('should not submit form if passwords do not match', async () => {
act(setup)
act(() => setup({}))

expect(await screen.findByPlaceholderText('create_wallet.placeholder_password')).toBeVisible()
expect(await screen.findByPlaceholderText('create_wallet.placeholder_password_confirm')).toBeVisible()
Expand All @@ -89,7 +92,7 @@ describe('<CreateWallet />', () => {
})

it('should advance to WalletCreationConfirmation after wallet is created', async () => {
apiMock.postWalletCreate.mockResolvedValueOnce({
;(apiMock.postWalletCreate as jest.Mock).mockResolvedValueOnce({
ok: true,
json: () =>
Promise.resolve({
Expand All @@ -99,7 +102,7 @@ describe('<CreateWallet />', () => {
}),
})

act(setup)
act(() => setup({}))

expect(await screen.findByText('create_wallet.button_create')).toBeVisible()
expect(await screen.queryByText('create_wallet.title_wallet_created')).not.toBeInTheDocument()
Expand All @@ -122,7 +125,7 @@ describe('<CreateWallet />', () => {
})

it('should verify that "skip" button is NOT visible by default (feature is disabled)', async () => {
apiMock.postWalletCreate.mockResolvedValueOnce({
;(apiMock.postWalletCreate as jest.Mock).mockResolvedValueOnce({
ok: true,
json: () =>
Promise.resolve({
Expand All @@ -132,7 +135,7 @@ describe('<CreateWallet />', () => {
}),
})

act(setup)
act(() => setup({}))

act(() => {
user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), testWalletName)
Expand Down Expand Up @@ -163,8 +166,7 @@ describe('<CreateWallet />', () => {

it('should verify that "skip" button IS visible when feature is enabled', async () => {
__testSetDebugFeatureEnabled('skipWalletBackupConfirmation', true)

apiMock.postWalletCreate.mockResolvedValueOnce({
;(apiMock.postWalletCreate as jest.Mock).mockResolvedValueOnce({
ok: true,
json: () =>
Promise.resolve({
Expand All @@ -174,7 +176,7 @@ describe('<CreateWallet />', () => {
}),
})

act(setup)
act(() => setup({}))

act(() => {
user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), testWalletName)
Expand Down
Loading