Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui-ux): call endpoint to save tx #4157

Merged
merged 11 commits into from
Feb 2, 2024
38 changes: 37 additions & 1 deletion mobile-app/app/components/OceanInterface/OceanInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { CTransactionSegWit } from "@defichain/jellyfish-transaction/dist";
import { WhaleApiClient } from "@defichain/whale-api-client";
import { Transaction } from "@defichain/whale-api-client/dist/api/transactions";
import { getEnvironment } from "@waveshq/walletkit-core";
import { EnvironmentNetwork, getEnvironment } from "@waveshq/walletkit-core";
import { RootState } from "@store";
import {
firstTransactionSelector,
Expand All @@ -29,6 +29,7 @@ import {
} from "@shared-contexts/NativeLoggingProvider";
import { getReleaseChannel } from "@api/releaseChannel";
import { useAppDispatch } from "@hooks/useAppDispatch";
import { useFeatureFlagContext } from "@contexts/FeatureFlagContext";
import { TransactionDetail } from "./TransactionDetail";
import { TransactionError } from "./TransactionError";

Expand Down Expand Up @@ -119,6 +120,8 @@ export function OceanInterface(): JSX.Element | null {
const { wallet, address } = useWalletContext();
const { getTransactionUrl } = useDeFiScanContext();
const { network } = useNetworkContext();
const { isFeatureAvailable } = useFeatureFlagContext();
const isSaveTxEnabled = isFeatureAvailable("save_tx");

// store
const { height, err: e } = useSelector((state: RootState) => state.ocean);
Expand All @@ -128,6 +131,7 @@ export function OceanInterface(): JSX.Element | null {
const slideAnim = useRef(new Animated.Value(0)).current;
// state
const [tx, setTx] = useState<OceanTransaction | undefined>(transaction);
const [calledTx, setCalledTx] = useState<string | undefined>();
const [err, setError] = useState<string | undefined>(e?.message);
const [txUrl, setTxUrl] = useState<string | undefined>();
// evm tx state
Expand All @@ -149,6 +153,38 @@ export function OceanInterface(): JSX.Element | null {
return vmmap.output;
};

useEffect(() => {
const saveTx = async (txId: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will save all tx for all network including testnet and playground

  1. Add checking that user is in mainnet
  2. Add feature flagging. To be able to disable this via feature flags in case something is wrong with the api

try {
await fetch(
`https://3paxhqj3np.ap-southeast-1.awsapprunner.com/transaction/${txId}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
transaction: txId,
}),
},
);
// store called transaction
setCalledTx(txId);
} catch (e) {
/* empty - don't do anything even if saveTx is not called */
}
};
if (
tx?.broadcasted && // only call tx when tx is done
calledTx !== tx?.tx.txId && // to ensure that api is only called once per tx
tx?.tx.txId !== undefined &&
network === EnvironmentNetwork.MainNet &&
isSaveTxEnabled // feature flag
) {
saveTx(tx.tx.txId);
}
}, [tx?.tx.txId, calledTx, tx?.broadcasted, network, isSaveTxEnabled]);

useEffect(() => {
// get evm tx id and url (if any)
const fetchEvmTx = async (txId: string) => {
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"@reduxjs/toolkit": "^1.9.7",
"@shopify/flash-list": "1.4.3",
"@waveshq/standard-defichain-jellyfishsdk": "^2.20.0",
"@waveshq/walletkit-core": "^1.3.9",
"@waveshq/walletkit-ui": "^1.3.9",
"@waveshq/walletkit-core": "^1.3.10",
"@waveshq/walletkit-ui": "^1.3.10",
"bignumber.js": "^9.1.2",
"buffer": "^6.0.3",
"classnames": "^2.3.2",
Expand Down
Loading