From 11ee5b4fa35e3ba77ae501916010d06418b318f3 Mon Sep 17 00:00:00 2001 From: Thebora Kompanioni Date: Sun, 8 Oct 2023 15:44:31 +0200 Subject: [PATCH] refactor: Consistent use of `walletName` vs `walletFileName` (#671) * refactor: consistent use of displayName vs walletFileName * refactor: Settings component from jsx to tsx * refactor: Wallets component from jsx to tsx * refactor: Onboarding component from jsx to tsx * refactor: ScheduleProgress component from jsx to tsx * chore(i18n): consistent use of global.errors.reason_unknown * refactor: CreateWallet component from jsx to tsx * refactor: BitcoinQR from jsx to tsx * refactor: Receive component from jsx to tsx * refactor: Earn component from jsx to tsx * dev(regtest): switch to python:3.11-slim-bookworm as base image see https://github.com/JoinMarket-Org/joinmarket-clientserver/pull/1484#issuecomment-1751814593 * chore(dev): do not log error when fetch was aborted --- .../joinmarket/directory_node/Dockerfile | 6 +- .../joinmarket/latest/Dockerfile | 6 +- package-lock.json | 19 + package.json | 1 + src/components/App.tsx | 6 +- src/components/BitcoinQR.jsx | 33 - src/components/BitcoinQR.tsx | 41 + src/components/CopyButton.tsx | 15 +- ...eWallet.test.jsx => CreateWallet.test.tsx} | 32 +- .../{CreateWallet.jsx => CreateWallet.tsx} | 88 ++- src/components/{Earn.jsx => Earn.tsx} | 710 ++++++++++-------- src/components/EarnReport.tsx | 2 +- src/components/ImportWallet.tsx | 57 +- src/components/Jam.tsx | 4 +- src/components/MainWalletView.tsx | 5 +- src/components/Navbar.tsx | 3 +- .../{Onboarding.jsx => Onboarding.tsx} | 0 src/components/Orderbook.tsx | 2 +- src/components/{Receive.jsx => Receive.tsx} | 36 +- src/components/RescanChain.tsx | 3 +- ...eduleProgress.jsx => ScheduleProgress.tsx} | 12 +- src/components/Send/index.tsx | 25 +- .../{Settings.test.jsx => Settings.test.tsx} | 10 +- src/components/{Settings.jsx => Settings.tsx} | 50 +- src/components/Wallet.test.tsx | 30 +- src/components/Wallet.tsx | 43 +- src/components/WalletCreationConfirmation.tsx | 13 +- .../{Wallets.test.jsx => Wallets.test.tsx} | 101 +-- src/components/{Wallets.jsx => Wallets.tsx} | 105 +-- src/components/fb/CreateFidelityBond.tsx | 19 +- src/components/fb/SpendFidelityBondModal.tsx | 3 +- .../jar_details/JarDetailsOverlay.tsx | 4 +- src/components/settings/FeeConfigModal.tsx | 4 +- src/components/settings/SeedModal.tsx | 6 +- src/context/ServiceConfigContext.tsx | 16 +- src/context/ServiceInfoContext.tsx | 24 +- src/context/WalletContext.tsx | 63 +- src/globals.d.ts | 1 + src/libs/JmWalletApi.ts | 110 +-- src/session.ts | 10 +- src/utils.ts | 8 +- 41 files changed, 976 insertions(+), 750 deletions(-) delete mode 100644 src/components/BitcoinQR.jsx create mode 100644 src/components/BitcoinQR.tsx rename src/components/{CreateWallet.test.jsx => CreateWallet.test.tsx} (91%) rename src/components/{CreateWallet.jsx => CreateWallet.tsx} (75%) rename src/components/{Earn.jsx => Earn.tsx} (50%) rename src/components/{Onboarding.jsx => Onboarding.tsx} (100%) rename src/components/{Receive.jsx => Receive.tsx} (92%) rename src/components/{ScheduleProgress.jsx => ScheduleProgress.tsx} (95%) rename src/components/{Settings.test.jsx => Settings.test.tsx} (82%) rename src/components/{Settings.jsx => Settings.tsx} (89%) rename src/components/{Wallets.test.jsx => Wallets.test.tsx} (80%) rename src/components/{Wallets.jsx => Wallets.tsx} (74%) diff --git a/docker/regtest/dockerfile-deps/joinmarket/directory_node/Dockerfile b/docker/regtest/dockerfile-deps/joinmarket/directory_node/Dockerfile index 2ca9a4a39..22b13bfb2 100644 --- a/docker/regtest/dockerfile-deps/joinmarket/directory_node/Dockerfile +++ b/docker/regtest/dockerfile-deps/joinmarket/directory_node/Dockerfile @@ -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/* @@ -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 diff --git a/docker/regtest/dockerfile-deps/joinmarket/latest/Dockerfile b/docker/regtest/dockerfile-deps/joinmarket/latest/Dockerfile index f875f186a..871c28759 100644 --- a/docker/regtest/dockerfile-deps/joinmarket/latest/Dockerfile +++ b/docker/regtest/dockerfile-deps/joinmarket/latest/Dockerfile @@ -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/* @@ -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 diff --git a/package-lock.json b/package-lock.json index 0b7be2acf..4c8c1031e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,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", @@ -4710,6 +4711,15 @@ "integrity": "sha512-L28j2FcJfSZOnL1WBjDYp2vUHCeIFlyYI/53EwD/rKUBQ7MtUUfbQWiyKJGpcnv4/WgrhWsFKrcPstcAt/J0tQ==", "dev": true }, + "node_modules/@types/qrcode": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@types/qrcode/-/qrcode-1.5.2.tgz", + "integrity": "sha512-W4KDz75m7rJjFbyCctzCtRzZUj+PrUHV+YjqDp50sSRezTbrtEAIq2iTzC6lISARl3qw+8IlcCyljdcVJE0Wug==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/qs": { "version": "6.9.7", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", @@ -25662,6 +25672,15 @@ "integrity": "sha512-L28j2FcJfSZOnL1WBjDYp2vUHCeIFlyYI/53EwD/rKUBQ7MtUUfbQWiyKJGpcnv4/WgrhWsFKrcPstcAt/J0tQ==", "dev": true }, + "@types/qrcode": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/@types/qrcode/-/qrcode-1.5.2.tgz", + "integrity": "sha512-W4KDz75m7rJjFbyCctzCtRzZUj+PrUHV+YjqDp50sSRezTbrtEAIq2iTzC6lISARl3qw+8IlcCyljdcVJE0Wug==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/qs": { "version": "6.9.7", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz", diff --git a/package.json b/package.json index 570a6678e..44d813d27 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/App.tsx b/src/components/App.tsx index 310ad0328..f3d39934c 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -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], ) diff --git a/src/components/BitcoinQR.jsx b/src/components/BitcoinQR.jsx deleted file mode 100644 index 4d082d257..000000000 --- a/src/components/BitcoinQR.jsx +++ /dev/null @@ -1,33 +0,0 @@ -import { useEffect, useState } from 'react' -import QRCode from 'qrcode' - -import { satsToBtc } from '../utils' - -export const BitcoinQR = ({ address, sats, errorCorrectionLevel = 'H', width = 260 }) => { - const [data, setData] = useState(null) - const [image, setImage] = useState(null) - - useEffect(() => { - const btc = satsToBtc(parseInt(sats, 10)) || 0 - const uri = `bitcoin:${address}${btc > 0 ? `?amount=${btc.toFixed(8)}` : ''}` - - QRCode.toDataURL(uri, { - errorCorrectionLevel, - width, - }) - .then((val) => { - setImage(val) - setData(uri) - }) - .catch(() => { - setImage(null) - setData(uri) - }) - }, [address, sats, errorCorrectionLevel, width]) - - return ( -
- {data} -
- ) -} diff --git a/src/components/BitcoinQR.tsx b/src/components/BitcoinQR.tsx new file mode 100644 index 000000000..a033b4636 --- /dev/null +++ b/src/components/BitcoinQR.tsx @@ -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() + const [image, setImage] = useState() + + 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 ( +
+ {data} +
+ ) +} diff --git a/src/components/CopyButton.tsx b/src/components/CopyButton.tsx index 713afc26d..c3a479338 100644 --- a/src/components/CopyButton.tsx +++ b/src/components/CopyButton.tsx @@ -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) { +function Copyable({ + value, + onSuccess, + onError, + className, + children, + disabled, + ...props +}: PropsWithChildren) { const valueFallbackInputRef = useRef(null) return ( <>