diff --git a/packages/neuron-wallet/package.json b/packages/neuron-wallet/package.json index 2fbc19f631..db9ddb637f 100644 --- a/packages/neuron-wallet/package.json +++ b/packages/neuron-wallet/package.json @@ -42,14 +42,15 @@ ] }, "dependencies": { - "@ckb-lumos/base": "^0.21.0-next.1", - "@ckb-lumos/bi": "^0.21.0-next.1", - "@ckb-lumos/ckb-indexer": "^0.21.0-next.1", - "@ckb-lumos/codec": "^0.21.0-next.1", - "@ckb-lumos/config-manager": "^0.21.0-next.1", - "@ckb-lumos/hd": "^0.21.0-next.1", - "@ckb-lumos/helpers": "^0.21.0-next.1", - "@ckb-lumos/rpc": "^0.21.0-next.1", + "@ckb-lumos/base": "0.21.0-next.1", + "@ckb-lumos/bi": "0.21.0-next.1", + "@ckb-lumos/ckb-indexer": "0.21.0-next.1", + "@ckb-lumos/codec": "0.21.0-next.1", + "@ckb-lumos/common-scripts": "0.21.0-next.1", + "@ckb-lumos/config-manager": "0.21.0-next.1", + "@ckb-lumos/hd": "0.21.0-next.1", + "@ckb-lumos/helpers": "0.21.0-next.1", + "@ckb-lumos/rpc": "0.21.0-next.1", "@iarna/toml": "2.2.5", "@ledgerhq/hw-transport-node-hid": "6.27.16", "@spore-sdk/core": "0.1.0-beta.9", diff --git a/packages/neuron-wallet/src/services/transaction-sender.ts b/packages/neuron-wallet/src/services/transaction-sender.ts index 65eaa02ccd..e25bc57611 100644 --- a/packages/neuron-wallet/src/services/transaction-sender.ts +++ b/packages/neuron-wallet/src/services/transaction-sender.ts @@ -41,11 +41,11 @@ import { getMultisigStatus } from '../utils/multisig' import { SignStatus } from '../models/offline-sign' import NetworksService from './networks' import { generateRPC } from '../utils/ckb-rpc' -import { CKBRPC } from '@ckb-lumos/rpc' import CellsService from './cells' import hd from '@ckb-lumos/hd' import { getClusterCellByOutPoint } from '@spore-sdk/core' import CellDep, { DepType } from '../models/chain/cell-dep' +import { dao } from '@ckb-lumos/common-scripts' interface SignInfo { witnessArgs: WitnessArgs @@ -840,9 +840,25 @@ export default class TransactionSender { withdrawBlockHash: string ): Promise => { const currentNetwork = NetworksService.getInstance().getCurrent() - const ckb = new CKBRPC(currentNetwork.remote) - const result = await ckb.calculateDaoMaximumWithdraw(depositOutPoint.toSDK(), withdrawBlockHash) - return BigInt(result) + const rpc = generateRPC(currentNetwork.remote, currentNetwork.type) + + let tx = await rpc.getTransaction(depositOutPoint.txHash) + if (tx.txStatus.status !== 'committed') throw new Error('Transaction is not committed yet') + const depositBlockHash = tx.txStatus.blockHash + + const cellOutput = tx.transaction.outputs[+depositOutPoint.index] + const cellOutputData = tx.transaction.outputsData[+depositOutPoint.index] + + const [depositHeader, withDrawHeader] = await Promise.all([ + rpc.getHeader(depositBlockHash), + rpc.getHeader(withdrawBlockHash), + ]) + + return dao.calculateMaximumWithdraw( + { outPoint: depositOutPoint.toSDK(), data: cellOutputData, cellOutput: cellOutput }, + depositHeader.dao, + withDrawHeader.dao + ) } private parseEpoch = (epoch: bigint) => { diff --git a/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts b/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts index fae1b30919..692208d273 100644 --- a/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts +++ b/packages/neuron-wallet/tests/services/tx/transaction-sender.test.ts @@ -158,10 +158,20 @@ jest.doMock('@ckb-lumos/rpc', () => { } }) +jest.doMock('@ckb-lumos/common-scripts', () => { + return { + dao: { + calculateMaximumWithdraw: stubbedCalculateDaoMaximumWithdraw, + }, + } +}) + jest.doMock('utils/ckb-rpc.ts', () => ({ generateRPC() { return { sendTransaction: stubbedSendTransaction, + getTransaction: stubbedGetTransaction, + getHeader: stubbedGetHeader, } }, })) @@ -802,7 +812,7 @@ describe('TransactionSender Test', () => { } stubbedGetHeader.mockResolvedValue(withdrawBlockHeader) - stubbedCalculateDaoMaximumWithdraw.mockResolvedValue(10300000000) + stubbedCalculateDaoMaximumWithdraw.mockResolvedValue(BigInt(10300000000)) stubbedGetNextAddress.mockReturnValue({ address: fakeAddress1, }) diff --git a/yarn.lock b/yarn.lock index 7457799bb0..8a2996bbc2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1703,7 +1703,7 @@ js-xxhash "^1.0.4" lodash.isequal "^4.5.0" -"@ckb-lumos/base@0.21.0-next.1", "@ckb-lumos/base@^0.21.0-next.1": +"@ckb-lumos/base@0.21.0-next.1": version "0.21.0-next.1" resolved "https://registry.yarnpkg.com/@ckb-lumos/base/-/base-0.21.0-next.1.tgz#ad82d0147c479b84bc0e80c3e32ad6a39ee75285" integrity sha512-dJL3pqa28oJcNfYLNOuWRIJCeWhUq9l7l2/SZItb9wIT4MX5pD0Z1tA8/s9qbvwmmsab+QGKaLCHXNNeOvS0hg== @@ -1724,7 +1724,7 @@ dependencies: jsbi "^4.1.0" -"@ckb-lumos/bi@0.21.0-next.1", "@ckb-lumos/bi@^0.21.0-next.1": +"@ckb-lumos/bi@0.21.0-next.1": version "0.21.0-next.1" resolved "https://registry.yarnpkg.com/@ckb-lumos/bi/-/bi-0.21.0-next.1.tgz#357b8da31882ab5e3e3f8aca54c30dd576e4544d" integrity sha512-FaMKBbtr826upcEVYt9/K/hutxHySD21t7ut5yv8lfj6LYcg6hWjtrbCM2INVV6/8HatfAf8YV2KsNRaluyt3A== @@ -1743,7 +1743,7 @@ cross-fetch "^3.1.5" events "^3.3.0" -"@ckb-lumos/ckb-indexer@^0.21.0-next.1": +"@ckb-lumos/ckb-indexer@0.21.0-next.1": version "0.21.0-next.1" resolved "https://registry.yarnpkg.com/@ckb-lumos/ckb-indexer/-/ckb-indexer-0.21.0-next.1.tgz#bc2fd6fcd2c482040565c255d7a9f8fd9269b462" integrity sha512-ftT8Rodv/oXIOZLfsXEOLQnHy05c8Wj3h6QasXPlZlRGMdtWrThGz+XVI6lz4VSIfVMPSbwnYT+Dv7bf8fDfdw== @@ -1763,7 +1763,7 @@ dependencies: "@ckb-lumos/bi" "0.20.0" -"@ckb-lumos/codec@0.21.0-next.1", "@ckb-lumos/codec@^0.21.0-next.1": +"@ckb-lumos/codec@0.21.0-next.1": version "0.21.0-next.1" resolved "https://registry.yarnpkg.com/@ckb-lumos/codec/-/codec-0.21.0-next.1.tgz#a75f5331026039799afb4f3419bea388e220d26c" integrity sha512-b1w4wbIAbuYngNTKtu6np93EYgnmM4tb6NGdaYN0vZ3kyunlODkLWyRHyMo+FGeBdWQjBwBbmxGNyXwDxtTEGQ== @@ -1784,6 +1784,20 @@ "@ckb-lumos/toolkit" "0.20.0" immutable "^4.0.0-rc.12" +"@ckb-lumos/common-scripts@0.21.0-next.1": + version "0.21.0-next.1" + resolved "https://registry.yarnpkg.com/@ckb-lumos/common-scripts/-/common-scripts-0.21.0-next.1.tgz#92e0295f9e123f3fdfe80e02706cc08c6310ffca" + integrity sha512-KhnWbNY1fNKTxp9CR4GAGyWsjjN1eOvidNLFwltLY03n8er2jtoHRbx3t944fIhUMtIwUVkWBi43SqpUCgSJbw== + dependencies: + "@ckb-lumos/base" "0.21.0-next.1" + "@ckb-lumos/bi" "0.21.0-next.1" + "@ckb-lumos/codec" "0.21.0-next.1" + "@ckb-lumos/config-manager" "0.21.0-next.1" + "@ckb-lumos/helpers" "0.21.0-next.1" + "@ckb-lumos/rpc" "0.21.0-next.1" + "@ckb-lumos/toolkit" "0.21.0-next.1" + immutable "^4.3.0" + "@ckb-lumos/config-manager@0.20.0", "@ckb-lumos/config-manager@^0.20.0": version "0.20.0" resolved "https://registry.yarnpkg.com/@ckb-lumos/config-manager/-/config-manager-0.20.0.tgz#f24946971005f62df62e22c3306947b5e820c181" @@ -1795,7 +1809,7 @@ "@types/deep-freeze-strict" "^1.1.0" deep-freeze-strict "^1.1.1" -"@ckb-lumos/config-manager@0.21.0-next.1", "@ckb-lumos/config-manager@^0.21.0-next.1": +"@ckb-lumos/config-manager@0.21.0-next.1": version "0.21.0-next.1" resolved "https://registry.yarnpkg.com/@ckb-lumos/config-manager/-/config-manager-0.21.0-next.1.tgz#927e21a5d9450155ebf766422a707fd3b0856a14" integrity sha512-G8CO+q1RH/Gt8ou8p/N99AUh5hIdU+MZcTZHwABOa4CLbXk2xFenRfeGhHv4u4ddYZ3SLx1zND7pSnbImmrh2A== @@ -1819,7 +1833,7 @@ sha3 "^2.1.3" uuid "^8.3.0" -"@ckb-lumos/hd@^0.21.0-next.1": +"@ckb-lumos/hd@0.21.0-next.1": version "0.21.0-next.1" resolved "https://registry.yarnpkg.com/@ckb-lumos/hd/-/hd-0.21.0-next.1.tgz#ffa4b80b974187982bbfa280138ca1dab0b2df0e" integrity sha512-gISrSs4OWoBVecRnYMfjYQc83aE0Khjjs1KmAkAg1J53PWGeU3kjbUQSCHjF6poFL5ylEARX9vOKixRfm6nktg== @@ -1844,7 +1858,7 @@ bech32 "^2.0.0" immutable "^4.0.0-rc.12" -"@ckb-lumos/helpers@^0.21.0-next.1": +"@ckb-lumos/helpers@0.21.0-next.1": version "0.21.0-next.1" resolved "https://registry.yarnpkg.com/@ckb-lumos/helpers/-/helpers-0.21.0-next.1.tgz#f0f2d9e231f5a266d53df0c60e7b7610b87e10b5" integrity sha512-lSvn2L97be7IlONFTdjjz+/jG6QlpEGyETyrcSfJxeOOtgjicPFaLXLnaTBIt/IElRZ2ZpclbTFvSNcbVOvKdQ== @@ -1883,7 +1897,7 @@ axios "0.27.2" tslib "2.3.1" -"@ckb-lumos/rpc@0.21.0-next.1", "@ckb-lumos/rpc@^0.21.0-next.1": +"@ckb-lumos/rpc@0.21.0-next.1": version "0.21.0-next.1" resolved "https://registry.yarnpkg.com/@ckb-lumos/rpc/-/rpc-0.21.0-next.1.tgz#f31610fc1713ae63e25475d3653ee8cc3eeabc0f" integrity sha512-6IjnME2wGg1rmVnajQ7CTBqbLnXkdNqRERRmnD1J9EnoHBc+onSYSfkC58ZCVCOe0xZIR2vNKmOUQ++dmlKKiQ==