Skip to content

Commit

Permalink
Update lisk client to alpha 10 (#4696)
Browse files Browse the repository at this point in the history
* 🐛 Rename variable

* ⬆️ Bump lisk-client version

* ⬆️ Bump lisk-client version
Update transaction dryrun logic to handle the latest SDK changes

* ♻️ Fix import usage
  • Loading branch information
ManuGowda authored Jan 5, 2023
1 parent bec7d4f commit f7825ba
Show file tree
Hide file tree
Showing 8 changed files with 2,577 additions and 1,558 deletions.
4,060 changes: 2,526 additions & 1,534 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"@json-rpc-tools/utils": "1.7.6",
"@ledgerhq/hw-transport": "6.3.0",
"@ledgerhq/hw-transport-node-hid": "6.6.0",
"@liskhq/lisk-client": "6.0.0-alpha.6",
"@liskhq/lisk-client": "6.0.0-alpha.10",
"@tanstack/react-query": "4.0.10",
"@tanstack/react-query-devtools": "4.2.1",
"@walletconnect/sign-client": "2.0.0-rc.4",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/search/components/SearchBar/SearchBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const SearchBar = ({ className, history }) => {

const onSelectedRow = (type, value) => {
if (type === 'transactions') {
addSearchParamsToUrl(history, { modal: 'transactionDetails', transactionId: value });
addSearchParamsToUrl(history, { modal: 'transactionDetails', transactionID: value });
} else if (type === 'delegate-account') {
history.push(`${routes.validatorProfile.path}?${routes.explorer.searchParam}=${value}`);
} else {
Expand Down
26 changes: 20 additions & 6 deletions src/modules/transaction/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,17 @@ export const getTransactionFee = async ({
...transactionObject.params,
...(numberOfSignatures &&
!transactionObject.params.signatures?.length && {
signatures: allocateEmptySignaturesWithEmptyBuffer(numberOfSignatures),
}),
signatures: allocateEmptySignaturesWithEmptyBuffer(numberOfSignatures),
}),
},
},
paramsSchema,
senderAccount.numberOfSignatures
? {
numberOfSignatures: senderAccount.numberOfSignatures,
numberOfEmptySignatures:
mandatoryKeys.length + optionalKeys.length - senderAccount.numberOfSignatures,
}
numberOfSignatures: senderAccount.numberOfSignatures,
numberOfEmptySignatures:
mandatoryKeys.length + optionalKeys.length - senderAccount.numberOfSignatures,
}
: {}
);

Expand Down Expand Up @@ -312,6 +312,20 @@ export const broadcast = async ({ transaction, serviceUrl, moduleCommandSchemas
});
};

/**
* Dry run a transaction to verify if the transaction is valid to be broadcasted to network
* @param {*} param0
* @returns
* {
result: enum {
INVALID = -1,
FAIL = 0,
OK = 1,
},
errorMessage?: string,
events: EventJSON [],
}
*/
export const dryRun = ({ transaction, serviceUrl, network }) => {
const moduleCommand = joinModuleAndCommand({
module: transaction.module,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import header from './headerMap';
import { splitModuleAndCommand } from '../../utils';

const TransactionDetails = ({ location }) => {
const transactionID = parseSearchParams(location.search).transactionId;
const transactionID = parseSearchParams(location.search).transactionID;
const { t } = useTranslation();
const [isParamsCollapsed, setIsParamsCollapsed] = useState(false);

Expand Down
39 changes: 26 additions & 13 deletions src/modules/transaction/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,14 @@ export const transactionBroadcasted = (transaction, moduleCommandSchemas) =>
const activeToken = token.active;
const serviceUrl = network.networks[activeToken].serviceUrl;
let broadcastResult;
// @todo dry run before broadcast
const dryRunResult = await dryRun({ transaction, serviceUrl, network });
const dryRunResult = await dryRun({ transaction, serviceUrl, network });

if (dryRunResult.data?.success === true) {
if (dryRunResult.data?.result === 1) {
broadcastResult = await broadcast(
{ transaction, serviceUrl, moduleCommandSchemas },
);

if(!broadcastResult.data?.error) {
if (!broadcastResult.data?.error) {
const moduleCommand = joinModuleAndCommand(transaction);
const paramsSchema = moduleCommandSchemas[moduleCommand];
const transactionJSON = toTransactionJSON(transaction, paramsSchema);
Expand All @@ -166,17 +165,31 @@ export const transactionBroadcasted = (transaction, moduleCommandSchemas) =>
return true;
}
// @todo we need to push pending transaction to the query cache
// https://github.com/LiskHQ/lisk-desktop/issues/4698 should handle this logic
}

if (dryRunResult.data?.result === -1) {
dispatch({
type: actionTypes.broadcastedTransactionError,
data: {
error: dryRunResult.data?.errorMessage,
transaction,
},
});
}

// @todo Remove the third fallback error message when the Core API errors are implemented
dispatch({
type: actionTypes.broadcastedTransactionError,
data: {
error: dryRunResult.data?.message ?? broadcastResult?.error ?? 'An error occurred while broadcasting the transaction',
transaction,
},
});
if (dryRunResult.data?.result === 0) {
// @TODO: Prepare error message by parsing the events based on each transaction type
// https://github.com/LiskHQ/lisk-desktop/issues/4698 should resolve all the dry run related logic along with feedback
const temporaryError = dryRunResult.data?.events.map(e => e.name).join(', ')
dispatch({
type: actionTypes.broadcastedTransactionError,
data: {
error: temporaryError,
transaction,
},
});
}

return false;
};
Expand Down Expand Up @@ -210,7 +223,7 @@ export const multisigTransactionSigned = ({
moduleCommandSchemas[formProps.moduleCommand],
state.network.networks.LSK.chainID,
privateKey,
txInitiatorAccount, // this is the intitor of the transaction wanting to be signed
txInitiatorAccount, // this is the initiator of the transaction wanting to be signed
);

if (!error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/cypress/features/delegates/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Then(/^validator should be watched$/, function () {

Then(/^I should be on a stake transaction details modal$/, () => {
cy.location().should((location) => {
const hasAddress = /\?modal=transactionDetails&transactionId=a1c5521f466ae5476d3908cc8d562444d45adf4ac3af57e77f1f9359999ab9ca&token=LSK/.test(location.href);
const hasAddress = /\?modal=transactionDetails&transactionID=a1c5521f466ae5476d3908cc8d562444d45adf4ac3af57e77f1f9359999ab9ca&token=LSK/.test(location.href);
expect(hasAddress).true;
});
});
2 changes: 1 addition & 1 deletion tests/cypress/features/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ When(/^I select ([^\s]+) in ([^\s]+) field$/, function (value, field) {

Then(/^I should be on transaction details modal$/, function () {
cy.location().should((location) => {
const hasAddress = /\?modal=transactionDetails&transactionId=f3f4755b31eae903c8cf1e35f123e907fd8ed8e2b9feeae39bedd5c495326d62/.test(location.href);
const hasAddress = /\?modal=transactionDetails&transactionID=f3f4755b31eae903c8cf1e35f123e907fd8ed8e2b9feeae39bedd5c495326d62/.test(location.href);
expect(hasAddress).true;
});
});

0 comments on commit f7825ba

Please sign in to comment.