Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ADN-314] Fix GNOT sending error #338

Merged
merged 1 commit into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/adena-extension/src/common/utils/client-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { validateAddress } from 'adena-module';
import gnotLogo from '@assets/gnot-logo.svg';
import contractLogo from '@assets/contract.svg';
import addPkgLogo from '@assets/addpkg.svg';
Expand Down Expand Up @@ -33,7 +34,9 @@ export function getDateDiff(d: Date | string): number {
return new Date().getDate() - new Date(d).getDate();
}

export function dateTimeFormatEn(d: Date | string): {
export function dateTimeFormatEn(
d: Date | string,
): {
year: string;
month: string;
day: string;
Expand Down Expand Up @@ -168,9 +171,7 @@ export function numberWithCommas(value: number, fixed?: number): string {
}

export function addressValidationCheck(v: string): boolean {
const startStringCheck = /^g1/;
const atozAndNumberCheck = /^[a-z0-9]{40}$/;
return startStringCheck.test(v) && atozAndNumberCheck.test(v) ? true : false;
return validateAddress(v);
}

export function removeUgly(target: any): any {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Account } from 'adena-module';

import { AddressBookValidationError } from '@common/errors/validation/address-book-validation-error';
import { addressValidationCheck } from '@common/utils/client-utils';
import { AddressBookItem } from '@repositories/wallet';
import { Account } from 'adena-module';

export const validateInvalidAddress = (address: string): boolean => {
const invalidCheck = addressValidationCheck(address);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { fonts, getTheme } from '@styles/theme';

export const ApproveTransactionWrapper = styled.div<{ isErrorNetworkFee: boolean }>`
${mixins.flex({ justify: 'flex-start' })};
width: 100%;
padding: 0 20px;
margin-bottom: 96px;
align-self: center;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const ApproveTransactionContainer: React.FC = () => {
const hash = transactionService.createHash(signed);
const response = await new Promise<BroadcastTxCommitResult | BroadcastTxSyncResult | TM2Error | null>((resolve) => {
transactionService
.sendTransaction(wallet, currentAccount, signed)
.sendTransaction(wallet, currentAccount, signed, true)
.then(resolve)
.catch((error: TM2Error | Error) => {
resolve(error);
Expand Down Expand Up @@ -285,7 +285,7 @@ const ApproveTransactionContainer: React.FC = () => {

const onResponseSendTransaction = useCallback(() => {
if (response) {
chrome.runtime.sendMessage(response);
// chrome.runtime.sendMessage(response);
}
}, [response]);

Expand Down
10 changes: 10 additions & 0 deletions packages/adena-module/src/utils/address.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { KeySigner } from '@gnolang/tm2-js-client';
import { fromBech32 } from '../encoding';

export async function publicKeyToAddress(
publicKey: Uint8Array,
addressPrefix: string = 'g',
): Promise<string> {
return new KeySigner(new Uint8Array(), publicKey, addressPrefix).getAddress();
}

export function validateAddress(address: string): boolean {
try {
const publicKey = fromBech32(address);
return Boolean(publicKey?.prefix);
} catch {
return false;
}
}
1 change: 1 addition & 0 deletions packages/adena-module/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { assert, assertDefined, assertDefinedAndNotNull } from './assert';
export { sleep } from './sleep';
export { isDefined, isNonNullObject, isUint8Array } from './typechecks';
export * from './messages';
export * from './address';
4 changes: 3 additions & 1 deletion packages/adena-module/src/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export interface Document {
function encodeMessageValue(message: { type: string; value: any }) {
switch (message.type) {
case MsgEndpoint.MSG_ADD_PKG:
const value = message.value;
const msgAddPkg = MsgAddPackage.create(value);
return {
typeUrl: MsgEndpoint.MSG_ADD_PKG,
value: MsgAddPackage.encode(message.value).finish(),
value: MsgAddPackage.encode(msgAddPkg).finish(),
};
case MsgEndpoint.MSG_CALL:
return {
Expand Down
Loading