From 1205e92107dd10a3ec13f9634ded6a4e615625a0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 4 Apr 2024 17:38:30 +0000 Subject: [PATCH 01/18] chore(deps): bump undici from 5.28.3 to 5.28.4 Bumps [undici](https://github.com/nodejs/undici) from 5.28.3 to 5.28.4. - [Release notes](https://github.com/nodejs/undici/releases) - [Commits](https://github.com/nodejs/undici/compare/v5.28.3...v5.28.4) --- updated-dependencies: - dependency-name: undici dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- packages/neuron-wallet/package.json | 2 +- yarn.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 1f41ad3916..b8e2c2fef1 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -74,7 +74,7 @@ "subleveldown": "4.1.4", "tslib": "2.6.2", "typeorm": "0.2.45", - "undici": "5.28.3", + "undici": "5.28.4", "uuid": "8.3.2" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 80dd638460..e1cb24f982 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2031,9 +2031,9 @@ regenerator-runtime "^0.14.0" "@babel/runtime@^7.23.9": - version "7.24.0" - resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.0.tgz#584c450063ffda59697021430cb47101b085951e" - integrity sha512-Chk32uHMg6TnQdvw2e9IlqPpFX/6NLuK0Ys2PqLb7/gL5uFn9mXvK715FGLlOLQrcO4qIkNHkvPGktzzXexsFw== + version "7.24.4" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.24.4.tgz#de795accd698007a66ba44add6cc86542aff1edd" + integrity sha512-dkxf7+hn8mFBwKjs9bvBlArzLVxVbS8usaPUDd5p2a9JCL9tB8OaOVN1isD4+Xyk4ns89/xeOmbQvgdK7IIVdA== dependencies: regenerator-runtime "^0.14.0" @@ -19712,10 +19712,10 @@ undici-types@~5.26.4: resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== -undici@5.28.3: - version "5.28.3" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.3.tgz#a731e0eff2c3fcfd41c1169a869062be222d1e5b" - integrity sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA== +undici@5.28.4: + version "5.28.4" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" + integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== dependencies: "@fastify/busboy" "^2.0.0" From 4d1b3bbb3540a833c974b770f6758daf0efbb291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E5=9B=BD=E5=AE=87?= <841185308@qq.com> Date: Mon, 8 Apr 2024 10:28:37 +0800 Subject: [PATCH 02/18] fix: Fix sending sudt to a new acp cell with extra 142 CKB by offline sign (#3055) Co-authored-by: Chen Yu --- packages/neuron-ui/src/components/HardwareSign/hooks.ts | 2 ++ packages/neuron-ui/src/components/PasswordRequest/hooks.ts | 3 ++- packages/neuron-ui/src/services/remote/offline.ts | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/neuron-ui/src/components/HardwareSign/hooks.ts b/packages/neuron-ui/src/components/HardwareSign/hooks.ts index cec9567a50..2ccc38400b 100644 --- a/packages/neuron-ui/src/components/HardwareSign/hooks.ts +++ b/packages/neuron-ui/src/components/HardwareSign/hooks.ts @@ -85,6 +85,8 @@ export default ({ switch (offlineSignJSON?.type) { case OfflineSignType.CreateSUDTAccount: return 'create-sudt-account' + case OfflineSignType.SendAcpSUDTToNewCell: + return 'send-acp-sudt-to-new-cell' case OfflineSignType.SendSUDT: return 'send-sudt' case OfflineSignType.UnlockDAO: diff --git a/packages/neuron-ui/src/components/PasswordRequest/hooks.ts b/packages/neuron-ui/src/components/PasswordRequest/hooks.ts index 9e335c9e4e..dbb4073155 100644 --- a/packages/neuron-ui/src/components/PasswordRequest/hooks.ts +++ b/packages/neuron-ui/src/components/PasswordRequest/hooks.ts @@ -56,9 +56,10 @@ export default ({ switch (actionType) { case 'create-sudt-account': return OfflineSignType.CreateSUDTAccount + case 'send-acp-sudt-to-new-cell': + return OfflineSignType.SendAcpSUDTToNewCell case 'send-ckb-asset': case 'send-acp-ckb-to-new-cell': - case 'send-acp-sudt-to-new-cell': case 'transfer-to-sudt': case 'send-sudt': return OfflineSignType.SendSUDT diff --git a/packages/neuron-ui/src/services/remote/offline.ts b/packages/neuron-ui/src/services/remote/offline.ts index f2ed6f88e3..6824bd9c0a 100644 --- a/packages/neuron-ui/src/services/remote/offline.ts +++ b/packages/neuron-ui/src/services/remote/offline.ts @@ -13,6 +13,7 @@ export enum OfflineSignType { UnlockDAO = 'UnlockDAO', CreateSUDTAccount = 'CreateSUDTAccount', SendSUDT = 'SendSUDT', + SendAcpSUDTToNewCell = 'SendAcpSUDTToNewCell', SendFromMultisigOnlySig = 'SendFromMultisigOnlySig', Invalid = 'Invalid', } From 2ec01b8808156c31905c39f46ce6e82080c6406e Mon Sep 17 00:00:00 2001 From: Tom Wang Date: Mon, 8 Apr 2024 20:19:07 +0800 Subject: [PATCH 03/18] fix: Add react-refresh@0.14.0 to resolutions in root package.json (#3108) (#3110) --- package.json | 3 ++- yarn.lock | 7 +------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 9d0c793ed0..aa0b2ab372 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,8 @@ "dependencies": {}, "resolutions": { "@types/react": "18.2.45", - "react-i18next": ">=11.16.4" + "react-i18next": ">=11.16.4", + "react-refresh": "0.14.0" }, "volta": { "node": "20.10.0" diff --git a/yarn.lock b/yarn.lock index 80dd638460..da5bd9347d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17127,12 +17127,7 @@ react-is@^17.0.0, react-is@^17.0.1, react-is@^17.0.2: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-refresh@^0.11.0: - version "0.11.0" - resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046" - integrity sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A== - -react-refresh@^0.14.0: +react-refresh@0.14.0, react-refresh@^0.11.0, react-refresh@^0.14.0: version "0.14.0" resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e" integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ== From 7118fb27c06de754a5d53841165254949dc46186 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 21:24:22 +0900 Subject: [PATCH 04/18] Update ckb client versions (#3097) feat: update ckb client versions Co-authored-by: Keith-CY Co-authored-by: Chen Yu --- .ckb-version | 2 +- compatible.json | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.ckb-version b/.ckb-version index de4d9773e7..003d88e0df 100644 --- a/.ckb-version +++ b/.ckb-version @@ -1 +1 @@ -v0.114.0 +v0.115.0 diff --git a/compatible.json b/compatible.json index c2c41af8a5..bdf141600c 100644 --- a/compatible.json +++ b/compatible.json @@ -1,5 +1,6 @@ { "fullVersions": [ + "0.115", "0.114", "0.113", "0.112", @@ -20,6 +21,7 @@ "compatible": { "0.111": { "full": [ + "0.115", "0.114", "0.113", "0.112", @@ -34,6 +36,7 @@ }, "0.110": { "full": [ + "0.115", "0.114", "0.113", "0.112", @@ -64,6 +67,7 @@ }, "0.112": { "full": [ + "0.115", "0.114", "0.113", "0.112", @@ -78,6 +82,7 @@ }, "0.114": { "full": [ + "0.115", "0.114", "0.113", "0.112", From 129aa3c3c86f7959d8500a05c7823a87a256aca9 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Wed, 10 Apr 2024 16:20:41 +0800 Subject: [PATCH 05/18] fix: Neuron for MacOS crashes on quitting (#3103) * fix: Neuron for MacOS crashes on quitting * fix: spell error --------- Co-authored-by: Chen Yu --- packages/neuron-wallet/src/main.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/neuron-wallet/src/main.ts b/packages/neuron-wallet/src/main.ts index a65b386bea..182eabd076 100644 --- a/packages/neuron-wallet/src/main.ts +++ b/packages/neuron-wallet/src/main.ts @@ -16,9 +16,11 @@ if (singleInstanceLock) { appController.start() }) - app.on('before-quit', async () => { + app.on('before-quit', async e => { logger.info('App:\tNeuron will exit') + e.preventDefault() await appController.end() + app.exit() }) app.on('activate', appController.openWindow) From f4027aa88985f0349d249fe6ea6468809f707c92 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 10 Apr 2024 23:43:37 +0900 Subject: [PATCH 06/18] chore(deps): bump undici from 5.28.3 to 5.28.4 in /packages/neuron-wallet (#3112) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Chen Yu --- packages/neuron-wallet/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 1f41ad3916..b8e2c2fef1 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -74,7 +74,7 @@ "subleveldown": "4.1.4", "tslib": "2.6.2", "typeorm": "0.2.45", - "undici": "5.28.3", + "undici": "5.28.4", "uuid": "8.3.2" }, "devDependencies": { From 71bb064b0f7e37d31ffae609443e3d4eef448255 Mon Sep 17 00:00:00 2001 From: Tom Wang Date: Thu, 11 Apr 2024 12:06:50 +0800 Subject: [PATCH 07/18] refactor: rewrite shannonToCKB with lumos formatUnit (#3114) --- .../neuron-wallet/src/utils/shannonToCKB.ts | 20 +++++++------------ .../neuron-wallet/src/utils/to-csv-row.ts | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/packages/neuron-wallet/src/utils/shannonToCKB.ts b/packages/neuron-wallet/src/utils/shannonToCKB.ts index 82c1a01871..8d9ba94c69 100644 --- a/packages/neuron-wallet/src/utils/shannonToCKB.ts +++ b/packages/neuron-wallet/src/utils/shannonToCKB.ts @@ -1,18 +1,12 @@ -const DECIMAL = 8 +import { formatUnit, ckbDecimals } from '@ckb-lumos/bi' const shannonToCKB = (shannon: bigint) => { - if (shannon === BigInt(0)) { - return `+0.${'0'.repeat(DECIMAL)}` - } - - const isNegative = shannon < 0 - const absStr = isNegative ? `${shannon}`.slice(1) : `${shannon}` - if (absStr.length <= DECIMAL) { - return `${isNegative ? '-' : '+'}0.${absStr.padStart(DECIMAL, '0')}` - } - const int = absStr.slice(0, -1 * DECIMAL) - const dec = absStr.slice(-1 * DECIMAL) - return `${isNegative ? '-' : '+'}${int}.${dec}` + return new Intl.NumberFormat('en-US', { + useGrouping: false, + signDisplay: 'always', + minimumFractionDigits: ckbDecimals, + maximumFractionDigits: ckbDecimals, + }).format(formatUnit(shannon, 'ckb') as any) } export default shannonToCKB diff --git a/packages/neuron-wallet/src/utils/to-csv-row.ts b/packages/neuron-wallet/src/utils/to-csv-row.ts index ce3d32e842..9992a4e327 100644 --- a/packages/neuron-wallet/src/utils/to-csv-row.ts +++ b/packages/neuron-wallet/src/utils/to-csv-row.ts @@ -41,7 +41,7 @@ const toCSVRow = ( txType = +tx.sudtInfo.amount <= 0 ? `UDT ${SEND_TYPE}` : `UDT ${RECEIVE_TYPE}` } } else { - amount = shannonToCKB(BigInt(tx.value ?? '')) + amount = shannonToCKB(BigInt(tx.value ?? '0')) if (tx.nervosDao) { txType = `Nervos DAO` } else if (['create', 'destroy'].includes(tx.type || '')) { From 476e982b7baf3239d464942e946de02597d8d0b8 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Thu, 11 Apr 2024 12:07:21 +0800 Subject: [PATCH 08/18] feat: Remove unnecessary package electron-build-env (#3116) feat: remove electron-build-env --- packages/neuron-wallet/package.json | 1 - yarn.lock | 49 +++++++++++++++++++---------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index b8e2c2fef1..48e38216b0 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -94,7 +94,6 @@ "@types/uuid": "8.3.4", "devtron": "1.4.0", "electron": "28.1.0", - "electron-build-env": "0.2.0", "electron-builder": "24.9.1", "electron-devtools-installer": "3.2.0", "jest-when": "3.6.0", diff --git a/yarn.lock b/yarn.lock index da5bd9347d..d756cab0ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8350,7 +8350,7 @@ commander@11.1.0: resolved "https://registry.yarnpkg.com/commander/-/commander-11.1.0.tgz#62fdce76006a68e5c1ab3314dc92e800eb83d906" integrity sha512-yPVavfyCcRhmorC7rWlkHn15b4wDVgVmBA7kV4QVBsF7kv/9TKJAbAXVTxvTnwP8HHKjRCJDClKbciiYS7p0DQ== -commander@^2.19.0, commander@^2.20.0, commander@^2.9.0: +commander@^2.19.0, commander@^2.20.0: version "2.20.3" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== @@ -9562,14 +9562,6 @@ ejs@^3.1.6, ejs@^3.1.7, ejs@^3.1.8: dependencies: jake "^10.8.5" -electron-build-env@0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/electron-build-env/-/electron-build-env-0.2.0.tgz#5649ee3e5fd006e267086caa945b77a1fa220b92" - integrity sha512-L431TbXtXe6iw3ko7ITr/qCu+jumVKLAhCDyhqfab6421LGlawVcT88Ws/DHR57+1lkLN1POQqwNOkjPwQJQmQ== - dependencies: - commander "^2.9.0" - mkdirp "^0.5.1" - electron-builder@24.9.1: version "24.9.1" resolved "https://registry.yarnpkg.com/electron-builder/-/electron-builder-24.9.1.tgz#4aee03947963b829a7f48a850fe02c219311ef63" @@ -18708,7 +18700,16 @@ string-natural-compare@^3.0.1: resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4" integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw== -"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -18826,7 +18827,14 @@ stringify-object@^3.3.0: is-obj "^1.0.1" is-regexp "^1.0.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -19707,10 +19715,10 @@ undici-types@~5.26.4: resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== -undici@5.28.3: - version "5.28.3" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.3.tgz#a731e0eff2c3fcfd41c1169a869062be222d1e5b" - integrity sha512-3ItfzbrhDlINjaP0duwnNsKpDQk3acHI3gVJ1z4fmwMK31k5G9OVIAMLSIaP6w4FaGkaAkN6zaQO9LUvZ1t7VA== +undici@5.28.4: + version "5.28.4" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.28.4.tgz#6b280408edb6a1a604a9b20340f45b422e373068" + integrity sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g== dependencies: "@fastify/busboy" "^2.0.0" @@ -20610,7 +20618,16 @@ workbox-window@6.6.1: "@types/trusted-types" "^2.0.2" workbox-core "6.6.1" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + +wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== From e03982446a1ba85541105b45b6992675f6c92839 Mon Sep 17 00:00:00 2001 From: devchenyan Date: Thu, 11 Apr 2024 15:58:01 +0800 Subject: [PATCH 09/18] feat: Displaying DAO rewards (#3054) * feat: Displaying DAO rewards * fix: spell error --------- Co-authored-by: Chen Yu --- .../DepositDialog/depositDialog.module.scss | 101 +++++++++++------- .../src/components/DepositDialog/hooks.ts | 33 ++++++ .../src/components/DepositDialog/index.tsx | 66 ++++++++++-- .../src/components/NervosDAO/index.tsx | 6 +- packages/neuron-ui/src/locales/en.json | 3 + packages/neuron-ui/src/locales/es.json | 3 + packages/neuron-ui/src/locales/fr.json | 3 + packages/neuron-ui/src/locales/zh-tw.json | 4 + packages/neuron-ui/src/locales/zh.json | 3 + 9 files changed, 173 insertions(+), 49 deletions(-) diff --git a/packages/neuron-ui/src/components/DepositDialog/depositDialog.module.scss b/packages/neuron-ui/src/components/DepositDialog/depositDialog.module.scss index 821546c681..b2fc0b5edf 100644 --- a/packages/neuron-ui/src/components/DepositDialog/depositDialog.module.scss +++ b/packages/neuron-ui/src/components/DepositDialog/depositDialog.module.scss @@ -1,7 +1,11 @@ @import '../../styles/mixin.scss'; +.container { + width: 680px; +} + .slider { - margin-top: 16px; + margin-top: 10px; :global(.ms-Slider-thumb) { top: -8px; @@ -32,10 +36,31 @@ margin-top: 16px; } -.depositValueLabel { - line-height: 20px; - color: var(--secondary-text-color); - font-size: 14px; +.depositValueLabelWrap { + display: flex; + + .depositValueLabel { + line-height: 20px; + color: var(--secondary-text-color); + font-size: 14px; + } + .tooltip { + margin-left: 120px; + } + .tip { + width: 400px; + word-break: normal; + white-space: normal; + line-height: 180%; + } + + svg { + margin: 2px 4px 0; + cursor: pointer; + path { + fill: var(--primary-color); + } + } } .fee { @@ -43,46 +68,49 @@ justify-content: space-between; font-size: 14px; line-height: 20px; + margin-top: 4px; color: var(--main-text-color); + gap: 24px; & > div { - &:nth-last-child(1) { - width: 230px; - text-align: right; + &:first-child { + flex-shrink: 0; } } } -.notice { - $lineHeight: 24px; - display: flex; - box-sizing: border-box; - margin-top: 22px; - border: 1px solid rgba(252, 136, 0, 0.2); - padding: 7px 54px; - border-radius: 4px; - background: #fff6eb; - color: #f68c2a; - font-weight: 500; - font-size: 12px; - line-height: $lineHeight; - text-align: center; - - & > svg { - $size: 14px; - flex-shrink: 0; - margin: calc(($lineHeight - $size) / 2) 4px 0 0; - width: $size; - height: $size; - - g[fill='#D50000'] { - fill: currentColor; +.rewards { + padding: 6px 16px; + background: var(--tag-green-bg-color); + border-radius: 8px; + margin-top: 14px; + div { + display: flex; + justify-content: space-between; + color: var(--primary-color); + p { + margin: 0; + padding: 4px 0; + font-size: 14px; + line-height: 20px; } } +} - @media (prefers-color-scheme: dark) { - border-color: #4b391c; - background: #4b391c; +.acpContent { + display: flex; + .tip { + min-width: 190px; + word-break: normal; + white-space: normal; + line-height: 180%; + } + svg { + margin: 2px 4px 0; + cursor: pointer; + path { + fill: var(--primary-color); + } } } @@ -90,7 +118,7 @@ font-weight: 500; font-size: 12px; background: inherit; - color: #f68c2a; + color: var(--primary-color); border: none; padding: 0; margin: 0; @@ -111,6 +139,7 @@ gap: 8px; & > svg { + flex-shrink: 0; path { fill: #e5e5e5; diff --git a/packages/neuron-ui/src/components/DepositDialog/hooks.ts b/packages/neuron-ui/src/components/DepositDialog/hooks.ts index 2a28144db6..41fa272d06 100644 --- a/packages/neuron-ui/src/components/DepositDialog/hooks.ts +++ b/packages/neuron-ui/src/components/DepositDialog/hooks.ts @@ -275,3 +275,36 @@ export const useOnDepositDialogCancel = ({ clearGeneratedTx() }, [dispatch, onCloseDepositDialog, resetDepositValue, clearGeneratedTx]) } + +export const useDepositRewards = ({ + depositValue, + maxDepositValue, + disabled, + globalAPC, +}: { + depositValue: string + maxDepositValue: string | null + disabled: boolean + globalAPC: number +}) => { + const [annualRewards, monthRewards] = useMemo(() => { + if (disabled) return ['0', '0'] + + const value = CKBToShannonFormatter( + (Number(maxDepositValue || depositValue) - MIN_DEPOSIT_AMOUNT).toFixed(MAX_DECIMAL_DIGITS).toString() + ) + + const dpc = globalAPC / 365 / 100 + + const mRewards = (Number(value) * dpc * 30).toFixed(0).toString() + + const rewerds = (Number(value) * dpc * 360).toFixed(0).toString() + + return [rewerds, mRewards] + }, [depositValue, maxDepositValue, disabled, globalAPC]) + + return { + annualRewards, + monthRewards, + } +} diff --git a/packages/neuron-ui/src/components/DepositDialog/index.tsx b/packages/neuron-ui/src/components/DepositDialog/index.tsx index fd4125033f..abc69ca05f 100644 --- a/packages/neuron-ui/src/components/DepositDialog/index.tsx +++ b/packages/neuron-ui/src/components/DepositDialog/index.tsx @@ -7,6 +7,7 @@ import { openExternal } from 'services/remote' import { localNumberFormatter, shannonToCKBFormatter } from 'utils' import { Attention, Success } from 'widgets/Icons/icon' import Dialog from 'widgets/Dialog' +import Tooltip from 'widgets/Tooltip' import styles from './depositDialog.module.scss' import { useBalanceReserved, @@ -14,6 +15,7 @@ import { useGenerateDaoDepositTx, useOnDepositDialogCancel, useOnDepositDialogSubmit, + useDepositRewards, } from './hooks' const NERVOS_DAO_RFC_URL = @@ -28,6 +30,7 @@ interface DepositDialogProps { isTxGenerated: boolean suggestFeeRate: number walletID: string + globalAPC: number } const RfcLink = React.memo(() => ( @@ -53,8 +56,9 @@ const DepositDialog = ({ isDepositing, isTxGenerated, suggestFeeRate, + globalAPC, }: DepositDialogProps) => { - const [t] = useTranslation() + const [t, { language }] = useTranslation() const disabled = !isTxGenerated const { isBalanceReserved, onIsBalanceReservedChange, setIsBalanceReserved } = useBalanceReserved() const { depositValue, onChangeDepositValue, slidePercent, onSliderChange, resetDepositValue } = useDepositValue( @@ -81,6 +85,14 @@ const DepositDialog = ({ }, [disabled, onConfirm] ) + const { annualRewards, monthRewards } = useDepositRewards({ + depositValue, + maxDepositValue, + disabled, + globalAPC, + }) + + const isChinese = language === 'zh' || language.startsWith('zh-') return ( {isDepositing ? ( ) : (
- +
+ + + ]} /> +
+ } + > + + +
+
+ {t('nervos-dao.fee')} + {`${shannonToCKBFormatter(fee)}`} +
+
+
+
- {t('nervos-dao.fee')} - {`${shannonToCKBFormatter(fee)}`} +

