Skip to content

Commit 1eebd89

Browse files
authored
fix: [ADN-407] Fix an error of broadcasting signed tx (#357)
2 parents be36531 + 0bda438 commit 1eebd89

File tree

3 files changed

+20
-31
lines changed

3 files changed

+20
-31
lines changed

packages/adena-extension/src/hooks/wallet/broadcast-transaction/use-broadcast-transaction-screen.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { useCallback, useMemo, useState } from 'react';
2-
import {
3-
RawBankSendMessage,
4-
RawTx,
5-
RawVmAddPackageMessage,
6-
RawVmCallMessage,
7-
strToSignedTx,
8-
} from 'adena-module';
2+
import { RawTx, strToSignedTx } from 'adena-module';
93
import { Tx } from '@gnolang/tm2-js-client';
104

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

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

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

8680
function mapVmAddPackageTransactionInfo(rawTx: RawTx): TransactionDisplayInfo[] {
87-
const message = rawTx.msg[0] as RawVmAddPackageMessage;
81+
const message = rawTx.msg[0] as any;
8882
const networkFee = makeGnotAmountByRaw(rawTx.fee.gas_fee);
8983
const networkFeeStr = `${networkFee?.value} ${networkFee?.denom}`;
9084
const extraInfo = rawTx.msg.length > 1 ? `${rawTx.msg.length}` : '';
@@ -169,7 +163,10 @@ const useBroadcastTransactionScreen = (): UseBroadcastTransactionScreenReturn =>
169163
.then((response) => {
170164
return Boolean(response?.hash);
171165
})
172-
.catch(() => false);
166+
.catch((e) => {
167+
console.error(e);
168+
return false;
169+
});
173170

174171
if (isSuccessBroadcasting) {
175172
navigate(RoutePath.Wallet);

packages/adena-module/src/utils/messages.ts

+11-19
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,25 @@ function encodeMessageValue(message: { type: string; value: any }) {
2626
case MsgEndpoint.MSG_ADD_PKG:
2727
const value = message.value;
2828
const msgAddPkg = MsgAddPackage.create(value);
29-
return {
29+
return Any.create({
3030
typeUrl: MsgEndpoint.MSG_ADD_PKG,
3131
value: MsgAddPackage.encode(msgAddPkg).finish(),
32-
};
32+
});
3333
case MsgEndpoint.MSG_CALL:
34-
return {
34+
return Any.create({
3535
typeUrl: MsgEndpoint.MSG_CALL,
3636
value: MsgCall.encode(message.value).finish(),
37-
};
37+
});
3838
case MsgEndpoint.MSG_SEND:
39-
return {
39+
return Any.create({
4040
typeUrl: MsgEndpoint.MSG_SEND,
41-
value: MsgSend.encode(message.value).finish(),
42-
};
41+
value: MsgSend.encode(MsgSend.create(message.value)).finish(),
42+
});
4343
default:
44-
return {
44+
return Any.create({
4545
typeUrl: MsgEndpoint.MSG_CALL,
46-
value: MsgCall.encode(message.value).finish(),
47-
};
46+
value: MsgCall.encode(MsgCall.create(message.value)).finish(),
47+
});
4848
}
4949
}
5050

@@ -178,15 +178,7 @@ export const strToSignedTx = (str: string): Tx | null => {
178178
gasWanted: sortedDocument.fee.gas_wanted,
179179
gasFee: sortedDocument.fee.gas_fee,
180180
}),
181-
signatures: rawTx.signatures.map((signature: any) =>
182-
TxSignature.fromJSON({
183-
...signature,
184-
pubKey: {
185-
...signature.pub_key,
186-
typeUrl: signature.pub_key['@type'],
187-
},
188-
}),
189-
),
181+
signatures: rawTx.signatures.map(TxSignature.fromJSON),
190182
memo: sortedDocument.memo,
191183
};
192184
} catch (e) {

packages/adena-module/src/wallet/keyring/address-keyring.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe('tx encode of address keyring', () => {
296296
const encodedTx = uint8ArrayToBase64(Tx.encode(signedTx).finish());
297297

298298
expect(encodedTx).toBe(
299-
'CoUBCgovdm0ubV9jYWxsEncKKGcxamc4bXR1dHU5a2hoZndjNG54bXVoY3BmdGYwcGFqZGhmdnNxZjUaFGduby5sYW5kL3IvZGVtby90b25nIghUcmFuc2ZlciooZzFrY2RkM24wZDQ3MmcycDVsOHN2eWc5dDB3cTZoNTg1N25xOTkyZioBMRINCIDRyggSBjF1Z25vdBp8CjgKEy90bS5QdWJLZXlTZWNwMjU2azESIQPhYTbbFx4y30iZNZQfBW4i+Jhj43OdCrfNSexCg5ydshJA6Jk3gs564wGTutNdODztNUlg88/WHmMPmJGRZHDuV00Mc9M5gGWBZDEpGysLsqzjMDxmsTu1PLtTYfTj0KphGQ==',
299+
'CoUBCgovdm0ubV9jYWxsEncKKGcxamc4bXR1dHU5a2hoZndjNG54bXVoY3BmdGYwcGFqZGhmdnNxZjUaFGduby5sYW5kL3IvZGVtby90b25nIghUcmFuc2ZlciooZzFrY2RkM24wZDQ3MmcycDVsOHN2eWc5dDB3cTZoNTg1N25xOTkyZioBMRINCIDRyggSBjF1Z25vdBpCEkDomTeCznrjAZO60104PO01SWDzz9YeYw+YkZFkcO5XTQxz0zmAZYFkMSkbKwuyrOMwPGaxO7U8u1Nh9OPQqmEZ',
300300
);
301301
});
302302
});

0 commit comments

Comments
 (0)