diff --git a/.github/workflows/aws.yml b/.github/workflows/aws.yml index 87cedf3..8c402a5 100644 --- a/.github/workflows/aws.yml +++ b/.github/workflows/aws.yml @@ -6,7 +6,7 @@ on: push: branches: - main - - admin-panel + - develop env: AWS_REGION: us-east-1 # set this to your preferred AWS region, e.g. us-west-1 diff --git a/components/Admin/Transfer/AddLog.tsx b/components/Admin/Transfer/AddLog.tsx index f01396d..8938e2f 100644 --- a/components/Admin/Transfer/AddLog.tsx +++ b/components/Admin/Transfer/AddLog.tsx @@ -7,7 +7,7 @@ export type SupportedOperations = AddLogRequestPayload["operation"]; type Props = { transfer: ITransfer; - onSelect: (item: SupportedOperations) => void; + onSelect: (item?: SupportedOperations) => void; }; const AddLogMenu: React.FC = ({ onSelect }) => { @@ -16,7 +16,7 @@ const AddLogMenu: React.FC = ({ onSelect }) => { const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; - const handleClose = (operation: SupportedOperations) => { + const handleClose = (operation?: SupportedOperations) => { onSelect(operation); setAnchorEl(null); }; @@ -27,7 +27,7 @@ const AddLogMenu: React.FC = ({ onSelect }) => { id="add-log-menu" anchorEl={anchorEl} open={open} - onClose={handleClose} + onClose={() => handleClose()} MenuListProps={{ "aria-labelledby": "basic-button", }} diff --git a/components/Bridge/WalletSwitchV2/UTXOConnect.tsx b/components/Bridge/WalletSwitchV2/UTXOConnect.tsx index 9db07b3..827fc66 100644 --- a/components/Bridge/WalletSwitchV2/UTXOConnect.tsx +++ b/components/Bridge/WalletSwitchV2/UTXOConnect.tsx @@ -15,7 +15,7 @@ import { MIN_AMOUNT } from "@constants"; import { SYSX_ASSET_GUID } from "@contexts/Transfer/constants"; import { useEffect } from "react"; -type AssetType = "sys" | "sysx" | "none"; +export type AssetType = "sys" | "sysx" | "none"; type UTXOConnectProps = { transfer: ITransfer; diff --git a/components/Bridge/v3/Steps/ConnectValidate.tsx b/components/Bridge/v3/Steps/ConnectValidate.tsx index 4518073..ec3a4a8 100644 --- a/components/Bridge/v3/Steps/ConnectValidate.tsx +++ b/components/Bridge/v3/Steps/ConnectValidate.tsx @@ -1,5 +1,5 @@ import NEVMConnect from "components/Bridge/WalletSwitchV2/NEVMConnect"; -import UTXOConnect from "components/Bridge/WalletSwitchV2/UTXOConnect"; +import UTXOConnect, { AssetType } from "components/Bridge/WalletSwitchV2/UTXOConnect"; import { useRouter } from "next/router"; import { FormProvider, @@ -25,12 +25,18 @@ import BridgeV3Loading from "../Loading"; import { ConnectValidateAgreeToTermsCheckbox } from "./ConnectValidate/AgreeToTermsCheckbox"; import { ConnectValidateAmountField } from "./ConnectValidate/AmountField"; import { ConnectValidateStartTransferButton } from "./ConnectValidate/StartTransferButton"; +import { useCallback } from "react"; const UTXOWrapped: React.FC<{ transfer: ITransfer }> = ({ transfer }) => { const { setValue, watch } = useFormContext(); const utxoAssetType = watch("utxoAssetType"); + const setSelectedAsset = useCallback( + (asset: AssetType) => setValue("utxoAssetType", asset), + [setValue] + ); + return ( = ({ transfer }) => { setValue("utxoXpub", xpub); }} selectedAsset={utxoAssetType} - setSelectedAsset={(asset) => setValue("utxoAssetType", asset)} + setSelectedAsset={setSelectedAsset} /> ); }; diff --git a/pages/api/transfer/index.ts b/pages/api/transfer/index.ts index 01d48ff..94a94c4 100644 --- a/pages/api/transfer/index.ts +++ b/pages/api/transfer/index.ts @@ -1,31 +1,14 @@ import { NextApiHandler } from "next"; -import firebase from "firebase-setup"; -import { - QueryConstraint, - collection, - getDocs, - orderBy, - query, - where, - or, - QueryFilterConstraint, -} from "firebase/firestore"; -import { signInWithEmailAndPassword } from "firebase/auth"; +import { where, QueryFilterConstraint } from "firebase/firestore"; import { TransferService } from "api/services/transfer"; import dbConnect from "lib/mongodb"; +import { ITransfer } from "@contexts/Transfer/types"; const transferService = new TransferService(); const getAll: NextApiHandler = async (req, res) => { const { nevm, utxo, version } = req.query; - if (process.env.NODE_ENV !== "development" && firebase.auth) { - await signInWithEmailAndPassword( - firebase.auth, - process.env.FIREBASE_AUTH_EMAIL!, - process.env.FIREBASE_AUTH_PASSWORD! - ); - } const queryConstraints: QueryFilterConstraint[] = []; if (nevm) { @@ -41,25 +24,16 @@ const getAll: NextApiHandler = async (req, res) => { return res.status(400).json({ message: "Some parameters are missing" }); } - const transferQuery = query( - collection(firebase.firestore, "transfers"), - or(...queryConstraints), - orderBy("createdAt", "desc") - ); - - const { docs } = await getDocs(transferQuery); - let transfers = docs.map((doc) => doc.data()); await dbConnect(); - let dbTransfer = await transferService.getAll({ + + const dbTransfer = await transferService.getAll({ nevmAddress: nevm as string, utxoAddress: utxo as string, utxoXpub: utxo as string, + version: version as ITransfer["version"], }); - transfers = [...transfers, ...dbTransfer]; - if (version) { - transfers = transfers.filter((transfer) => transfer.version === version); - } - return res.status(200).json(Object.values(transfers)); + + return res.status(200).json(Object.values(dbTransfer)); }; const handler: NextApiHandler = (req, res) => { diff --git a/utils/balance-hooks.ts b/utils/balance-hooks.ts index 00fb3c9..650900b 100644 --- a/utils/balance-hooks.ts +++ b/utils/balance-hooks.ts @@ -36,7 +36,7 @@ export const useUtxoBalance = ( const balanceInText = await fetch(url) .then((res) => res.json()) .then((res: BalanceResp) => { - if (assetGuid && address) { + if (assetGuid && address && res.tokensAsset) { const total = res.tokensAsset.reduce((acc, asset) => { if (asset.assetGuid === assetGuid) { return acc + parseInt(asset.balance);