{t(`nervos-dao.estimated-rewards`, { days: 30 })}

+

{shannonToCKBFormatter(monthRewards)} CKB

+
+
+

{t(`nervos-dao.estimated-rewards`, { days: 360 })}

+

{shannonToCKBFormatter(annualRewards)} CKB

-
- -
-
- ]} /> +
+ {t(`nervos-dao.estimated-apc`)} + {isChinese ? null : ( + {t(`nervos-dao.estimated-apc-tooltip`)}

} + > + +
+ )} +
+

{globalAPC}%

diff --git a/packages/neuron-ui/src/components/NervosDAO/index.tsx b/packages/neuron-ui/src/components/NervosDAO/index.tsx index 24fcef51da..c31269a8f0 100644 --- a/packages/neuron-ui/src/components/NervosDAO/index.tsx +++ b/packages/neuron-ui/src/components/NervosDAO/index.tsx @@ -222,6 +222,7 @@ const NervosDAO = () => { isDepositing={sending} isTxGenerated={!!send.generatedTx} suggestFeeRate={suggestFeeRate} + globalAPC={globalAPC} /> ) }, [ @@ -233,6 +234,7 @@ const NervosDAO = () => { sending, send.generatedTx, suggestFeeRate, + globalAPC, ]) const MemoizedWithdrawDialog = useMemo(() => { @@ -260,7 +262,7 @@ const NervosDAO = () => { const onlineAndSynced = ConnectionStatus.Online === connectionStatus && SyncStatus.SyncCompleted === syncStatus - const isEnglish = language === 'en' || language.startsWith('en-') + const isChinese = language === 'zh' || language.startsWith('zh-') return ( {
{t(`nervos-dao.apc`)} - {isEnglish && ( + {isChinese ? null : ( diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index 4204d777e0..5cc728b75c 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -709,6 +709,9 @@ "compensation-accumulated": "{{blockNumber}} blocks compensation accumulated", "withdraw-alert": "Hint: there are only {{epochs}} epochs (~{{hours}} hours) until the end of your current lock period. If you wish to withdraw in current lock period, please send withdraw request in time. There are {{nextLeftEpochs}} epochs(~{{days}} days) until the end of your next lock period.", "balance-not-reserved": "Don't reserve any CKBytes for future DAO operations (Not recommended)", + "estimated-rewards": "Estimated Rewards of {{days}} days", + "estimated-apc": "Estimated APC", + "estimated-apc-tooltip": "Estimated Annual Percentage Compensation", "deposit-amount": "Deposit Amount (CKB)", "deposit-record": { "deposited-at": "Deposited", diff --git a/packages/neuron-ui/src/locales/es.json b/packages/neuron-ui/src/locales/es.json index dc163b043b..7ee4f72514 100644 --- a/packages/neuron-ui/src/locales/es.json +++ b/packages/neuron-ui/src/locales/es.json @@ -692,6 +692,9 @@ "compensation-accumulated": "Compensación acumulada en {{blockNumber}} bloques", "withdraw-alert": "Advertencia: solo quedan {{epochs}} epochs ({{hours}} horas) hasta el final de su periodo de bloqueo actual. Si desea retirar en el periodo de bloqueo actual, envíe la solicitud de retiro a tiempo. Solo quedan {{nextLeftEpochs}} epochs ({{days}} días) hasta el final de su próximo periodo de bloqueo.", "balance-not-reserved": "No reservar ningún CKBytes para futuras operaciones de DAO (no se recomienda)", + "estimated-rewards": "Recompensas estimadas de {{días}} días", + "estimated-apc": "Estimación APC", + "estimated-apc-tooltip": "Estimación de Compensación Anual", "deposit-amount": "Cantidad a Depositar (CKB)", "deposit-record": { "deposited-at": "Depositado", diff --git a/packages/neuron-ui/src/locales/fr.json b/packages/neuron-ui/src/locales/fr.json index 6a76f0d5e4..7d39eebac9 100644 --- a/packages/neuron-ui/src/locales/fr.json +++ b/packages/neuron-ui/src/locales/fr.json @@ -699,6 +699,9 @@ "compensation-accumulated": "{{blockNumber}} blocs de compensation accumulée", "withdraw-alert": "Astuce : il ne reste que {{epochs}} époques (~{{hours}} heures) jusqu'à la fin de votre période de verrouillage actuelle. Si vous souhaitez retirer pendant cette période de verrouillage, veuillez envoyer une demande de retrait à temps. Il reste {{nextLeftEpochs}} époques (~{{days}} jours) jusqu'à la fin de votre prochaine période de verrouillage.", "balance-not-reserved": "Ne pas réserver de CKBytes pour les futures opérations DAO (non recommandé)", + "estimated-rewards": "Récompenses estimées de {{days}} jours", + "estimated-apc": "Estimation de APC", + "estimated-apc-tooltip": "Estimation de Compensation Annuel", "deposit-amount": "Montant du dépôt (CKB)", "deposit-record": { "deposited-at": "Déposé", diff --git a/packages/neuron-ui/src/locales/zh-tw.json b/packages/neuron-ui/src/locales/zh-tw.json index 32130fbf4e..e3d4260af5 100644 --- a/packages/neuron-ui/src/locales/zh-tw.json +++ b/packages/neuron-ui/src/locales/zh-tw.json @@ -703,6 +703,10 @@ "compensation-accumulated": "已累計 {{blockNumber}} 個塊的鎖定補貼", "withdraw-alert": "提示:本補貼申請距離 Nervos DAO 規則允許的最近一個鎖定週期僅剩下 {{epochs}} 個 epoch (約 {{hours}} 小時)。如果您希望在本鎖定週期取出,請及時提交取出申請,以確保取出申請能在本鎖定週期結束之前上鏈。下一個鎖定週期的結束時間預計為 {{nextLeftEpochs}} 個 epochs (約 {{days}} 天)。", "balance-not-reserved": "(不建議)不預留未來操作手續費", + "estimated-rewards": "{{days}}天預計獎勵", + "estimated-apc": "預計年化鎖定補貼率", + "estimated-apc-tooltip": "預計年化鎖定補貼率", + "deposit-amount": "存入金額 (CKB)", "deposit-record": { "deposited-at": "存入於", "completed-at": "已取出", diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index bef868f0b4..0611594ee6 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -702,6 +702,9 @@ "compensation-accumulated": "已累计 {{blockNumber}} 个块的锁定补贴", "withdraw-alert": "提示:本补贴申请距离 Nervos DAO 规则允许的最近一个锁定周期仅剩下 {{epochs}} 个 epoch (约 {{hours}} 小时)。 如果您希望在本锁定周期取出,请及时提交取出申请,以确保取出申请能在本锁定周期结束之前上链。下一个锁定周期的结束时间预计为 {{nextLeftEpochs}} 个 epochs (约 {{days}} 天)。", "balance-not-reserved": "不预留未来操作手续费(不建议)", + "estimated-rewards": "{{days}}天预计奖励", + "estimated-apc": "预计年化锁定补贴率", + "estimated-apc-tooltip": "预计年化锁定补贴率", "deposit-amount": "存入金额 (CKB)", "deposit-record": { "deposited-at": "存入于", From 3d3e767f3a8e446b1e9d568545abcd99aa8c9bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E5=9B=BD=E5=AE=87?= <841185308@qq.com> Date: Fri, 12 Apr 2024 15:58:50 +0800 Subject: [PATCH 10/18] feat: Keep screen awake (#3066) --- .../GeneralSetting/generalSetting.module.scss | 9 ++++-- .../src/components/GeneralSetting/index.tsx | 27 ++++++++++++++++-- .../components/Settings/settings.module.scss | 2 +- .../neuron-ui/src/containers/Main/index.tsx | 11 ++++++-- packages/neuron-ui/src/locales/en.json | 3 +- packages/neuron-ui/src/locales/es.json | 3 +- packages/neuron-ui/src/locales/fr.json | 3 +- packages/neuron-ui/src/locales/zh-tw.json | 3 +- packages/neuron-ui/src/locales/zh.json | 3 +- packages/neuron-ui/src/services/localCache.ts | 11 ++++++++ packages/neuron-ui/src/utils/index.ts | 1 + packages/neuron-ui/src/utils/wakeScreen.ts | 28 +++++++++++++++++++ 12 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 packages/neuron-ui/src/utils/wakeScreen.ts diff --git a/packages/neuron-ui/src/components/GeneralSetting/generalSetting.module.scss b/packages/neuron-ui/src/components/GeneralSetting/generalSetting.module.scss index e55142e967..bd41cc7b53 100644 --- a/packages/neuron-ui/src/components/GeneralSetting/generalSetting.module.scss +++ b/packages/neuron-ui/src/components/GeneralSetting/generalSetting.module.scss @@ -4,14 +4,19 @@ $action-button-width: 11.25rem; .container { display: flex; + flex-wrap: wrap; width: 100%; + gap: 16px; .content { width: 176px; padding: 16px; background: var(--input-disabled-color); border-radius: 8px; - margin-right: 16px; + display: flex; + flex-direction: column; + justify-content: space-between; + flex-shrink: 0; p { font-size: 14px; @@ -19,7 +24,7 @@ $action-button-width: 11.25rem; margin: 0 0 12px; color: var(--main-text-color); } - button { + button[data-button-type='text'] { font-size: 14px; line-height: 20px; border: none; diff --git a/packages/neuron-ui/src/components/GeneralSetting/index.tsx b/packages/neuron-ui/src/components/GeneralSetting/index.tsx index 7866c4eaaa..bc0dcc5ba0 100644 --- a/packages/neuron-ui/src/components/GeneralSetting/index.tsx +++ b/packages/neuron-ui/src/components/GeneralSetting/index.tsx @@ -8,8 +8,10 @@ import { ReactComponent as VersionLogo } from 'widgets/Icons/VersionLogo.svg' import { ReactComponent as ArrowNext } from 'widgets/Icons/ArrowNext.svg' import { ReactComponent as Update } from 'widgets/Icons/Update.svg' import { cancelCheckUpdates, downloadUpdate, installUpdate, getVersion } from 'services/remote' -import { uniformTimeFormatter, bytesFormatter, clsx } from 'utils' +import { uniformTimeFormatter, bytesFormatter, clsx, wakeScreen, releaseWakeLock } from 'utils' import { LanguageSelect } from 'widgets/Icons/icon' +import Switch from 'widgets/Switch' +import { keepScreenAwake } from 'services/localCache' import styles from './generalSetting.module.scss' import { useCheckUpdate, useUpdateDownloadStatus } from './hooks' @@ -173,13 +175,29 @@ const GeneralSetting = ({ updater }: GeneralSettingProps) => { } }, [updater.errorMsg, setErrorMsg]) + const [isScreenKeepAwake, setIsScreenKeepAwake] = useState(keepScreenAwake.get()) + const onChangeScreenKeepAwake = useCallback((v: boolean) => { + keepScreenAwake.save(v) + setIsScreenKeepAwake(v) + if (v) { + wakeScreen() + } else { + releaseWakeLock() + } + }, []) + return (

{t('settings.general.version')} v{newVersion || currentVersion}

- @@ -189,6 +207,7 @@ const GeneralSetting = ({ updater }: GeneralSettingProps) => {

{t('settings.general.language')}

+
+

{t('settings.general.keep-awake')}

+ +
{ } = useNoDiskSpace(navigate) const needConfirm = newCkbDataPath && newCkbDataPath !== oldCkbDataPath + useEffect(() => { + if (keepScreenAwake.get()) { + wakeScreen() + } + }, []) + return (
diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index 5cc728b75c..5e16c40df8 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -394,7 +394,8 @@ "version": "Version", "language": "Language", "select-language": "Select Language", - "apply": "Apply" + "apply": "Apply", + "keep-awake": "Keep the screen awake during synchronization" }, "wallet-manager": { "edit-wallet": { diff --git a/packages/neuron-ui/src/locales/es.json b/packages/neuron-ui/src/locales/es.json index 7ee4f72514..590e452f5f 100644 --- a/packages/neuron-ui/src/locales/es.json +++ b/packages/neuron-ui/src/locales/es.json @@ -386,7 +386,8 @@ "version": "Versión", "language": "Idioma", "select-language": "Seleccionar Idioma", - "apply": "Aplicar" + "apply": "Aplicar", + "keep-awake": "Mantener la pantalla encendida durante la sincronización" }, "wallet-manager": { "edit-wallet": { diff --git a/packages/neuron-ui/src/locales/fr.json b/packages/neuron-ui/src/locales/fr.json index 7d39eebac9..c42bfc3594 100644 --- a/packages/neuron-ui/src/locales/fr.json +++ b/packages/neuron-ui/src/locales/fr.json @@ -393,7 +393,8 @@ "version": "Version", "language": "Langue", "select-language": "Sélectionner la langue", - "apply": "Appliquer" + "apply": "Appliquer", + "keep-awake": "Maintenir l'écran allumé pendant la synchronisation" }, "wallet-manager": { "edit-wallet": { diff --git a/packages/neuron-ui/src/locales/zh-tw.json b/packages/neuron-ui/src/locales/zh-tw.json index e3d4260af5..b6b4baad1d 100644 --- a/packages/neuron-ui/src/locales/zh-tw.json +++ b/packages/neuron-ui/src/locales/zh-tw.json @@ -389,7 +389,8 @@ "version": "版本", "language": "語言", "select-language": "選擇語言", - "apply": "應用" + "apply": "應用", + "keep-awake": "同步期間保持屏幕喚醒" }, "wallet-manager": { "edit-wallet": { diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 0611594ee6..c837c54415 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -387,7 +387,8 @@ "version": "版本", "language": "系统语言", "select-language": "选择语言", - "apply": "应用" + "apply": "应用", + "keep-awake": "同步期间保持屏幕唤醒" }, "wallet-manager": { "edit-wallet": { diff --git a/packages/neuron-ui/src/services/localCache.ts b/packages/neuron-ui/src/services/localCache.ts index 02ae5b823e..a53f75513c 100644 --- a/packages/neuron-ui/src/services/localCache.ts +++ b/packages/neuron-ui/src/services/localCache.ts @@ -11,6 +11,7 @@ export enum LocalCacheKey { LoadedWalletIDs = 'loadedWalletIDs', ImportedWallet = 'ImportedWallet', ShownNodeId = 'ShownNodeId', + ScreenAwake = 'ScreenAwake', } export const addresses = { @@ -165,3 +166,13 @@ export const lastShowInternalNodeIds = { window.localStorage.setItem(`${type}_${LocalCacheKey.ShownNodeId}`, id) }, } + +export const keepScreenAwake = { + get: () => { + const value = window.localStorage.getItem(LocalCacheKey.ScreenAwake) + return !!value && value === 'true' + }, + save: (value: boolean) => { + window.localStorage.setItem(LocalCacheKey.ScreenAwake, value.toString()) + }, +} diff --git a/packages/neuron-ui/src/utils/index.ts b/packages/neuron-ui/src/utils/index.ts index eb762f388d..4fe2f818d6 100644 --- a/packages/neuron-ui/src/utils/index.ts +++ b/packages/neuron-ui/src/utils/index.ts @@ -28,5 +28,6 @@ export * from './multisig' export * from './getNetworkLabel' export * from './calculateUsedCapacity' export * from './outPointTransform' +export * from './wakeScreen' export { CONSTANTS } diff --git a/packages/neuron-ui/src/utils/wakeScreen.ts b/packages/neuron-ui/src/utils/wakeScreen.ts new file mode 100644 index 0000000000..20e2ff6109 --- /dev/null +++ b/packages/neuron-ui/src/utils/wakeScreen.ts @@ -0,0 +1,28 @@ +let wakeLock: WakeLockSentinel | undefined + +async function reAwake() { + if (document.visibilityState === 'visible') { + wakeLock = await navigator.wakeLock.request('screen') + } else { + wakeLock?.release() + wakeLock = undefined + } +} + +export async function wakeScreen() { + if (wakeLock) return + try { + wakeLock = await navigator.wakeLock.request('screen') + document.addEventListener('visibilitychange', reAwake) + } catch (err) { + // do nothing here + } +} + +export async function releaseWakeLock() { + if (wakeLock) { + await wakeLock.release() + document.removeEventListener('visibilitychange', reAwake) + wakeLock = undefined + } +} From de1df5d57b8589d7f94065d33ada8570a1969493 Mon Sep 17 00:00:00 2001 From: Tom Wang Date: Fri, 12 Apr 2024 17:36:18 +0800 Subject: [PATCH 11/18] refactor: rewrite sudtValueToAmount with formatUnit in neuron-wallet (#3119) --- .../src/utils/sudt-value-to-amount.ts | 37 ++++--------------- .../utils/sudt-value-to-amount/fixtures.json | 10 +++++ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/packages/neuron-wallet/src/utils/sudt-value-to-amount.ts b/packages/neuron-wallet/src/utils/sudt-value-to-amount.ts index 4791a68544..37c1ed2c03 100644 --- a/packages/neuron-wallet/src/utils/sudt-value-to-amount.ts +++ b/packages/neuron-wallet/src/utils/sudt-value-to-amount.ts @@ -1,32 +1,11 @@ -const sudtValueToAmount = (value: string | null | undefined = '0', decimal: string | null | undefined = '') => { - if (value === null || value === '0') { - return '+0' - } - - if (decimal === null || decimal === undefined || Number.isNaN(+value)) { - return '--' - } - - let sign = '+' - if (value.startsWith('-')) { - 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}${decimalFraction}` - } - return `${sign}${unsignedSUDTValue}` +import { formatUnit } from '@ckb-lumos/bi' + +const sudtValueToAmount = (value: string | null = '0', decimal: string | null = '') => { + return value === null || value === '0' + ? '+0' + : decimal === null || Number.isNaN(+value) || Number.isNaN(+decimal) + ? '--' + : `${+value >= 0 ? '+' : ''}${formatUnit(BigInt(value), +decimal)}` } export default sudtValueToAmount diff --git a/packages/neuron-wallet/tests/utils/sudt-value-to-amount/fixtures.json b/packages/neuron-wallet/tests/utils/sudt-value-to-amount/fixtures.json index d98624cd1e..f4b1c9c6e5 100644 --- a/packages/neuron-wallet/tests/utils/sudt-value-to-amount/fixtures.json +++ b/packages/neuron-wallet/tests/utils/sudt-value-to-amount/fixtures.json @@ -14,11 +14,21 @@ "decimal": "12", "expected": "+0" }, + "null value and null decimal": { + "value": null, + "decimal": null, + "expected": "+0" + }, "zero value": { "value": "0", "decimal": "1", "expected": "+0" }, + "zero value and null decimal": { + "value": "0", + "decimal": null, + "expected": "+0" + }, "negative value": { "value": "-1", "decimal": "1", From 5fe467e73cc607d53d82dc4c28bd379708569ca2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 13 Apr 2024 12:57:57 +0900 Subject: [PATCH 12/18] Update ckb client versions (#3122) feat: update ckb client versions Co-authored-by: Keith-CY --- .ckb-light-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ckb-light-version b/.ckb-light-version index d379b578ae..534baa8df5 100644 --- a/.ckb-light-version +++ b/.ckb-light-version @@ -1 +1 @@ -v0.3.6 +v0.3.7 From f05cff7624e97a8bd7cb4dd451b56e7b6fe62053 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 14 Apr 2024 22:16:23 +0900 Subject: [PATCH 13/18] chore: Update ckb node assume valid target (#3123) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- packages/neuron-wallet/.env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/neuron-wallet/.env b/packages/neuron-wallet/.env index ea6ce9081c..f32862920f 100644 --- a/packages/neuron-wallet/.env +++ b/packages/neuron-wallet/.env @@ -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 From 59fef75a3daaba63d58236572caebb02a8122787 Mon Sep 17 00:00:00 2001 From: Keith Date: Sun, 14 Apr 2024 22:40:50 +0900 Subject: [PATCH 14/18] chore: update versions and changelogs --- CHANGELOG.md | 29 +++++++++++++++++++++++++++++ lerna.json | 2 +- package.json | 2 +- packages/neuron-ui/package.json | 2 +- packages/neuron-wallet/package.json | 4 ++-- 5 files changed, 34 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c618b3b53..1442482595 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,32 @@ +# 0.114.3 (2024-04-16) + +### CKB Node & Light Client + +- [CKB@v0.114.0](https://github.com/nervosnetwork/ckb/releases/tag/v0.114.0) was released on Feb. 29st, 2024. This version of CKB node is now bundled and preconfigured in Neuron. +- [CKB Light Client@v0.3.7](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 diff --git a/lerna.json b/lerna.json index 85d52c39c0..0e77734cb4 100644 --- a/lerna.json +++ b/lerna.json @@ -1,6 +1,6 @@ { "packages": ["packages/*"], - "version": "0.114.2", + "version": "0.114.3", "npmClient": "yarn", "$schema": "node_modules/lerna/schemas/lerna-schema.json" } diff --git a/package.json b/package.json index aa0b2ab372..0f08c1da14 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/neuron-ui/package.json b/packages/neuron-ui/package.json index ba3c788a3d..9901985b4f 100644 --- a/packages/neuron-ui/package.json +++ b/packages/neuron-ui/package.json @@ -1,6 +1,6 @@ { "name": "neuron-ui", - "version": "0.114.2", + "version": "0.114.3", "private": true, "author": { "name": "Nervos Core Dev", diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 48e38216b0..f59790491c 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -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", @@ -97,7 +97,7 @@ "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" } } From 359d7b784408b7c82696ab2356c71fd0c2ab832c Mon Sep 17 00:00:00 2001 From: Tom Wang Date: Tue, 16 Apr 2024 16:37:13 +0800 Subject: [PATCH 15/18] refactor: rewrite sudtValueToAmount with formatUnit in neuron-ui (#3126) * refactor: rewrite sudtValueToAmount with formatUnit in neuron-ui * Add comment for using any type Co-authored-by: homura --------- Co-authored-by: homura --- packages/neuron-ui/package.json | 1 + .../formatters/sudtValueToAmount/fixtures.ts | 14 +++++- packages/neuron-ui/src/utils/formatters.ts | 49 +++++-------------- packages/neuron-ui/src/utils/getSUDTAmount.ts | 2 +- 4 files changed, 26 insertions(+), 40 deletions(-) diff --git a/packages/neuron-ui/package.json b/packages/neuron-ui/package.json index ba3c788a3d..a36fc216d9 100644 --- a/packages/neuron-ui/package.json +++ b/packages/neuron-ui/package.json @@ -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", diff --git a/packages/neuron-ui/src/tests/formatters/sudtValueToAmount/fixtures.ts b/packages/neuron-ui/src/tests/formatters/sudtValueToAmount/fixtures.ts index a91adedd80..e6ec65d7b8 100644 --- a/packages/neuron-ui/src/tests/formatters/sudtValueToAmount/fixtures.ts +++ b/packages/neuron-ui/src/tests/formatters/sudtValueToAmount/fixtures.ts @@ -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', + }, } diff --git a/packages/neuron-ui/src/utils/formatters.ts b/packages/neuron-ui/src/utils/formatters.ts index ea630e6fad..45dc1f36e0 100644 --- a/packages/neuron-ui/src/utils/formatters.ts +++ b/packages/neuron-ui/src/utils/formatters.ts @@ -1,3 +1,4 @@ +import { formatUnit } from '@ckb-lumos/bi' import { molecule } from '@ckb-lumos/codec' import { blockchain } from '@ckb-lumos/base' import { TFunction } from 'i18next' @@ -236,45 +237,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(Number(value))) { + console.warn(`Invalid sudt value: ${value}`) } - if (Number.isNaN(+value)) { - console.warn(`sUDT value is not a valid number`) - return showPositiveSign ? '+0' : '0' - } - 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) => { diff --git a/packages/neuron-ui/src/utils/getSUDTAmount.ts b/packages/neuron-ui/src/utils/getSUDTAmount.ts index d8c66a1ce6..ac151fdc1d 100644 --- a/packages/neuron-ui/src/utils/getSUDTAmount.ts +++ b/packages/neuron-ui/src/utils/getSUDTAmount.ts @@ -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, From e26700932f5942c59b17a7bfdf0b6d375012c1c2 Mon Sep 17 00:00:00 2001 From: Keith Date: Wed, 17 Apr 2024 03:06:18 +0900 Subject: [PATCH 16/18] docs: update ckb version in release note --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1442482595..a35aea95a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### CKB Node & Light Client -- [CKB@v0.114.0](https://github.com/nervosnetwork/ckb/releases/tag/v0.114.0) was released on Feb. 29st, 2024. This version of CKB node is now bundled and preconfigured in Neuron. +- [CKB@v0.115.0](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 Client@v0.3.7](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 From 5b64e719fdeca51cc89e2f8601fb735be8ab635b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E5=9B=BD=E5=AE=87?= <841185308@qq.com> Date: Wed, 17 Apr 2024 13:59:02 +0800 Subject: [PATCH 17/18] fix: If all of the previous Tx hashes are cell base, skip fetch tx. (#3125) --- .../src/block-sync-renderer/sync/light-synchronizer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/neuron-wallet/src/block-sync-renderer/sync/light-synchronizer.ts b/packages/neuron-wallet/src/block-sync-renderer/sync/light-synchronizer.ts index 1adccf187b..ece089a109 100644 --- a/packages/neuron-wallet/src/block-sync-renderer/sync/light-synchronizer.ts +++ b/packages/neuron-wallet/src/block-sync-renderer/sync/light-synchronizer.ts @@ -262,6 +262,7 @@ export default class LightSynchronizer extends Synchronizer { previousTxHashes.add(previousTxHash) } }) + if (!previousTxHashes.size) return await this.lightRpc.createBatchRequest([...previousTxHashes].map(v => ['fetchTransaction' as keyof Base, v])).exec() } From ab2e85d66d9075f9dfc62a3ad54c14cca26e30ad Mon Sep 17 00:00:00 2001 From: devchenyan Date: Wed, 17 Apr 2024 14:40:37 +0800 Subject: [PATCH 18/18] fix: Pop up window can be rolled when error message is long (#3118) fix: AlertDialog title Co-authored-by: Chen Yu --- .../neuron-ui/src/widgets/AlertDialog/alertDialog.module.scss | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/neuron-ui/src/widgets/AlertDialog/alertDialog.module.scss b/packages/neuron-ui/src/widgets/AlertDialog/alertDialog.module.scss index b89b270757..2ed26542cf 100644 --- a/packages/neuron-ui/src/widgets/AlertDialog/alertDialog.module.scss +++ b/packages/neuron-ui/src/widgets/AlertDialog/alertDialog.module.scss @@ -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 {