Skip to content

Commit

Permalink
Merge branch 'develop' into fix-clear-sync-data
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Apr 19, 2024
2 parents 0ecb821 + 50d034f commit dd6f616
Show file tree
Hide file tree
Showing 34 changed files with 215 additions and 168 deletions.
2 changes: 1 addition & 1 deletion .ckb-light-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.3.6
v0.3.7
2 changes: 1 addition & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
node:
- 18.12.0
- 20.11.1
os:
- macos-latest
- ubuntu-20.04
Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# 0.114.3 (2024-04-16)

### CKB Node & Light Client

- [[email protected]](https://github.com/nervosnetwork/ckb/releases/tag/v0.115.0) was released on Apr. 1st, 2024. This version of CKB node is now bundled and preconfigured in Neuron.
- [CKB Light [email protected]](https://github.com/nervosnetwork/ckb-light-client/releases/tag/v0.3.7) was released on Apr. 13th, 2024. This version of CKB Light Client is now bundled and preconfigured in Neuron

### Assumed valid target

Block before `0x9443ad8da9172d484367bc5467988cba7a0c46028398309edfdda7d2d79be897`(at height `12,703,957`) will be skipped in validation.(https://github.com/nervosnetwork/neuron/pull/3123)

---

## New features

- #3054: Displaying DAO rewards.(@devchenyan)
- #3066: Support keeping screen awake.(@yanguoyu)

## Bug fixes

- #3055: Fix sending sudt to a new acp cell with extra 142 CKB by offline sign.(@yanguoyu)
- #3103: Handle MacOS crash properly on quitting.(@devchenyan)

## New Contributors

- @twhy made their first contribution in https://github.com/nervosnetwork/neuron/pull/3110

**Full Changelog**: https://github.com/nervosnetwork/neuron/compare/v0.114.2...v0.114.3

# 0.114.2 (2024-03-15)

### CKB Node & Light Client
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": ["packages/*"],
"version": "0.114.2",
"version": "0.114.3",
"npmClient": "yarn",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "neuron",
"productName": "Neuron",
"description": "CKB Neuron Wallet",
"version": "0.114.2",
"version": "0.114.3",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand Down
5 changes: 3 additions & 2 deletions packages/neuron-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "neuron-ui",
"version": "0.114.2",
"version": "0.114.3",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand Down Expand Up @@ -50,6 +50,7 @@
"last 2 chrome versions"
],
"dependencies": {
"@ckb-lumos/bi": "0.21.1",
"@ckb-lumos/base": "0.21.1",
"@ckb-lumos/codec": "0.21.1",
"@nervosnetwork/ckb-sdk-core": "0.109.0",
Expand Down Expand Up @@ -90,7 +91,7 @@
"@types/styled-components": "5.1.34",
"@wojtekmaj/enzyme-adapter-react-17": "0.8.0",
"babel-jest": "25.5.1",
"electron": "28.1.0",
"electron": "30.0.0",
"enzyme": "3.11.0",
"enzyme-adapter-react-16": "1.15.7",
"eslint-config-airbnb": "19.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/AddressBook/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const AddressBook = ({ onClose }: { onClose?: () => void }) => {
return `${HIDE_BALANCE} CKB`
}
return (
<CopyZone content={shannonToCKBFormatter(balance, false, '')} className={styles.copyBalance}>
<CopyZone content={shannonToCKBFormatter(balance, false, false)} className={styles.copyBalance}>
<span className="textOverflow">{`${shannonToCKBFormatter(balance)} CKB`}</span>
</CopyZone>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/Balance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Balance = ({ balance, connectionStatus, syncStatus }: BalanceProps) => {
return (
<>
<span>{`${t('overview.balance')}:`}</span>
<CopyZone content={shannonToCKBFormatter(balance, false, '')} name={t('overview.copy-balance')}>
<CopyZone content={shannonToCKBFormatter(balance, false, false)} name={t('overview.copy-balance')}>
<span className={styles.balanceValue}>{shannonToCKBFormatter(balance)}</span>
</CopyZone>
<BalanceSyncIcon connectionStatus={connectionStatus} syncStatus={syncStatus} />
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/components/DepositDialog/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const useGenerateDaoDepositTx = ({
payload: res,
})
if (isDepositAll) {
setMaxDepositValue(shannonToCKBFormatter(res?.outputs[0]?.capacity ?? '0', false, ''))
setMaxDepositValue(shannonToCKBFormatter(res?.outputs[0]?.capacity ?? '0', false, false))
if (!isBalanceReserved) {
setErrorMessage(t('messages.remain-ckb-for-withdraw'))
}
Expand Down Expand Up @@ -181,7 +181,7 @@ export const useDepositValue = (balance: string, showDepositDialog: boolean) =>
const amount = shannonToCKBFormatter(
((BigInt(percent) * BigInt(balance)) / BigInt(PERCENT_100)).toString(),
false,
''
false
)
setDepositValue(padFractionDigitsIfDecimal(amount, 8))
},
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/components/NervosDAO/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ const NervosDAO = () => {
</>
) : (
<CopyZone
content={shannonToCKBFormatter(`${free}`, false, '')}
content={shannonToCKBFormatter(`${free}`, false, false)}
name={t('nervos-dao.copy-balance')}
className={styles.balance}
>
Expand All @@ -303,7 +303,7 @@ const NervosDAO = () => {
<div className={styles.value}>
{onlineAndSynced && !isPrivacyMode ? (
<CopyZone
content={shannonToCKBFormatter(`${locked}`, false, '')}
content={shannonToCKBFormatter(`${locked}`, false, false)}
name={t('nervos-dao.copy-balance')}
className={styles.balance}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const TabsVariantWithTxTypes = ({
{isIncomeShow ? (
<div className={clsx(styles.fieldValue, styles.fullRow, styles.income)}>
<CopyZone
content={shannonToCKBFormatter(transaction.value, false, '')}
content={shannonToCKBFormatter(transaction.value, false, false)}
className={styles.incomeCopy}
maskRadius={8}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export const DAORecord = ({
) : (
<CopyZone
className={clsx(styles.amount, styles.withCopy)}
content={shannonToCKBFormatter(capacity, false, '')}
content={shannonToCKBFormatter(capacity, false, false)}
>
{`${shannonToCKBFormatter(capacity)} CKB`}
</CopyZone>
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-ui/src/components/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const Overview = () => {
)}
</span>
{showBalance ? (
<CopyZone content={shannonToCKBFormatter(balance, false, '')} className={styles.copyBalance}>
<CopyZone content={shannonToCKBFormatter(balance, false, false)} className={styles.copyBalance}>
<span className={styles.balanceValue}>{shannonToCKBFormatter(balance)}</span>
</CopyZone>
) : (
Expand All @@ -191,7 +191,7 @@ const Overview = () => {
<Lock />
<span className={styles.lockedTitle}>{t('overview.locked-balance')}&nbsp;:</span>
{showBalance ? (
<CopyZone content={shannonToCKBFormatter(balance, false, '')}>
<CopyZone content={shannonToCKBFormatter(balance, false, false)}>
<span className={styles.lockedBalance}>{shannonToCKBFormatter(lockedBalance)}</span>
</CopyZone>
) : (
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/PageContainer/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const useSetBlockNumber = ({
)
const onOpenAddressInExplorer = useCallback(() => {
const explorerUrl = getExplorerUrl(isMainnet)
openExternal(`${explorerUrl}/address/${firstAddress}`)
openExternal(`${explorerUrl}/address/${firstAddress}?sort=time`)
}, [firstAddress, isMainnet])
const onViewBlock = useCallback(() => {
const explorerUrl = getExplorerUrl(isMainnet)
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/components/Send/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const updateTransactionWith =
if (type === 'all') {
const fmtItems = items.map((item, i) => ({
...item,
amount: shannonToCKBFormatter(res.result.outputs[i].capacity, false, ''),
amount: shannonToCKBFormatter(res.result.outputs[i].capacity, false, false),
}))
const totalAmount = outputsToTotalAmount(fmtItems)
setTotalAmount(totalAmount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const useSendInfo = ({
...v.slice(0, v.length - 1),
{
...v[v.length - 1],
amount: shannonToCKBFormatter(res.outputs[res.outputs.length - 1].capacity, false, ''),
amount: shannonToCKBFormatter(res.outputs[res.outputs.length - 1].capacity, false, false),
disabled: true,
},
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,28 @@ export default {
expected: '0',
},
'0 decimal': {
value: '1',
value: '12345',
decimal: '0',
expected: '1',
expected: '12,345',
},
'1 decimal': {
value: '1',
decimal: '1',
expected: '0.1',
},
'2 decimal': {
value: '1234567890',
decimal: '2',
expected: '12,345,678.9',
},
'32 decimal': {
value: '100000000000000000000000000000001',
decimal: '32',
expected: '1.00000000000000000000000000000001',
},
'32 decimal and commas': {
value: '12345678900000000000000000000000000000001',
decimal: '32',
expected: '123,456,789.00000000000000000000000000000001',
},
}
87 changes: 19 additions & 68 deletions packages/neuron-ui/src/utils/formatters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { molecule } from '@ckb-lumos/codec'
import { blockchain } from '@ckb-lumos/base'
import { formatUnit, ckbDecimals } from '@ckb-lumos/bi'
import { TFunction } from 'i18next'
import { FailureFromController } from 'services/remote/remoteApiWrapper'
import { CapacityUnit } from './enums'
Expand Down Expand Up @@ -103,40 +104,16 @@ export const CKBToShannonFormatter = (amount: string = '0', unit: CapacityUnit =
}
}

export const shannonToCKBFormatter = (shannon: string, showPositiveSign?: boolean, delimiter: string = ',') => {
export const shannonToCKBFormatter = (shannon: string, showPositiveSign?: boolean, showCommaSeparator = true) => {
if (Number.isNaN(+shannon)) {
console.warn(`Shannon is not a valid number`)
console.warn(`Invalid shannon value: ${shannon}`)
return shannon
}
if (shannon === null) {
return '0'
}
let sign = ''
if (shannon.startsWith('-')) {
sign = '-'
} else if (showPositiveSign) {
sign = '+'
}
const unsignedShannon = shannon.replace(/^-?0*/, '')
let unsignedCKB = ''
if (unsignedShannon.length <= 8) {
unsignedCKB = `0.${unsignedShannon.padStart(8, '0')}`.replace(/\.?0+$/, '')
} else {
const decimal = `.${unsignedShannon.slice(-8)}`.replace(/\.?0+$/, '')
const int = unsignedShannon.slice(0, -8).replace(/\^0+/, '')
unsignedCKB = `${(
int
.split('')
.reverse()
.join('')
.match(/\d{1,3}/g) || ['0']
)
.join(delimiter)
.split('')
.reverse()
.join('')}${decimal}`
}
return +unsignedCKB === 0 ? '0' : `${sign}${unsignedCKB}`
return new Intl.NumberFormat('en-US', {
useGrouping: showCommaSeparator,
signDisplay: showPositiveSign && +shannon > 0 ? 'always' : 'auto',
maximumFractionDigits: ckbDecimals,
}).format(formatUnit(BigInt(shannon ?? '0'), 'ckb') as any)
}

export const localNumberFormatter = (num: string | number | bigint = 0) => {
Expand Down Expand Up @@ -236,45 +213,19 @@ export const sudtValueToAmount = (
value: string | null = '0',
decimal: string = '0',
showPositiveSign = false,
separator = ','
showCommaSeparator = true
) => {
if (value === null) {
return showPositiveSign ? '+0' : '0'
}
if (Number.isNaN(+value)) {
console.warn(`sUDT value is not a valid number`)
return showPositiveSign ? '+0' : '0'
if (Number.isNaN(Number(value))) {
console.warn(`Invalid sudt value: ${value}`)
}
let sign = ''
if (value.startsWith('-')) {
sign = '-'
} else if (showPositiveSign) {
sign = '+'
}
const unsignedValue = value.replace(/^-?0*/, '')
const dec = +decimal
if (dec === 0) {
return +unsignedValue ? `${sign}${unsignedValue}` : '0'
}
let unsignedSUDTValue = ''
if (unsignedValue.length <= dec) {
unsignedSUDTValue = `0.${unsignedValue.padStart(dec, '0')}`.replace(/\.?0+$/, '')
} else {
const decimalFraction = `.${unsignedValue.slice(-dec)}`.replace(/\.?0+$/, '')
const int = unsignedValue.slice(0, -dec).replace(/\^0+/, '')
unsignedSUDTValue = `${(
int
.split('')
.reverse()
.join('')
.match(/\d{1,3}/g) || ['0']
)
.join(separator)
.split('')
.reverse()
.join('')}${decimalFraction}`
}
return `${sign}${+unsignedSUDTValue === 0 ? '0' : unsignedSUDTValue}`
const val = value === null || Number.isNaN(+value) ? '0' : value
const [int, dec = ''] = formatUnit(val, +decimal).split('.')
const fmt = new Intl.NumberFormat('en-US', {
useGrouping: showCommaSeparator,
signDisplay: showPositiveSign ? 'always' : 'auto',
})
// use any type to avoid TS errors since string is not listed in the args IntlFormatter.prototype.format definition but it works
return `${fmt.format(int as any)}${dec ? `.${dec}` : ''}`
}

export const sUDTAmountFormatter = (amount: string) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/utils/getSUDTAmount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getSUDTAmount = ({
let amountToCopy = amount
if (tokenInfo) {
amount = `${sudtValueToAmount(amount, tokenInfo.decimal)} ${tokenInfo.symbol}`
amountToCopy = sudtValueToAmount(amountToCopy, tokenInfo.decimal, false, '')
amountToCopy = sudtValueToAmount(amountToCopy, tokenInfo.decimal, false, false)
}
return {
amount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
font-weight: 500;
margin: 14px 0 16px 0;
color: var(--main-text-color);
white-space: pre-wrap;
word-wrap: break-word;
overflow-wrap: break-word;
}

.message {
Expand Down
4 changes: 2 additions & 2 deletions packages/neuron-wallet/.env
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@ DAO_CODE_HASH=0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e
MULTISIG_CODE_HASH=0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8

# CKB NODE OPTIONS
CKB_NODE_ASSUME_VALID_TARGET='0x397d7d41167051cab2bf1610e334ad3aa5cf612e2cd442f71b91422e0361141e'
CKB_NODE_DATA_SIZE=51
CKB_NODE_ASSUME_VALID_TARGET='0x9443ad8da9172d484367bc5467988cba7a0c46028398309edfdda7d2d79be897'
CKB_NODE_DATA_SIZE=53
6 changes: 3 additions & 3 deletions packages/neuron-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "Neuron",
"description": "CKB Neuron Wallet",
"homepage": "https://www.nervos.org/",
"version": "0.114.2",
"version": "0.114.3",
"private": true,
"author": {
"name": "Nervos Core Dev",
Expand Down Expand Up @@ -93,11 +93,11 @@
"@types/sqlite3": "3.1.11",
"@types/uuid": "8.3.4",
"devtron": "1.4.0",
"electron": "28.1.0",
"electron": "30.0.0",
"electron-builder": "24.9.1",
"electron-devtools-installer": "3.2.0",
"jest-when": "3.6.0",
"neuron-ui": "0.114.2",
"neuron-ui": "0.114.3",
"typescript": "5.3.3"
}
}
Loading

1 comment on commit dd6f616

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 8752218651

Please sign in to comment.