Skip to content

Commit

Permalink
fix: [ADN-407] Fix an error of broadcasting signed tx (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss authored Jan 31, 2024
2 parents be36531 + 0bda438 commit 1eebd89
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { useCallback, useMemo, useState } from 'react';
import {
RawBankSendMessage,
RawTx,
RawVmAddPackageMessage,
RawVmCallMessage,
strToSignedTx,
} from 'adena-module';
import { RawTx, strToSignedTx } from 'adena-module';
import { Tx } from '@gnolang/tm2-js-client';

import { makeGnotAmountByRaw } from '@common/utils/amount-utils';
Expand Down Expand Up @@ -54,7 +48,7 @@ function makeTypeName(rawTx: RawTx): string {
}

function mapBankSendTransactionInfo(rawTx: RawTx): TransactionDisplayInfo[] {
const message = rawTx.msg[0] as RawBankSendMessage;
const message = rawTx.msg[0] as any;
const amount = makeGnotAmountByRaw(message.amount);
const amountStr = `${amount?.value} ${amount?.denom}`;
const networkFee = makeGnotAmountByRaw(rawTx.fee.gas_fee);
Expand All @@ -70,7 +64,7 @@ function mapBankSendTransactionInfo(rawTx: RawTx): TransactionDisplayInfo[] {
}

function mapVmCallTransactionInfo(rawTx: RawTx): TransactionDisplayInfo[] {
const message = rawTx.msg[0] as RawVmCallMessage;
const message = rawTx.msg[0] as any;
const networkFee = makeGnotAmountByRaw(rawTx.fee.gas_fee);
const networkFeeStr = `${networkFee?.value} ${networkFee?.denom}`;
const extraInfo = rawTx.msg.length > 1 ? `${rawTx.msg.length}` : '';
Expand All @@ -84,7 +78,7 @@ function mapVmCallTransactionInfo(rawTx: RawTx): TransactionDisplayInfo[] {
}

function mapVmAddPackageTransactionInfo(rawTx: RawTx): TransactionDisplayInfo[] {
const message = rawTx.msg[0] as RawVmAddPackageMessage;
const message = rawTx.msg[0] as any;
const networkFee = makeGnotAmountByRaw(rawTx.fee.gas_fee);
const networkFeeStr = `${networkFee?.value} ${networkFee?.denom}`;
const extraInfo = rawTx.msg.length > 1 ? `${rawTx.msg.length}` : '';
Expand Down Expand Up @@ -169,7 +163,10 @@ const useBroadcastTransactionScreen = (): UseBroadcastTransactionScreenReturn =>
.then((response) => {
return Boolean(response?.hash);
})
.catch(() => false);
.catch((e) => {
console.error(e);
return false;
});

if (isSuccessBroadcasting) {
navigate(RoutePath.Wallet);
Expand Down
30 changes: 11 additions & 19 deletions packages/adena-module/src/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ function encodeMessageValue(message: { type: string; value: any }) {
case MsgEndpoint.MSG_ADD_PKG:
const value = message.value;
const msgAddPkg = MsgAddPackage.create(value);
return {
return Any.create({
typeUrl: MsgEndpoint.MSG_ADD_PKG,
value: MsgAddPackage.encode(msgAddPkg).finish(),
};
});
case MsgEndpoint.MSG_CALL:
return {
return Any.create({
typeUrl: MsgEndpoint.MSG_CALL,
value: MsgCall.encode(message.value).finish(),
};
});
case MsgEndpoint.MSG_SEND:
return {
return Any.create({
typeUrl: MsgEndpoint.MSG_SEND,
value: MsgSend.encode(message.value).finish(),
};
value: MsgSend.encode(MsgSend.create(message.value)).finish(),
});
default:
return {
return Any.create({
typeUrl: MsgEndpoint.MSG_CALL,
value: MsgCall.encode(message.value).finish(),
};
value: MsgCall.encode(MsgCall.create(message.value)).finish(),
});
}
}

Expand Down Expand Up @@ -178,15 +178,7 @@ export const strToSignedTx = (str: string): Tx | null => {
gasWanted: sortedDocument.fee.gas_wanted,
gasFee: sortedDocument.fee.gas_fee,
}),
signatures: rawTx.signatures.map((signature: any) =>
TxSignature.fromJSON({
...signature,
pubKey: {
...signature.pub_key,
typeUrl: signature.pub_key['@type'],
},
}),
),
signatures: rawTx.signatures.map(TxSignature.fromJSON),
memo: sortedDocument.memo,
};
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe('tx encode of address keyring', () => {
const encodedTx = uint8ArrayToBase64(Tx.encode(signedTx).finish());

expect(encodedTx).toBe(
'CoUBCgovdm0ubV9jYWxsEncKKGcxamc4bXR1dHU5a2hoZndjNG54bXVoY3BmdGYwcGFqZGhmdnNxZjUaFGduby5sYW5kL3IvZGVtby90b25nIghUcmFuc2ZlciooZzFrY2RkM24wZDQ3MmcycDVsOHN2eWc5dDB3cTZoNTg1N25xOTkyZioBMRINCIDRyggSBjF1Z25vdBp8CjgKEy90bS5QdWJLZXlTZWNwMjU2azESIQPhYTbbFx4y30iZNZQfBW4i+Jhj43OdCrfNSexCg5ydshJA6Jk3gs564wGTutNdODztNUlg88/WHmMPmJGRZHDuV00Mc9M5gGWBZDEpGysLsqzjMDxmsTu1PLtTYfTj0KphGQ==',
'CoUBCgovdm0ubV9jYWxsEncKKGcxamc4bXR1dHU5a2hoZndjNG54bXVoY3BmdGYwcGFqZGhmdnNxZjUaFGduby5sYW5kL3IvZGVtby90b25nIghUcmFuc2ZlciooZzFrY2RkM24wZDQ3MmcycDVsOHN2eWc5dDB3cTZoNTg1N25xOTkyZioBMRINCIDRyggSBjF1Z25vdBpCEkDomTeCznrjAZO60104PO01SWDzz9YeYw+YkZFkcO5XTQxz0zmAZYFkMSkbKwuyrOMwPGaxO7U8u1Nh9OPQqmEZ',
);
});
});

0 comments on commit 1eebd89

Please sign in to comment.