'use strict' ; import * as vscode from 'vscode' ; import { WalletTreeItem } from '../explorer/wallets/WalletTreeItem' ; import { UserInputUtil , IBlockchainQuickPickItem } from './UserInputUtil' ; import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter' ; import { FabricWalletRegistry , FabricWalletRegistryEntry , LogType , FabricGatewayRegistry , FabricGatewayRegistryEntry } from 'ibm-blockchain-platform-common' ; export async function removeWallet ( treeItem ) { const outputAdapter = VSCodeBlockchainOutputAdapter . instance ( ) ; outputAdapter . log ( LogType . INFO , undefined , `removeWallet` ) ; let walletsToDelete ; if ( ! treeItem ) { let wallets = [ ] ; wallets = await FabricWalletRegistry . instance ( ) . getAll ( false ) ; if ( wallets . length === 0 ) { outputAdapter . log ( LogType . ERROR , `No wallets to remove. Local wallets cannot be removed.` ) ; return ; } const chosenWallet = await UserInputUtil . showWalletsQuickPickBox ( 'Choose the wallet(s) that you want to remove' , true , false ) as IBlockchainQuickPickItem < FabricWalletRegistryEntry > [ ] ; if ( ! chosenWallet || chosenWallet . length === 0 ) { return ; } walletsToDelete = chosenWallet . map ( ( _wallet ) => { return _wallet . data ; } ) ; } else { walletsToDelete = [ treeItem . registryEntry ] ; } const deleteFsWallet = await vscode . window . showWarningMessage ( `This will remove the wallet(s). Do you want to continue?` , 'Yes' , 'No' ) ; if ( deleteFsWallet === undefined ) { return ; } else if ( deleteFsWallet === 'Yes' ) { for ( const _wallet of walletsToDelete ) { await FabricWalletRegistry . instance ( ) . delete ( _wallet . name ) ; const gateways = await FabricGatewayRegistry . instance ( ) . getAll ( false ) ; for ( const gateway of gateways ) { if ( gateway . associatedWallet === _wallet . name ) { gateway . associatedWallet = '' ; await FabricGatewayRegistry . instance ( ) . update ( gateway ) ; } } } if ( walletsToDelete . length > 1 ) { outputAdapter . log ( LogType . SUCCESS , `Successfully removed wallets` ) ; } else { outputAdapter . log ( LogType . SUCCESS , `Successfully removed ${ walletsToDelete [ 0 ] . name } wallet` ) ; } } }