'use strict' ; import { VSCodeBlockchainOutputAdapter } from '../logging/VSCodeBlockchainOutputAdapter' ; import { GatewayAssociatedTreeItem } from '../explorer/model/GatewayAssociatedTreeItem' ; import { IBlockchainQuickPickItem , UserInputUtil } from './UserInputUtil' ; import { LogType , FabricGatewayRegistry , FabricGatewayRegistryEntry } from 'ibm-blockchain-platform-common' ; export async function dissociateWallet ( associatedGatewayTreeItem ) { const outputAdapter = VSCodeBlockchainOutputAdapter . instance ( ) ; outputAdapter . log ( LogType . INFO , undefined , 'dissociateWallet' ) ; let gateway ; if ( ! associatedGatewayTreeItem ) { let gateways = [ ] ; gateways = await FabricGatewayRegistry . instance ( ) . getAll ( false ) ; if ( gateways . length === 0 ) { outputAdapter . log ( LogType . ERROR , `No gateways to dissociate found. Local gateways cannot be dissociated from their wallet.` ) ; return ; } const chosenGateway = await UserInputUtil . showGatewayQuickPickBox ( 'Pick a gateway to dissociate a wallet for' , false , false , true ) as IBlockchainQuickPickItem < FabricGatewayRegistryEntry > ; if ( ! chosenGateway ) { return ; } gateway = chosenGateway . data ; } else { gateway = associatedGatewayTreeItem . gateway ; } try { const fabricGatewayRegistry = FabricGatewayRegistry . instance ( ) ; gateway . associatedWallet = '' ; await fabricGatewayRegistry . update ( gateway ) ; const gatewayName = gateway . name ; outputAdapter . log ( LogType . SUCCESS , `Successfully dissociated wallet from "${ gatewayName }" gateway` ) ; } catch ( error ) { outputAdapter . log ( LogType . ERROR , `Unable to dissociate wallet: ${ error . message }` , `Unable to dissociate wallet: ${ error . toString ( ) }` ) ; } }