Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…etplace into add-react-tweet
  • Loading branch information
muditmahajan committed Apr 4, 2024
2 parents b8b1ca0 + c9511fe commit 6dc98a7
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 117 deletions.
40 changes: 28 additions & 12 deletions src/api/marketplace/orders/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,29 @@ def cancel_escrow(order_id: str, status: str):
on_chain_transaction.save()

# After the above task is finished successfully, update the order status to cancelled
order.status = status
order.save()

create_order_tracking(order=order, status=status)
create_notification_for_order(order=order, old_status='accepted', new_status=status)
if on_chain_transaction.is_confirmed:

escrow.status = "cancelled"
escrow.save()
order.status = status
order.save()

return True
create_order_tracking(order=order, status=status)
create_notification_for_order(
order=order, old_status='accepted', new_status=status)

escrow.status = "cancelled"
escrow.save()

return True
else:
return False

except Exception as e:
logger.error('Error in cancelling escrow: %s', str(e))
return False


@celery_app.task(base=QueueOnce, once={'graceful': True})
@celery_app.task(base=QueueOnce, once={'graceful': True}, autoretry_for=(Exception,), retry_kwargs={'max_retries': 3})
def confirm_escrow(order_id: str):
try:
# Get order and corresponding escrow
Expand Down Expand Up @@ -169,11 +175,21 @@ def confirm_escrow(order_id: str):

on_chain_transaction.save()

order.status = 'completed'
order.save()
if on_chain_transaction.is_confirmed:
order.status = 'completed'
order.save()

escrow.status = "delivered"
escrow.save()
create_order_tracking(order=order, status=order.status)
create_notification_for_order(
order=order, old_status='accepted', new_status='completed')

escrow.status = "delivered"
escrow.save()

return True

else:
return False

