Skip to content

Commit

Permalink
Fix zk transaction detail
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdfx committed Nov 6, 2024
1 parent 3d53fa7 commit 84ef081
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion scripts/post-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function writeManifestFile(targetPath, fileContent) {

(async () => {
try {
const id = "1019";
const id = "1020";

const chromeFileName = `${pck.name}-chrome-edge-${pck.version}-${id}`;
const firefoxFileName = `${pck.name}-firefox-${pck.version}-${id}`;
Expand Down
9 changes: 7 additions & 2 deletions src/popup/pages/Wallet/component/TxListView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,13 @@ const TxItem = ({

amount = getBalanceForUI(result.totalBalanceChange, MAIN_COIN_CONFIG.decimals, 2);
amount = result.symbol + amount;
let isZkReceive = result.symbol !== "-"
showAddress = isZkReceive ? addressSlice(result.from, 8):addressSlice(result.to, 8)
if(result.symbol == "-"){
showAddress = addressSlice(result.to, 8)
}else if(result.symbol == "+"){
showAddress = addressSlice(result.from, 8)
}else{
showAddress = addressSlice(result.to, 8)
}
}
}
if (!showAddress) {
Expand Down
39 changes: 27 additions & 12 deletions src/utils/zkUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ export function getZkAppUpdateInfo(accountUpdates, publicKey, tokenId) {
let otherList = [];
accountUpdates.forEach((update) => {
const { body } = update;
const magnitude = new BigNumber(body.balanceChange.magnitude)
.abs()
.toString();
if (body.tokenId === tokenId) {
const magnitude = new BigNumber(body.balanceChange.magnitude)
.abs()
.toString();
if (body.publicKey === publicKey) {
if (body.balanceChange.sgn === "Negative") {
totalBalanceChange = new BigNumber(totalBalanceChange)
Expand All @@ -330,34 +330,49 @@ export function getZkAppUpdateInfo(accountUpdates, publicKey, tokenId) {
.toString();
}
} else {
updateList.push({
address: body.publicKey,
amount: magnitude,
});
if (!new BigNumber(magnitude).isZero()) {
updateList.push({
address: body.publicKey,
amount: magnitude,
});
}
}
}
if (body.publicKey !== publicKey) {
otherList.push(body.publicKey);
otherList.push({
address: body.publicKey,
amount: magnitude,
});
}
});
if (updateList.length !== 0) {
updateList.sort((a, b) => b.amount - a.amount);
}
if (otherList.length !== 0) {
otherList.sort((a, b) => b.amount - a.amount);
}

let symbol = "";
let from = "";
let to = "";

if (totalBalanceChange > 0) {
symbol = "+";

from = updateList.length > 0 ? updateList[0].address : otherList[0];
from =
updateList.length > 0 ? updateList[0].address : otherList[0]?.address;
to = publicKey;
} else if (totalBalanceChange < 0) {
symbol = "-";
totalBalanceChange = new BigNumber(totalBalanceChange).abs().toString();
from = publicKey;
to = updateList.length > 0 ? updateList[0].address : otherList[0];
to =
updateList.length > 0 ? updateList[0].address : otherList[0]?.address;
} else {
to =
updateList.length > 0 ? updateList[0].address : otherList[0]?.address;
from = publicKey;
}

return {
totalBalanceChange,
symbol,
Expand All @@ -374,4 +389,4 @@ export function getZkAppUpdateInfo(accountUpdates, publicKey, tokenId) {
to: "-",
};
}
}
}

0 comments on commit 84ef081

Please sign in to comment.