diff --git a/components/Balance.tsx b/components/Balance.tsx index 6c102ac..7a0a9b0 100644 --- a/components/Balance.tsx +++ b/components/Balance.tsx @@ -56,11 +56,7 @@ const Balance: FC = ({ className }) => {

Ӿ {showXnoBalance ? ( account?.balance === null ? ( diff --git a/components/XnoInput.tsx b/components/XnoInput.tsx new file mode 100644 index 0000000..1fd926a --- /dev/null +++ b/components/XnoInput.tsx @@ -0,0 +1,54 @@ +import Big from 'bignumber.js' +import { useRouter } from 'next/router' +import { FC, useCallback } from 'react' + +// delete if not needed +export interface Props { + value: string + onChange: (value: string) => void +} + +Big.config({ EXPONENTIAL_AT: 1e9 }) +const bigToConvert = new Big(`1${'0'.repeat(30)}`) + +const XnoInput: FC = ({ value, onChange }) => { + const { query, replace, pathname } = useRouter() + + const onInputChange = useCallback( + (value: string) => { + onChange(value) + replace({ + pathname, + query: { + ...query, + amount: + value !== '' + ? new Big(value).times(bigToConvert).toString() // since nanocurrency-js can't handle decimals :( + : '', + }, + }) + }, + [replace, pathname, query, onChange] + ) + + return ( +
+ + { + if (!validity.patternMismatch) onInputChange(value) + }} + /> +
+ ) +} + +export default XnoInput diff --git a/lib/hooks/useDrawQrCode.ts b/lib/hooks/useDrawQrCode.ts index fe45a56..2521ddf 100644 --- a/lib/hooks/useDrawQrCode.ts +++ b/lib/hooks/useDrawQrCode.ts @@ -16,7 +16,7 @@ const useDrawQrCode = ({ raw, address }: { raw?: string; address: string }) => { qr.toCanvas(canvasRef.current, genTxnUrl({ address: address, raw }), { color: { light: darkMode ? colors.coolGray['800'] : colors.white, - dark: colors.violet['50'], + dark: darkMode ? colors.violet['50'] : colors.violet['400'], }, }) }, [raw, address, canvasRef, darkMode]) diff --git a/pages/receive/qr.tsx b/pages/receive/qr.tsx index 3d6d342..533168a 100644 --- a/pages/receive/qr.tsx +++ b/pages/receive/qr.tsx @@ -1,24 +1,39 @@ import { LoginIcon } from '@heroicons/react/outline' import type { NextPage } from 'next' +import { useRouter } from 'next/router' +import { useState } from 'react' +import XnoInput from '../../components/XnoInput' import { useAccount } from '../../lib/context/accountContext' import useDrawQrCode from '../../lib/hooks/useDrawQrCode' const MyQrCode: NextPage = () => { const account = useAccount() - const canvasRef = useDrawQrCode({ address: account?.address ?? '' }) + const { query } = useRouter() + const { amount } = query as { amount?: string } + const canvasRef = useDrawQrCode({ + address: account?.address ?? '', + raw: amount, + }) + + const [xnoToSend, setXnoToSend] = useState('') return (
- +

receive

+ +
+ optional amount + +
) } diff --git a/pages/send/index.tsx b/pages/send/index.tsx index b5c2639..05a9590 100644 --- a/pages/send/index.tsx +++ b/pages/send/index.tsx @@ -1,38 +1,20 @@ import { ArrowDownIcon } from '@heroicons/react/outline' import { PaperAirplaneIcon } from '@heroicons/react/solid' -import Big from 'bignumber.js' import clsx from 'clsx' import { Unit, convert } from 'nanocurrency' import type { NextPage } from 'next' import { useRouter } from 'next/router' import { useCallback, useEffect, useState } from 'react' +import XnoInput from '../../components/XnoInput' import useSendNano from '../../lib/hooks/useSendNano' -Big.config({ EXPONENTIAL_AT: 1e9 }) -const bigToConvert = new Big(`1${'0'.repeat(30)}`) - const Send: NextPage = () => { - const { query, push, replace, pathname } = useRouter() + const { query, push } = useRouter() const { address, amount } = query as { address?: string; amount?: string } const [xnoToSend, setXnoToSend] = useState('') - const onXnoAmountChange = useCallback( - (value: string) => { - setXnoToSend(value) - replace({ - pathname, - query: { - ...query, - amount: - value !== '' - ? new Big(value).times(bigToConvert).toString() // since nanocurrency-js can't handle decimals :( - : '', - }, - }) - }, - [replace, pathname, query] - ) + const { send } = useSendNano() const [startX, setStartX] = useState(0) @@ -54,6 +36,9 @@ const Send: NextPage = () => { const sendNano = async () => { try { await send(address as string, amount as string) + navigator.serviceWorker + .getRegistration() + .then(sw => sw?.showNotification('sent!')) push('/dashboard') } catch { backToBase() @@ -81,22 +66,7 @@ const Send: NextPage = () => { onSubmit={ev => ev.preventDefault()} className="flex flex-col gap-3 items-center h-full" > -
- - { - if (!validity.patternMismatch) onXnoAmountChange(value) - }} - /> -
+ to
diff --git a/pages/send/qr.tsx b/pages/send/qr.tsx index c8c2ea6..a78ff69 100644 --- a/pages/send/qr.tsx +++ b/pages/send/qr.tsx @@ -32,7 +32,7 @@ const ReadQrCode: NextPage = () => { ref={videoRef} /> {!videoLive && ( -
+
)} )