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

Develop #37

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions components/Admin/Transfer/AddLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Props> = ({ onSelect }) => {
Expand All @@ -16,7 +16,7 @@ const AddLogMenu: React.FC<Props> = ({ onSelect }) => {
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};
const handleClose = (operation: SupportedOperations) => {
const handleClose = (operation?: SupportedOperations) => {
onSelect(operation);
setAnchorEl(null);
};
Expand All @@ -27,7 +27,7 @@ const AddLogMenu: React.FC<Props> = ({ onSelect }) => {
id="add-log-menu"
anchorEl={anchorEl}
open={open}
onClose={handleClose}
onClose={() => handleClose()}
MenuListProps={{
"aria-labelledby": "basic-button",
}}
Expand Down
2 changes: 1 addition & 1 deletion components/Bridge/WalletSwitchV2/UTXOConnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions components/Bridge/v3/Steps/ConnectValidate.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 (
<UTXOConnect
transfer={transfer}
Expand All @@ -39,7 +45,7 @@ const UTXOWrapped: React.FC<{ transfer: ITransfer }> = ({ transfer }) => {
setValue("utxoXpub", xpub);
}}
selectedAsset={utxoAssetType}
setSelectedAsset={(asset) => setValue("utxoAssetType", asset)}
setSelectedAsset={setSelectedAsset}
/>
);
};
Expand Down
40 changes: 7 additions & 33 deletions pages/api/transfer/index.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion utils/balance-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading