Ok, Iāve a stupid question I canāt find the answer to. I need to get the current userās wallet address(s?). Iām trying to simplify the transactions display by filtering out āhome baseā and adjusting the sign of the value according to if tokens coming or going. But my usrAddress keeps coming back undefined
regardless of how I try to spell or punctuate Moralis.User.Address
. Iām expecting some function like that to return to me an array of addresses, or even a chain array of arrays of addresses on each chain. But Iām getting nothing. Does this functionality exist somewhere? I canāt find it in the docs.
Hereās some nifty ReactJS hook code on the topic to make me look smarter while asking this really dumb question:
import { useEffect, useState } from "react";
import { useMoralis } from "react-moralis";
const emptyList = [];
export const useTransactions = (props) => {
const { isAuthenticated, Moralis } = useMoralis();
const [Txs, setTxs] = useState(emptyList);
const [isLoading, setIsLoading] = useState(true);
const usrAddress = Moralis.User.Address;
console.groupCollapsed("useTransactions");
console.log(
isAuthenticated ? usrAddress + " is authenticated." : "Unauthenticated."
);
useEffect(() => {
if (isAuthenticated) {
Moralis.Web3.getTransactions({ usePost: true }).then((userTrans) => {
let newTxs = userTrans.map((Tx) => {
const output = { ...Tx };
if (Tx.from_address === usrAddress) {
output.counterparty = Tx.to_address;
output.amount = -1 * parseFloat(Tx.value);
} else {
output.counterparty = Tx.from_address;
output.amount = parseFloat(Tx.value);
}
return output;
});
setTxs(newTxs);
setIsLoading(false);
});
} else {
setTxs(emptyList);
setIsLoading(true);
}
}, [Moralis.Web3, isAuthenticated, usrAddress]);
console.log(isLoading ? "Transactions loading..." : "Returning Txs: ", Txs);
console.groupEnd();
return { Txs, isLoading };
};
But all it ever gives me is āundefined is authenticatedā and a list of nothing but deposits that should be withdraws (and half the time Iām my own counterparty). I see my address in the output. But how do you tell React which one is mine?
Thoughts?