From 3c6ae8e115f7a41ae1915e54124a576320346e79 Mon Sep 17 00:00:00 2001 From: "Justin R. Evans" Date: Wed, 11 May 2022 07:31:24 -0400 Subject: [PATCH 1/2] Updating transfer transactions state --- .../src/App/Token/TokenDetails.tsx | 15 ++++-- .../App/Token/Transfers/TransferDetails.tsx | 15 +++--- packages/anoma-wallet/src/slices/accounts.ts | 2 +- packages/anoma-wallet/src/slices/transfers.ts | 47 +++++++++---------- 4 files changed, 39 insertions(+), 40 deletions(-) diff --git a/packages/anoma-wallet/src/App/Token/TokenDetails.tsx b/packages/anoma-wallet/src/App/Token/TokenDetails.tsx index 9d9429fa01..1c9f87cd4b 100644 --- a/packages/anoma-wallet/src/App/Token/TokenDetails.tsx +++ b/packages/anoma-wallet/src/App/Token/TokenDetails.tsx @@ -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)); @@ -128,7 +132,10 @@ const TokenDetails = ({ persistor }: Props): JSX.Element => {
- {type ? "Received" : "Sent"} {amount} {tokenType} + {transaction.source === establishedAddress + ? "Sent " + : "Received "} + ({type}) {amount} {tokenType}
{dateTimeFormatted} diff --git a/packages/anoma-wallet/src/App/Token/Transfers/TransferDetails.tsx b/packages/anoma-wallet/src/App/Token/Transfers/TransferDetails.tsx index f533334135..3db495d08c 100644 --- a/packages/anoma-wallet/src/App/Token/Transfers/TransferDetails.tsx +++ b/packages/anoma-wallet/src/App/Token/Transfers/TransferDetails.tsx @@ -13,13 +13,11 @@ type TransferDetailsParams = { const TransferDetail = (): JSX.Element => { const navigate = useNavigate(); - const { id = "", appliedHash = "" } = useParams(); - const { transactions: accountTransactions } = useAppSelector( + const { appliedHash = "" } = useParams(); + const { transactions } = useAppSelector( (state) => state.transfers ); - const transactions = accountTransactions[id] || []; - const { tokenType, amount, @@ -27,7 +25,7 @@ const TransferDetail = (): JSX.Element => { timestamp = 0, height = 0, memo, - shielded, + source, target, type, } = transactions.find( @@ -47,11 +45,13 @@ const TransferDetail = (): JSX.Element => {

- {type ? "Received" : "Sent"} {amount} {tokenType} + {type} {amount} {tokenType}
{dateTimeFormatted}

+

Source address:

+
{source}

Target address:

{target}

Applied hash:

@@ -63,9 +63,6 @@ const TransferDetail = (): JSX.Element => { Block height: {height}

Notes: {memo ? memo : "n/a"}

-

- Shielded transaction?: {shielded ? "Yes!" : "No"} -

); }; diff --git a/packages/anoma-wallet/src/slices/accounts.ts b/packages/anoma-wallet/src/slices/accounts.ts index 20d49b66e7..341e7680ef 100644 --- a/packages/anoma-wallet/src/slices/accounts.ts +++ b/packages/anoma-wallet/src/slices/accounts.ts @@ -106,7 +106,7 @@ export const submitInitAccountTransaction = createAsyncThunk( establishedAddress, }; - if (url.match(/testnet/)) { + if (url.match(/testnet|localhost/)) { dispatch( submitTransferTransaction({ account: initializedAccount, diff --git a/packages/anoma-wallet/src/slices/transfers.ts b/packages/anoma-wallet/src/slices/transfers.ts index 423ab0a0d9..905d71d8f7 100644 --- a/packages/anoma-wallet/src/slices/transfers.ts +++ b/packages/anoma-wallet/src/slices/transfers.ts @@ -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 = { @@ -34,7 +31,7 @@ type TransferEvents = { }; export type TransfersState = { - transactions: TransferTransactions; + transactions: TransferTransaction[]; isTransferSubmitting: boolean; transferError?: string; events?: TransferEvents; @@ -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, @@ -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, }; @@ -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; @@ -185,10 +183,7 @@ const transfersSlice = createSlice({ } : undefined; - state.transactions = { - ...state.transactions, - [id]: transactions, - }; + state.transactions.push(transaction); } ); }, From 0e73388977ff6b8ede910a7fc1a44db094103003 Mon Sep 17 00:00:00 2001 From: "Justin R. Evans" Date: Wed, 11 May 2022 07:40:41 -0400 Subject: [PATCH 2/2] Clean up --- .../anoma-wallet/src/App/Token/Transfers/TransferDetails.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/anoma-wallet/src/App/Token/Transfers/TransferDetails.tsx b/packages/anoma-wallet/src/App/Token/Transfers/TransferDetails.tsx index 3db495d08c..80cf541ebe 100644 --- a/packages/anoma-wallet/src/App/Token/Transfers/TransferDetails.tsx +++ b/packages/anoma-wallet/src/App/Token/Transfers/TransferDetails.tsx @@ -45,7 +45,9 @@ const TransferDetail = (): JSX.Element => {

- {type} {amount} {tokenType} + {type} +
+ {amount} {tokenType}

{dateTimeFormatted}