Skip to content

Commit

Permalink
Use constants
Browse files Browse the repository at this point in the history
  • Loading branch information
reyraa committed Dec 27, 2021
1 parent 6e958c2 commit 940b555
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/utils/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,26 +227,26 @@ const flattenTransaction = ({ moduleAssetId, asset, ...rest }) => {
};

switch (moduleAssetId) {
case MODULE_ASSETS_NAME_ID_MAP.transfer: {
case transfer: {
transaction.recipientAddress = asset.recipient.address;
transaction.amount = asset.amount;
transaction.data = asset.data;
break;
}

case MODULE_ASSETS_NAME_ID_MAP.voteDelegate:
case voteDelegate:
transaction.votes = asset.votes;
break;

case MODULE_ASSETS_NAME_ID_MAP.registerDelegate:
case registerDelegate:
transaction.username = asset.username;
break;

case MODULE_ASSETS_NAME_ID_MAP.unlockToken:
case unlockToken:
transaction.unlockObjects = asset.unlockObjects;
break;

case MODULE_ASSETS_NAME_ID_MAP.registerMultisignatureGroup: {
case registerMultisignatureGroup: {
transaction.numberOfSignatures = asset.numberOfSignatures;
transaction.mandatoryKeys = asset.mandatoryKeys;
transaction.optionalKeys = asset.optionalKeys;
Expand Down Expand Up @@ -498,13 +498,14 @@ const signUsingPrivateKey = (schema, transaction, networkIdentifier, privateKey)
Buffer.from(privateKey, 'hex'),
);

const signUsingHW = async (schema, transaction, account, networkIdentifier, network) => {
const signUsingHW = async (schema, transaction, account, networkIdentifier, network, keys) => {
const signingBytes = transactions.getSigningBytes(schema, transaction);
const [error, signedTransaction] = await to(signTransactionByHW(
account,
networkIdentifier,
transaction,
signingBytes,
keys,
));
if (error) {
throw error;
Expand All @@ -519,7 +520,9 @@ export const sign = async (
moduleAssetId, rawTransaction, privateKey,
) => {
if (!isEmpty(account.hwInfo)) {
const signedTx = await signUsingHW(schema, transaction, account, networkIdentifier, network);
const signedTx = await signUsingHW(
schema, transaction, account, networkIdentifier, network, keys,
);
return signedTx;
}
if (isMultisignature || isMultiSignatureRegistration) {
Expand Down Expand Up @@ -556,8 +559,7 @@ const signMultisigTransaction = async (
* Define keys.
* Since the sender is different, the keys are defined based on that
*/
const isGroupRegistration = transaction.moduleAssetId
=== MODULE_ASSETS_NAME_ID_MAP.registerMultisignatureGroup;
const isGroupRegistration = transaction.moduleAssetId === registerMultisignatureGroup;
const schema = network.networks.LSK.moduleAssetSchemas[transaction.moduleAssetId];
const networkIdentifier = Buffer.from(network.networks.LSK.networkIdentifier, 'hex');

Expand Down Expand Up @@ -607,7 +609,7 @@ const signMultisigTransaction = async (
* @returns {number} the number of signatures required
*/
const getNumberOfSignatures = (account, transaction) => {
if (transaction?.moduleAssetId === MODULE_ASSETS_NAME_ID_MAP.registerMultisignatureGroup) {
if (transaction?.moduleAssetId === registerMultisignatureGroup) {
return transaction.optionalKeys.length + transaction.mandatoryKeys.length + 1;
}
if (account?.summary?.isMultisignature) {
Expand Down

0 comments on commit 940b555

Please sign in to comment.