Skip to content

Commit

Permalink
Extract isDustPayment to a helper
Browse files Browse the repository at this point in the history
  • Loading branch information
CassioMG committed Jan 15, 2025
1 parent 779ab0f commit e485309
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
12 changes: 12 additions & 0 deletions extension/src/popup/helpers/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ export const getIsSupportedSorobanOp = (
export const getIsSwap = (operation: HorizonOperation) =>
operation.type_i === 13 && operation.source_account === operation.to;

export const getIsDustPayment = (
publicKey: string,
operation: HorizonOperation,
) =>
getIsPayment(operation.type) &&
"asset_type" in operation &&
operation.asset_type === "native" &&
"to" in operation &&
operation.to === publicKey &&
"amount" in operation &&
new BigNumber(operation.amount).lte(new BigNumber(0.1));

interface SortOperationsByAsset {
operations: HorizonOperation[];
balances: AssetType[] | SorobanBalance[];
Expand Down
17 changes: 7 additions & 10 deletions extension/src/popup/views/AccountHistory/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Text } from "@stellar/design-system";
import BigNumber from "bignumber.js";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useSelector } from "react-redux";
Expand All @@ -11,7 +10,11 @@ import {
settingsSelector,
} from "popup/ducks/settings";
import { transactionSubmissionSelector } from "popup/ducks/transactionSubmission";
import { getIsPayment, getIsSwap } from "popup/helpers/account";
import {
getIsDustPayment,
getIsPayment,
getIsSwap,
} from "popup/helpers/account";
import { getMonthLabel } from "popup/helpers/getMonthLabel";

import {
Expand Down Expand Up @@ -81,14 +84,8 @@ export const AccountHistory = () => {
operation.type ===
Horizon.HorizonApi.OperationResponseType.createAccount &&
operation.account !== publicKey;
const isDustPayment =
isPayment &&
"asset_type" in operation &&
operation.asset_type === "native" &&
"to" in operation &&
operation.to === publicKey &&
"amount" in operation &&
new BigNumber(operation.amount).lte(new BigNumber(0.1));
const isDustPayment = getIsDustPayment(publicKey, operation);

const parsedOperation = {
...operation,
isPayment,
Expand Down

0 comments on commit e485309

Please sign in to comment.