This commit is contained in:
Filipe Medeiros 2021-11-28 05:15:19 +00:00
parent b41e8c88f7
commit 57c06bc0fe
13 changed files with 51 additions and 27 deletions

View file

@ -6,6 +6,7 @@ import { useCurrentAccount } from '../lib/context/accountContext'
import { usePreferences } from '../lib/context/preferencesContext'
import { ShowCurrencyPreference } from '../lib/db/types'
import useXnoPrice from '../lib/hooks/useXnoPrice'
import rawToNanoDisplay from '../lib/xno/rawToNanoDisplay'
export interface Props {
className?: string
@ -37,6 +38,7 @@ const Balance: FC<Props> = ({ className }) => {
account !== undefined
const xnoBalance = tools.convert(account?.balance ?? '0', 'RAW', 'NANO')
const xnoBalanceDisplay = rawToNanoDisplay(account?.balance ?? '0')
return (
<div
@ -55,7 +57,11 @@ const Balance: FC<Props> = ({ className }) => {
showXnoBalance ? 'font-medium dark:font-semibold' : 'font-semibold'
)}
>
{showXnoBalance ? <> {Number(xnoBalance).toFixed(2)}</> : 'NO'}
{showXnoBalance ? (
<> {xnoBalanceDisplay === 'small' ? '<0.01' : xnoBalanceDisplay}</>
) : (
'NO'
)}
</span>
</h3>
{showFiatBalance && (

View file

@ -1,8 +1,8 @@
import { ClockIcon } from '@heroicons/react/outline'
import { DownloadIcon, UploadIcon } from '@heroicons/react/solid'
import clsx from 'clsx'
import { tools } from 'nanocurrency-web'
import { FC, useCallback, useState } from 'react'
import { useCallback, useState } from 'react'
import type { FC } from 'react'
import { useCurrentAccount } from '../lib/context/accountContext'
import useAccountHistory from '../lib/hooks/useAccountHistory'
@ -10,12 +10,7 @@ import useAccountReceivable from '../lib/hooks/useAccountReceivable'
import useListenToConfirmations from '../lib/hooks/useListenToConfirmations'
import useReceiveNano from '../lib/hooks/useReceiveNano'
import { ConfirmationMessage } from '../lib/types'
const rawToNanoDisplay = (raw: string) =>
Number(tools.convert(raw, 'RAW', 'NANO').slice(0, 20))
.toFixed(2)
.replace(/^0\.00/, 'small')
.replace('.00', '')
import rawToNanoDisplay from '../lib/xno/rawToNanoDisplay'
export interface Props {
className?: string
@ -65,8 +60,6 @@ const RecentTransactions: FC<Props> = ({ className }) => {
useListenToConfirmations(onConfirmation)
console.log(listenedReceivables)
return (
<div className={clsx('flex flex-col gap-6 w-full', className)}>
{hasReceivable && (
@ -95,7 +88,7 @@ const RecentTransactions: FC<Props> = ({ className }) => {
<span className="flex-shrink-0 font-medium">
Ӿ{' '}
{rawToNanoDisplay(message.amount) === 'small' ? (
'<.01'
'<0.01'
) : rawToNanoDisplay(message.amount).startsWith('0.') ? (
<>
<span className="text-sm font-semibold">0</span>
@ -135,7 +128,7 @@ const RecentTransactions: FC<Props> = ({ className }) => {
<span className="flex-shrink-0 font-medium">
Ӿ{' '}
{rawToNanoDisplay(receivable.amount) === 'small' ? (
'<.01'
'<0.01'
) : rawToNanoDisplay(receivable.amount).startsWith('0.') ? (
<>
<span className="text-sm font-semibold">0</span>
@ -187,7 +180,7 @@ const RecentTransactions: FC<Props> = ({ className }) => {
<span className="flex-shrink-0 font-medium">
Ӿ{' '}
{rawToNanoDisplay(txn.amount) === 'small' ? (
'<.01'
'<0.01'
) : rawToNanoDisplay(txn.amount).startsWith('0.') ? (
<>
<span className="text-sm font-semibold">0</span>

View file

@ -54,7 +54,7 @@ export const PreferencesProvider: FC = ({ children }) => {
fetchPreferencesFromIdb()
}, [])
const setDarkMode = useDarkMode()
const { setDarkMode, isDarkMode } = useDarkMode()
const setPreference = useCallback(
<P extends PreferenceName>(
@ -70,6 +70,10 @@ export const PreferencesProvider: FC = ({ children }) => {
[setDarkMode]
)
useEffect(() => {
setPreference('darkMode', isDarkMode)
}, [isDarkMode, setPreference])
return (
<preferencesContext.Provider value={{ preferences, setPreference }}>
{children}

View file

@ -1,10 +1,12 @@
import { useCallback, useEffect } from 'react'
import { useCallback, useEffect, useState } from 'react'
import { getPreference } from '../db/preferences'
const useDarkMode = () => {
const [isDarkMode, setIsDarkMode] = useState(true)
const setDarkMode = useCallback(async (darkMode: boolean) => {
const htmlClasses = document.querySelector('html')?.classList
setIsDarkMode(darkMode)
if (darkMode) htmlClasses?.add('dark')
else htmlClasses?.remove('dark')
}, [])
@ -19,7 +21,7 @@ const useDarkMode = () => {
darkModeOnStarup()
}, [setDarkMode])
return setDarkMode
return { setDarkMode, isDarkMode }
}
export default useDarkMode

View file

@ -15,8 +15,14 @@ const useListenToConfirmations = (
const wsRef = useRef<WebSocket>()
useEffect(() => {
wsRef.current = new WebSocket('wss://node.somenano.com/websocket')
return () => wsRef.current?.close()
wsRef.current = new WebSocket('wss://socket.nanos.cc/')
return () => {
if (
wsRef.current?.readyState !== WebSocket.CLOSING &&
wsRef.current?.readyState !== WebSocket.CLOSED
)
wsRef.current?.close()
}
}, [])
useEffect(() => {
@ -36,7 +42,11 @@ const useListenToConfirmations = (
)
wsRef.current!.addEventListener('message', ({ data }) => {
const parsed = JSON.parse(data) as ConfirmationMessage
if (parsed.topic !== 'confirmation') return
if (
parsed.topic !== 'confirmation' ||
parsed.message.block.subtype !== 'send'
)
return
onConfirmation(parsed)
})

View file

@ -39,7 +39,7 @@ const useReceiveNano = () => {
)
await consumePrecomputedWork(account.address)
const work = await computeWorkAsync(processResponse.hash, { send: false })
const work = await computeWorkAsync(processResponse.hash, { send: true })
setAccount({
...account,
frontier: processResponse.hash,

View file

@ -2,7 +2,7 @@ import fetcher from '../fetcher'
import { AccountHistoryResponse } from '../types'
const fetchAccountHistory = (address: string, count = 20, head = undefined) =>
fetcher('https://mynano.ninja/api/node', {
fetcher('https://proxy.powernode.cc/proxy', {
method: 'POST',
body: {
action: 'account_history',

View file

@ -2,7 +2,7 @@ import fetcher from '../fetcher'
import { AccountInfoResponse } from '../types'
const fetchAccountInfo = (address: string) =>
fetcher('https://mynano.ninja/api/node', {
fetcher('https://proxy.powernode.cc/proxy', {
method: 'POST',
body: {
action: 'account_info',

View file

@ -6,7 +6,7 @@ const _fetchAccountReceivable = (
count = 20,
version22 = false
) =>
fetcher('https://mynano.ninja/api/node', {
fetcher('https://proxy.powernode.cc/proxy', {
method: 'POST',
body: {
action: version22 ? 'accounts_pending' : 'accounts_receivable',

View file

@ -2,7 +2,7 @@ import fetcher from '../fetcher'
import type { BlocksInfoResponse } from '../types'
const fetchBlocksInfo = (hashes: string[]) =>
fetcher('https://mynano.ninja/api/node', {
fetcher('https://proxy.powernode.cc/proxy', {
method: 'POST',
body: {
action: 'blocks_info',

View file

@ -0,0 +1,9 @@
import { tools } from 'nanocurrency-web'
const rawToNanoDisplay = (raw: string) =>
Number(tools.convert(raw, 'RAW', 'NANO').slice(0, 20))
.toFixed(2)
.replace(/^0\.00/, 'small')
.replace('.00', '')
export default rawToNanoDisplay

View file

@ -19,7 +19,7 @@ const sendNano = async (
const signedBlock = block.receive(blockData, privateKey)
const processResponse = await fetcher<ProcessResponse>(
'https://mynano.ninja/api/node',
'https://proxy.powernode.cc/proxy',
{
method: 'POST',
body: {

View file

@ -18,7 +18,7 @@ const sendNano = async (
const signedBlock = block.send(blockData, privateKey)
const processResponse = await fetcher<ProcessResponse>(
'https://mynano.ninja/api/node',
'https://proxy.powernode.cc/proxy',
{
method: 'POST',
body: {