@@ -16,6 +16,7 @@ import { WalletListSubject, CurrentWalletSubject } from 'models/subjects/wallets
1616import dataUpdateSubject from 'models/subjects/data-update'
1717import CommandSubject from 'models/subjects/command'
1818import WindowManager from 'models/window-manager'
19+ import CellsService from 'services/cells'
1920
2021import NodeService from './node'
2122import FileService from './file'
@@ -315,7 +316,7 @@ export default class WalletService {
315316 throw new IsRequired ( 'Password' )
316317 }
317318
318- const addressInfos = await this . getAddressInfos ( )
319+ const addressInfos = await this . getAddressInfos ( walletID )
319320
320321 const addresses : string [ ] = addressInfos . map ( info => info . address )
321322
@@ -371,10 +372,31 @@ export default class WalletService {
371372 return txHash
372373 }
373374
375+ public computeCycles = async ( walletID : string = '' , capacities : string ) : Promise < string > => {
376+ const wallet = await this . get ( walletID )
377+ if ( ! wallet ) {
378+ throw new WalletNotFound ( walletID )
379+ }
380+
381+ const addressInfos = await this . getAddressInfos ( walletID )
382+
383+ const addresses : string [ ] = addressInfos . map ( info => info . address )
384+
385+ const lockHashes : string [ ] = await LockUtils . addressesToAllLockHashes ( addresses )
386+
387+ const { inputs } = await CellsService . gatherInputs ( capacities , lockHashes , '0' )
388+ const cycles = BigInt ( 1387008 ) * BigInt ( inputs . length )
389+
390+ return cycles . toString ( )
391+ }
392+
374393 // path is a BIP44 full path such as "m/44'/309'/0'/0/0"
375- public getAddressInfos = async ( ) : Promise < AddressInterface [ ] > => {
376- const walletId = this . getCurrent ( ) ! . id
377- const addrs = await AddressService . allAddressesByWalletId ( walletId )
394+ public getAddressInfos = async ( walletID : string ) : Promise < AddressInterface [ ] > => {
395+ const wallet = await this . get ( walletID )
396+ if ( ! wallet ) {
397+ throw new WalletNotFound ( walletID )
398+ }
399+ const addrs = await AddressService . allAddressesByWalletId ( walletID )
378400 return addrs
379401 }
380402
0 commit comments