Skip to content

Commit

Permalink
[fix][652] convert hex to string memo (#3616)
Browse files Browse the repository at this point in the history
* feat: update UI send method transaction

* merged from sere

* remove unused code

* Update: check method name

* fix: disable decode when transaction is send with memo

* update: convert hex to string
  • Loading branch information
TranTrungTien authored Jul 10, 2024
1 parent 48f9234 commit dd238bc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 95 deletions.
8 changes: 8 additions & 0 deletions src/app/core/utils/ethers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ export async function addNetwork(chain) {
}
}

export const hex2a = (hex: string) => {
if(!hex && typeof hex != 'string') return "";
const data = hex.toString();
let str = '';
for (let i = 0; i < data.length; i += 2)
str += String.fromCharCode(parseInt(data.substr(i, 2), 16));
return str;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,96 +79,4 @@
</button>
</div>
</div>
</div>
<div class="decode-message">
<div *ngIf="isDataField" class="d-flex align-items-start highlight">
<div class="flex-grow-1 data-field-msg">
<div *ngIf="type === 'Hex'">
<p class="font-space-mono">{{ data }}</p>
</div>
<div *ngIf="type === 'Decode'">
<div class="data-item">
<ng-container *ngFor="let item of data">
<p class="font-space-mono item-name">{{item?.name}}</p>
<a *ngIf="item?.isLink" class="text--primary" routerLink="/address/{{ item?.decode }}">
{{item?.decode}}
</a>
<div *ngIf="!item?.isLink">
<div *ngIf="item?.type === 'tuple'" class="d-flex flex-wrap gap-2 align-items-center">
<div *ngFor="let dataDecoded of item?.decode">
<a *ngIf="dataDecoded?.isLink" class="text--primary" routerLink="/address/{{ dataDecoded?.name }}">
{{dataDecoded?.name}}
</a>
<p *ngIf="!dataDecoded?.isLink" class="font-space-mono" >{{dataDecoded?.name}}</p>
</div>
</div>
<div *ngIf="item?.type !== 'tuple'">
<p class="font-space-mono" >{{item?.decode}}</p>
</div>
</div>
</ng-container>
</div>
</div>
</div>
<div class="button-container">
<button
class="button-data body-04 button-dec"
[class.active]="type === 'Decode'"
(click)="onDecode('data')">
<span>Dec</span>
</button>
<button
class="button-data body-04 button-hex"
[class.active]="type === 'Hex'"
(click)="onHex()">
<span>Hex</span>
</button>
</div>
</div>
</div>
<div class="decode-message">
<div *ngIf="isDataField" class="d-flex align-items-start highlight">
<div class="flex-grow-1 data-field-msg">
<div *ngIf="type === 'Hex'">
<p class="font-space-mono">{{ data }}</p>
</div>
<div *ngIf="type === 'Decode'">
<div class="data-item">
<ng-container *ngFor="let item of data">
<p class="font-space-mono item-name">{{item?.name}}</p>
<a *ngIf="item?.isLink" class="text--primary" routerLink="/address/{{ item?.decode }}">
{{item?.decode}}
</a>
<div *ngIf="!item?.isLink">
<div *ngIf="item?.type === 'tuple'" class="d-flex flex-wrap gap-2 align-items-center">
<div *ngFor="let dataDecoded of item?.decode">
<a *ngIf="dataDecoded?.isLink" class="text--primary" routerLink="/address/{{ dataDecoded?.name }}">
{{dataDecoded?.name}}
</a>
<p *ngIf="!dataDecoded?.isLink" class="font-space-mono" >{{dataDecoded?.name}}</p>
</div>
</div>
<div *ngIf="item?.type !== 'tuple'">
<p class="font-space-mono" >{{item?.decode}}</p>
</div>
</div>
</ng-container>
</div>
</div>
</div>
<div class="button-container">
<button
class="button-data body-04 button-dec"
[class.active]="type === 'Decode'"
(click)="onDecode('data')">
<span>Dec</span>
</button>
<button
class="button-data body-04 button-hex"
[class.active]="type === 'Hex'"
(click)="onHex()">
<span>Hex</span>
</button>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</ng-container>
</div>

<div class="log-data body-02 break-word box-decoded overflow-auto" *ngIf="typeInput === inputDataType.DECODED">
<div class="log-data body-02 break-word box-decoded" *ngIf="typeInput === inputDataType.DECODED">
<ng-container *ngIf="isEvmContract">
<ng-container *ngIf="!env.isMobile">
<div class="row pb-3 text--gray-4 body-01 fw-semibold decoded-header">
Expand Down Expand Up @@ -108,7 +108,7 @@
</div>

<div
class="log-data break-word font-space-mono overflow-auto"
class="log-data break-word font-space-mono"
*ngIf="typeInput === inputDataType.ORIGINAL"
[appExpandable]="transaction?.inputData"
[maxCharVisible]="500">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CommonService } from 'src/app/core/services/common.service';
import { ContractService } from 'src/app/core/services/contract.service';
import { TransactionService } from 'src/app/core/services/transaction.service';
import { getBalance } from 'src/app/core/utils/common/parsing';
import { hex2a } from 'src/app/core/utils/ethers/utils';

@Component({
selector: 'app-evm-transaction',
Expand Down Expand Up @@ -131,7 +132,7 @@ export class EvmTransactionComponent implements OnChanges {
next: (res) => {
if (res?.evm_smart_contract?.length > 0)
this.isEvmContract = true;
else this.transaction.memo = this.transaction.inputData as any;
else this.transaction.memo = hex2a(this.transaction.inputData as any);
},
});
}
Expand Down

0 comments on commit dd238bc

Please sign in to comment.