except Exception as e:
raise Exception('Error in confirming escrow', str(e))
Expand Down
34 changes: 24 additions & 10 deletions src/api/marketplace/orders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def put(self, request, pk):
status=status.HTTP_400_BAD_REQUEST,
)
else:
if not on_chain_transaction.err:
if not on_chain_transaction.err and on_chain_transaction.created_at > timezone.now() - timezone.timedelta(minutes=5):
action = "cancellation" if request.user_account.id == order.buyer.id else "rejection"
return Response(
{
Expand All @@ -752,15 +752,29 @@ def put(self, request, pk):
status=status.HTTP_400_BAD_REQUEST,
)
else:
return Response(
{
"isSuccess": False,
"message": "Order cancellation failed",
"data": None,
"errors": "Order cancellation failed",
},
status=status.HTTP_400_BAD_REQUEST,
)
# Retry the transaction
res = cancel_escrow(pk, order_status)
if res:
# Cancel all order items
order_items.update(status=order_status)
return Response(
{
"isSuccess": True,
"data": None,
"message": "Order cancelled successfully",
},
status=status.HTTP_200_OK,
)
else:
return Response(
{
"isSuccess": False,
"message": "Order cancellation failed",
"data": None,
"errors": "Order cancellation failed",
},
status=status.HTTP_400_BAD_REQUEST,
)
# Create an on chain transaction
else:
self.create_on_chain_transaction(order)
Expand Down
13 changes: 12 additions & 1 deletion src/ui/app/business/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import CancelIcon from "@mui/icons-material/Cancel";
import RuleOutlinedIcon from "@mui/icons-material/RuleOutlined";
import ManualVerifyModal from "@/src/components/dashboardComponents/manualVerifyModal";
import WalletConnectModal from "@/src/components/web3Components/walletConnectModal";

const tabs = [
{
Expand All @@ -82,6 +83,7 @@ const tabs = [
];
export default function BusinessDashboardPage() {
const router = useRouter();
const [connectWallet, setConnectWallet] = useState(false);
const searchParams = useSearchParams();
const [selectedOrder, setSelectedOrder] = useState<OrderType | null>(null);
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -858,7 +860,11 @@ export default function BusinessDashboardPage() {
transaction.transaction_type ===
TRANSACTION_TYPE.CANCEL_ESCROW
)?.length === 0 && (
<CancelEscrow order={params?.row} updateStatus={getOrders} />
<CancelEscrow
order={params?.row}
updateStatus={getOrders}
setConnectWallet={setConnectWallet}
/>
)}
{(params?.row?.status === ORDER_STATUS.ACCEPTED ||
params?.row?.status === ORDER_STATUS.PENDING) &&
Expand Down Expand Up @@ -1530,6 +1536,11 @@ export default function BusinessDashboardPage() {
/>
) : null}
</Box>
<WalletConnectModal
open={connectWallet}
setOpen={setConnectWallet}
connect={true}
/>
</RouteProtection>
);
}
33 changes: 3 additions & 30 deletions src/ui/app/components/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ import NextLink from "next/link";
import SavedProfileIcon from "@/public/svg/Saved.svg";
import SavedProfileDisabledIcon from "@/public/svg/Saved_disabled.svg";

type NavbarProps = {
setCategoryOpen: React.Dispatch<React.SetStateAction<boolean>>;
categoryOpen: boolean;
};

const MENU_ITEMS: {
[key: string]: {
label: string;
Expand Down Expand Up @@ -71,7 +66,7 @@ const MENU_ITEMS: {
},
Dashboard: {
label: "Dashboard",
route: "/dashboard?tab=orders",
route: "/dashboard",
icon: DashboardIcon,
disabledIcon: DashboardDisabledIcon,
},
Expand Down Expand Up @@ -228,13 +223,8 @@ const MenuItemsComponent = ({ items }: { items: string[] }) => {
) : null;
};

export default function Navbar({ setCategoryOpen, categoryOpen }: NavbarProps) {
const {
isTwitterUserLoggedIn,
logoutTwitterUser,
isAccountSetupComplete,
checkAccountSetup,
} = useTwitterAuth();
export default function Navbar() {
const { isTwitterUserLoggedIn, logoutTwitterUser } = useTwitterAuth();

const router = useRouter();
const pathname = usePathname();
Expand All @@ -260,23 +250,6 @@ export default function Navbar({ setCategoryOpen, categoryOpen }: NavbarProps) {
}
}, [isTwitterUserLoggedIn]);

useEffect(() => {
const status = params.get("authenticationStatus");
if (
isTwitterUserLoggedIn &&
!isAccountSetupComplete &&
status === "success"
) {
setCategoryOpen(true);
}
}, [isTwitterUserLoggedIn, isAccountSetupComplete]);

useEffect(() => {
if (!categoryOpen) {
checkAccountSetup();
}
}, [categoryOpen]);

const handleConnect = () => {
const roleQueryParams = pathname.includes("business")
? "Business"
Expand Down
17 changes: 14 additions & 3 deletions src/ui/app/influencer/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import MessageIcon from "@mui/icons-material/Message";
import Joyride, { ACTIONS, EVENTS, STATUS } from "react-joyride";
import XfluencerLogo from "@/public/svg/Xfluencer_Logo_Beta.svg";
import { DriveEta } from "@mui/icons-material";
import WalletConnectModal from "@/src/components/web3Components/walletConnectModal";

const tabs = [
{
Expand Down Expand Up @@ -90,6 +91,7 @@ const getProfileCompletedStatus: (businessDetails: any) => string = (
export default function BusinessDashboardPage() {
const router = useRouter();
const searchParams = useSearchParams();
const [connectWallet, setConnectWallet] = useState(false);
const [selectedOrder, setSelectedOrder] = useState<OrderType | null>(null);
const [loading, setLoading] = useState(false);
const [orders, setOrders] = useState<OrderType[]>([]);
Expand Down Expand Up @@ -178,8 +180,8 @@ export default function BusinessDashboardPage() {
Customized filters.
</Typography>
<Typography sx={{ mt: 1 }}>
Advanced filters for orders based on the services, date, order ID, and
businesses.
Advanced filters for orders based on the services, date, order ID,
and businesses.
</Typography>
</Box>
),
Expand Down Expand Up @@ -853,7 +855,11 @@ export default function BusinessDashboardPage() {
(transaction: TransactionType) =>
transaction.transaction_type === TRANSACTION_TYPE.CLAIM_ESCROW
)?.length === 0 && (
<ClaimEscrow order={params?.row} updateStatus={getOrders} />
<ClaimEscrow
order={params?.row}
updateStatus={getOrders}
setConnectWallet={setConnectWallet}
/>
)}
</Box>
);
Expand Down Expand Up @@ -1452,6 +1458,11 @@ export default function BusinessDashboardPage() {
/>
) : null}
</Box>
<WalletConnectModal
open={connectWallet}
setOpen={setConnectWallet}
connect={true}
/>
</RouteProtection>
);
}
4 changes: 2 additions & 2 deletions src/ui/app/influencer/profile/[id]/_services/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Services = ({
total_data_count: 0,
total_page_count: 0,
current_page_number: 1,
current_page_size: 10,
current_page_size: 9,
});
const [loading, setLoading] = React.useState<boolean>(true);
const [openModal, setOpenModal] = React.useState<boolean>(false);
Expand All @@ -65,7 +65,7 @@ const Services = ({
page_size:
id === loggedInUser?.id
? pagination.current_page_size
: pagination.current_page_size,
: pagination.current_page_size + 1,
influencer: id,
status: id === loggedInUser?.id ? type : "published",
}
Expand Down
23 changes: 2 additions & 21 deletions src/ui/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
"use client";

import CategorySelectionModal from "@/src/components/categorySelectionModal";
import EmailLoginModal from "@/src/components/emailLoginModal";
import WalletContextProvider from "@/src/components/shared/walletContextProvider";
import WalletConnectModal from "@/src/components/web3Components/walletConnectModal";
import { AppStore, makeStore } from "@/src/store";
import { Inter } from "next/font/google";
import { SnackbarProvider } from "notistack";
import { useRef, useState } from "react";
import { useRef } from "react";
import { Provider } from "react-redux";
import { persistStore } from "redux-persist";
import { PersistGate } from "redux-persist/integration/react";
Expand All @@ -29,10 +26,6 @@ export default function RootLayout({
}
const persistor = persistStore(storeRef.current);

const [emailOpen, setEmailOpen] = useState<boolean>(false);
const [categoryOpen, setCategoryOpen] = useState<boolean>(false);
const [walletOpen, setWalletOpen] = useState<boolean>(false);

return (
<html lang="en">
<head>
Expand All @@ -52,20 +45,8 @@ export default function RootLayout({
<PersistGate loading={null} persistor={persistor}>
<ThemeRegistry options={{ key: "mui-theme" }}>
<WalletContextProvider>
<Navbar
setCategoryOpen={setCategoryOpen}
categoryOpen={categoryOpen}
/>
<Navbar />
{children}
<EmailLoginModal open={emailOpen} setOpen={setEmailOpen} />
<CategorySelectionModal
open={categoryOpen}
setOpen={setCategoryOpen}
/>
<WalletConnectModal
open={walletOpen}
setOpen={setWalletOpen}
/>
</WalletContextProvider>
</ThemeRegistry>
</PersistGate>
Expand Down
6 changes: 5 additions & 1 deletion src/ui/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ export default function Home({}: Props) {
router.push(url);
}, []);

return null;
return (
<Backdrop open={true}>
<CircularProgress color="secondary" />
</Backdrop>
);
}
6 changes: 5 additions & 1 deletion src/ui/src/components/walletsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Image from "next/image";
import { useEffect, useState } from "react";
import { ConfirmDelete } from "../shared/confirmDeleteModal";
import { notification } from "../shared/notification";
import { LOGIN_METHODS } from "@/src/utils/consts";

type Props = {
walletOpen: boolean;
Expand Down Expand Up @@ -114,7 +115,10 @@ export default function WalletsTable({ walletOpen }: Props) {

const disConnectWallet = async () => {
try {
if (connectedWallet?.wallet_address_id === user?.user?.username) {
if (
connectedWallet?.wallet_address_id === user?.user?.username &&
user?.user?.login_method === LOGIN_METHODS.WALLET
) {
await logoutTwitterUser();
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/ui/src/components/web3Components/cancelEscrow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ import { notification } from "../../shared/notification";
type CancelEscrowProps = {
order: OrderType;
updateStatus: () => void;
setConnectWallet: (value: boolean) => void;
};

const programId = new PublicKey(idl.metadata.address);

export default function CancelEscrow({
updateStatus,
order,
setConnectWallet,
}: CancelEscrowProps) {
const [localLoading, setLocalLoading] = useState(false);
const connection = new Connection(`https://api.devnet.solana.com`, {
Expand Down Expand Up @@ -86,12 +88,14 @@ export default function CancelEscrow({
// Check if wallet is connected
if (!connection || !publicKey) {
notification("Please connect your wallet first", "error");
setConnectWallet(true);
return;
}

// Check that the correct wallet is connected
if (publicKey?.toBase58() !== order?.buyer_wallet?.wallet_address_id) {
notification("Please connect the correct wallet", "error");
setConnectWallet(true);
return;
}

Expand Down
Loading

0 comments on commit 6dc98a7

Please sign in to comment.