Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
saveStakingPreferences = async (
wallet: TheWallet,
prefs: any,
accountAddress: string
): Promise => {
Logger.debug('api::saveStakingPreferences called');
Logger.debug(`wallet: ${JSON.stringify(wallet)}`);
try {
const originalWallet = this.reloadWallet(wallet);
await originalWallet.unlock(''); // TODO switch to pin code
Logger.debug('api::saveStakingPreferences unlock');
this.api.setSigner(originalWallet);
Logger.debug('api::saveStakingPreferences setSigner');
const validatorPrefs = new ValidatorPrefs(prefs);
const intentionIndex = await this.getIntentionIndex(accountAddress);
const txHash = await this.api.tx.staking
.registerPreferences(intentionIndex, validatorPrefs)
.signAndSend(accountAddress);
Logger.debug(`api::saveStakingPreferences txHash ${txHash}`);
return txHash;
} catch (error) {
Logger.error('api::saveStakingPreferences error: ' + stringifyError(error));
throw new GenericApiError();
}
};