Skip to content

Commit

Permalink
Merge pull request anoma#54 from heliaxdev/bug/48-transfer-transactions
Browse files Browse the repository at this point in the history
bug/40 - Fix Received Transactions Not Shown
  • Loading branch information
jurevans authored May 11, 2022
2 parents 8366fce + 0e73388 commit 99c33d0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
15 changes: 11 additions & 4 deletions packages/anoma-wallet/src/App/Token/TokenDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ const TokenDetails = ({ persistor }: Props): JSX.Element => {
const token = Tokens[tokenType] || {};

// eslint-disable-next-line prefer-const
let transactions =
(accountTransactions[id] && [...accountTransactions[id]]) || [];
transactions.sort((a, b) => b.timestamp - a.timestamp);
const transactions = accountTransactions
.filter(
(transaction) =>
transaction.source === establishedAddress ||
transaction.target === establishedAddress
)
.reverse();

useEffect(() => {
dispatch(fetchBalanceByAccount(account));
Expand Down Expand Up @@ -128,7 +132,10 @@ const TokenDetails = ({ persistor }: Props): JSX.Element => {
<TransactionListItem key={`${appliedHash}:${timestamp}`}>
<div>
<strong>
{type ? "Received" : "Sent"} {amount} {tokenType}
{transaction.source === establishedAddress
? "Sent "
: "Received "}
({type}) {amount} {tokenType}
</strong>
<br />
{dateTimeFormatted}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ type TransferDetailsParams = {

const TransferDetail = (): JSX.Element => {
const navigate = useNavigate();
const { id = "", appliedHash = "" } = useParams<TransferDetailsParams>();
const { transactions: accountTransactions } = useAppSelector<TransfersState>(
const { appliedHash = "" } = useParams<TransferDetailsParams>();
const { transactions } = useAppSelector<TransfersState>(
(state) => state.transfers
);

const transactions = accountTransactions[id] || [];

const {
tokenType,
amount,
gas = 0,
timestamp = 0,
height = 0,
memo,
shielded,
source,
target,
type,
} = transactions.find(
Expand All @@ -47,11 +45,15 @@ const TransferDetail = (): JSX.Element => {
</NavigationContainer>
<p>
<strong>
{type ? "Received" : "Sent"} {amount} {tokenType}
{type}
<br />
{amount} {tokenType}
</strong>
<br />
{dateTimeFormatted}
</p>
<p>Source address:</p>
<Address>{source}</Address>
<p>Target address:</p>
<Address>{target}</Address>
<p>Applied hash:</p>
Expand All @@ -63,9 +65,6 @@ const TransferDetail = (): JSX.Element => {
Block height: <strong>{height}</strong>
</p>
<p>Notes: {memo ? memo : "n/a"}</p>
<p>
Shielded transaction?: <strong>{shielded ? "Yes!" : "No"}</strong>
</p>
</TransferDetailContainer>
);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/anoma-wallet/src/slices/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const submitInitAccountTransaction = createAsyncThunk(
establishedAddress,
};

if (url.match(/testnet/)) {
if (url.match(/testnet|localhost/)) {
dispatch(
submitTransferTransaction({
account: initializedAccount,
Expand Down
47 changes: 21 additions & 26 deletions packages/anoma-wallet/src/slices/transfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,22 @@ import { amountFromMicro, promiseWithTimeout } from "utils/helpers";
import { DerivedAccount, fetchBalanceByAccount } from "./accounts";

enum TransferType {
Sent,
Received,
IBC = "IBC",
Shielded = "Shielded",
NonShielded = "Non-Shielded",
}

export type TransferTransaction = {
tokenType: TokenType;
appliedHash: string;
source: string;
target: string;
type: TransferType;
amount: number;
memo?: string;
shielded: boolean;
gas: number;
height: number;
tokenType: TokenType;
gas: number;
appliedHash: string;
memo: string;
timestamp: number;
type: TransferType;
};

type TransferTransactions = {
[accountId: string]: TransferTransaction[];
};

type TransferEvents = {
Expand All @@ -34,7 +31,7 @@ type TransferEvents = {
};

export type TransfersState = {
transactions: TransferTransactions;
transactions: TransferTransaction[];
isTransferSubmitting: boolean;
transferError?: string;
events?: TransferEvents;
Expand Down Expand Up @@ -69,16 +66,19 @@ export const submitTransferTransaction = createAsyncThunk(
) => {
const {
id,
establishedAddress: source = "",
establishedAddress = "",
tokenType,
signingKey: privateKey,
} = account;

const source = useFaucet ? FAUCET_ADDRESS : establishedAddress;

const epoch = await rpcClient.queryEpoch();
const transfer = await new Transfer().init();
const token = Tokens[tokenType];

const { hash, bytes } = await transfer.makeTransfer({
source: useFaucet ? FAUCET_ADDRESS : source,
source,
target,
token: token.address || "",
amount,
Expand Down Expand Up @@ -117,23 +117,23 @@ export const submitTransferTransaction = createAsyncThunk(
id,
useFaucet,
transaction: {
source,
target,
appliedHash,
tokenType,
target,
amount,
memo,
shielded,
gas,
height,
timestamp: new Date().getTime(),
type: useFaucet ? TransferType.Received : TransferType.Sent,
type: shielded ? TransferType.Shielded : TransferType.NonShielded,
},
};
}
);

const initialState: TransfersState = {
transactions: {},
transactions: [],
isTransferSubmitting: false,
};

Expand Down Expand Up @@ -170,10 +170,8 @@ const transfersSlice = createSlice({
transaction: TransferTransaction;
}>
) => {
const { id, useFaucet, transaction } = action.payload;
const { useFaucet, transaction } = action.payload;
const { gas, appliedHash } = transaction;
const transactions = state.transactions[id] || [];
transactions.push(transaction);

state.isTransferSubmitting = false;
state.transferError = undefined;
Expand All @@ -185,10 +183,7 @@ const transfersSlice = createSlice({
}
: undefined;

state.transactions = {
...state.transactions,
[id]: transactions,
};
state.transactions.push(transaction);
}
);
},
Expand Down

0 comments on commit 99c33d0

Please sign in to comment.