Skip to content

Commit

Permalink
Merge pull request zingolabs#731 from juanky201271/dev_parse_address_…
Browse files Browse the repository at this point in the history
…command_fixes

Parse address & viewkey status fixed
  • Loading branch information
juanky201271 authored Oct 15, 2024
2 parents 0ea5d6a + f98f200 commit 44bc707
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 18 deletions.
4 changes: 4 additions & 0 deletions app/rpc/enums/RPCParseAddressStatusEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum RPCParseAddressStatusEnum {
successAddressParse = 'success',
invalidAddressParse = 'Invalid address',
}
4 changes: 0 additions & 4 deletions app/rpc/enums/RPCParseStatusEnum.ts

This file was deleted.

4 changes: 4 additions & 0 deletions app/rpc/enums/RPCParseViewKeyStatusEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum RPCParseViewKeyStatusEnum {
successViewKeyParse = 'success',
invalidViewKeyParse = 'Invalid viewkey',
}
4 changes: 2 additions & 2 deletions app/rpc/types/RPCParseAddressType.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ChainNameEnum } from '../../AppState';
import { RPCAddressKindEnum } from '../enums/RPCAddressKindEnum';
import { RPCParseStatusEnum } from '../enums/RPCParseStatusEnum';
import { RPCParseAddressStatusEnum } from '../enums/RPCParseAddressStatusEnum';
import { RPCReceiversEnum } from '../enums/RPCReceiversEnum';

export type RPCParseAddressType = {
status: RPCParseStatusEnum;
status: RPCParseAddressStatusEnum;
chain_name?: ChainNameEnum;
address_kind?:
| RPCAddressKindEnum.unifiedAddressKind
Expand Down
4 changes: 2 additions & 2 deletions app/rpc/types/RPCParseViewKeyType.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ChainNameEnum } from '../../AppState';
import { RPCAddressKindEnum } from '../enums/RPCAddressKindEnum';
import { RPCParseStatusEnum } from '../enums/RPCParseStatusEnum';
import { RPCParseViewKeyStatusEnum } from '../enums/RPCParseViewKeyStatusEnum';
import { RPCPoolsEnum } from '../enums/RPCPoolsEnum';

export type RPCParseViewKeyType = {
status: RPCParseStatusEnum;
status: RPCParseViewKeyStatusEnum;
chain_name?: ChainNameEnum;
address_kind?: RPCAddressKindEnum.ufvkAddressKind;
pools_available?: RPCPoolsEnum[];
Expand Down
12 changes: 7 additions & 5 deletions app/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import randomColor from 'randomcolor';
import RPCModule from '../RPCModule';
import { Buffer } from 'buffer';
import { RPCParseAddressType } from '../rpc/types/RPCParseAddressType';
import { RPCParseStatusEnum } from '../rpc/enums/RPCParseStatusEnum';
import { RPCParseAddressStatusEnum } from '../rpc/enums/RPCParseAddressStatusEnum';
import { RPCAddressKindEnum } from '../rpc/enums/RPCAddressKindEnum';

export default class Utils {
Expand Down Expand Up @@ -310,7 +310,7 @@ export default class Utils {
const result: string = await RPCModule.execute(CommandEnum.parseAddress, address);
//console.log(result);
if (result) {
if (result.toLowerCase().startsWith(GlobalConst.error) || result.toLowerCase() === 'null') {
if (result.toLowerCase().startsWith(GlobalConst.error)) {
return false;
}
} else {
Expand All @@ -325,14 +325,16 @@ export default class Utils {

//console.log('parse-address', address, resultJSON, resultJSON.status === RPCParseStatusEnum.successParse);

return resultJSON.status === RPCParseStatusEnum.successParse && resultJSON.chain_name === serverChainName;
return (
resultJSON.status === RPCParseAddressStatusEnum.successAddressParse && resultJSON.chain_name === serverChainName
);
}

static async isValidOrchardOrSaplingAddress(address: string, serverChainName: string): Promise<boolean> {
const result: string = await RPCModule.execute(CommandEnum.parseAddress, address);
//console.log(result);
if (result) {
if (result.toLowerCase().startsWith(GlobalConst.error) || result.toLowerCase() === 'null') {
if (result.toLowerCase().startsWith(GlobalConst.error)) {
return false;
}
} else {
Expand All @@ -348,7 +350,7 @@ export default class Utils {
//console.log('parse-memo', address, resultJSON);

return (
resultJSON.status === RPCParseStatusEnum.successParse &&
resultJSON.status === RPCParseAddressStatusEnum.successAddressParse &&
resultJSON.address_kind !== RPCAddressKindEnum.transparentAddressKind &&
resultJSON.address_kind !== RPCAddressKindEnum.texAddressKind &&
resultJSON.chain_name === serverChainName
Expand Down
9 changes: 6 additions & 3 deletions components/Send/components/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ButtonTypeEnum, CommandEnum, PrivacyLevelFromEnum, GlobalConst } from '
import { CurrencyEnum } from '../../../app/AppState';
import { RPCAddressKindEnum } from '../../../app/rpc/enums/RPCAddressKindEnum';
import { RPCReceiversEnum } from '../../../app/rpc/enums/RPCReceiversEnum';
import { RPCParseStatusEnum } from '../../../app/rpc/enums/RPCParseStatusEnum';
import { RPCParseAddressStatusEnum } from '../../../app/rpc/enums/RPCParseAddressStatusEnum';

type ConfirmProps = {
calculatedFee: number;
Expand Down Expand Up @@ -127,7 +127,7 @@ const Confirm: React.FunctionComponent<ConfirmProps> = ({

const result: string = await RPCModule.execute(CommandEnum.parseAddress, sendPageState.toaddr.to);
if (result) {
if (result.toLowerCase().startsWith(GlobalConst.error) || result.toLowerCase() === 'null') {
if (result.toLowerCase().startsWith(GlobalConst.error)) {
return '-';
}
} else {
Expand All @@ -143,7 +143,10 @@ const Confirm: React.FunctionComponent<ConfirmProps> = ({

//console.log('parse-address', sendPageState.toaddr.to, resultJSON.status === RPCParseStatusEnum.successParse);

if (resultJSON.status !== RPCParseStatusEnum.successParse || resultJSON.chain_name !== server.chainName) {
if (
resultJSON.status !== RPCParseAddressStatusEnum.successAddressParse ||
resultJSON.chain_name !== server.chainName
) {
return '-';
}

Expand Down
5 changes: 3 additions & 2 deletions components/Ufvk/ImportUfvk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import 'moment/locale/es';
import 'moment/locale/pt';
import 'moment/locale/ru';
import { ButtonTypeEnum, CommandEnum, GlobalConst } from '../../app/AppState';
import { RPCParseStatusEnum } from '../../app/rpc/enums/RPCParseStatusEnum';
import { RPCParseViewKeyStatusEnum } from '../../app/rpc/enums/RPCParseViewKeyStatusEnum';

type ImportUfvkProps = {
onClickCancel: () => void;
Expand Down Expand Up @@ -103,7 +103,8 @@ const ImportUfvk: React.FunctionComponent<ImportUfvkProps> = ({ onClickCancel, o

//console.log('parse ufvk', scannedKey, resultJSON);

const valid = resultJSON.status === RPCParseStatusEnum.successParse && resultJSON.chain_name === server.chainName;
const valid =
resultJSON.status === RPCParseViewKeyStatusEnum.successViewKeyParse && resultJSON.chain_name === server.chainName;

if (valid) {
return true;
Expand Down

0 comments on commit 44bc707

Please sign in to comment.