Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Feb 14, 2024
1 parent 04361e4 commit 9b7fffc
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 69 deletions.
39 changes: 20 additions & 19 deletions trade.renegade.fi/app/(desktop)/[base]/[quote]/deposit-button.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import { ArrowForwardIcon } from "@chakra-ui/icons"
import { Button, useDisclosure } from "@chakra-ui/react"
import { Token } from "@renegade-fi/renegade-js"
import { toast } from "sonner"
import { useAccount, useWaitForTransaction } from "wagmi"

import { renegade } from "@/app/providers"
import { CreateStepper } from "@/components/steppers/create-stepper/create-stepper"
import { useDeposit } from "@/contexts/Deposit/deposit-context"
import { useRenegade } from "@/contexts/Renegade/renegade-context"
import { env } from "@/env.mjs"
Expand All @@ -14,8 +6,16 @@ import {
useErc20Approve,
usePrepareErc20Approve,
} from "@/generated"
import { ArrowForwardIcon } from "@chakra-ui/icons"
import { Button, useDisclosure } from "@chakra-ui/react"
import { Token } from "@renegade-fi/renegade-js"
import { toast } from "sonner"
import { useAccount, useWaitForTransaction } from "wagmi"

import { useButton } from "@/hooks/use-button"
import { useIsLocked } from "@/hooks/use-is-locked"
import { CreateStepper } from "@/components/steppers/create-stepper/create-stepper"
import { renegade } from "@/app/providers"

const MAX_INT = BigInt(
"115792089237316195423570985008687907853269984665640564039457584007913129639935"
Expand Down Expand Up @@ -74,12 +74,13 @@ export default function DepositButton() {
handleApprove()
} else {
if (!accountId || !address) return
await renegade.task.deposit(
accountId,
new Token({ address: Token.findAddressByTicker(baseTicker) }),
BigInt(baseTokenAmount),
address
)
await renegade.task
.deposit(
accountId,
new Token({ address: Token.findAddressByTicker(baseTicker) }),
BigInt(baseTokenAmount),
address
)
.then(() => toast.info("Deposit task added to queue"))
.catch((error) => toast.error(`Error depositing: ${error}`))
}
Expand All @@ -100,9 +101,9 @@ export default function DepositButton() {
isDisabled
? { backgroundColor: "transparent" }
: {
borderColor: "white.60",
color: "white",
}
borderColor: "white.60",
color: "white",
}
}
transform={baseTokenAmount ? "translateY(10px)" : "translateY(-10px)"}
visibility={baseTokenAmount ? "visible" : "hidden"}
Expand All @@ -118,8 +119,8 @@ export default function DepositButton() {
{shouldUse
? buttonText
: needsApproval
? `Approve ${baseTicker}`
: `Deposit ${baseTokenAmount || ""} ${baseTicker}`}
? `Approve ${baseTicker}`
: `Deposit ${baseTokenAmount || ""} ${baseTicker}`}
</Button>
{signInIsOpen && <CreateStepper onClose={onCloseSignIn} />}
</>
Expand Down
24 changes: 13 additions & 11 deletions trade.renegade.fi/components/panels/orders-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,32 +290,34 @@ function OrderBookPanel() {
`0x${orders[counterpartyOrder.id]?.quoteToken.address}`
)
const title = orders[counterpartyOrder.id]
? `${orders[counterpartyOrder.id].side === "buy" ? "Buy" : "Sell"
} ${orders[counterpartyOrder.id].amount} ${baseTicker} ${orders[counterpartyOrder.id].side === "buy" ? "with" : "for"
} ${quoteTicker}`
? `${
orders[counterpartyOrder.id].side === "buy" ? "Buy" : "Sell"
} ${orders[counterpartyOrder.id].amount} ${baseTicker} ${
orders[counterpartyOrder.id].side === "buy" ? "with" : "for"
} ${quoteTicker}`
: `Unknown order hash: ${counterpartyOrder.id
.split("-")[0]
.toString()}`
.split("-")[0]
.toString()}`

const status =
counterpartyOrder.id in orders
? "ACTIVE"
: counterpartyOrder.state === "Cancelled" &&
!(counterpartyOrder.id in orders) &&
savedOrders.some(({ id }) => id === counterpartyOrder.id)
? "MATCHED"
: counterpartyOrder.state === "Cancelled"
? "VERIFIED"
: counterpartyOrder.state.toUpperCase()
? "MATCHED"
: counterpartyOrder.state === "Cancelled"
? "VERIFIED"
: counterpartyOrder.state.toUpperCase()

const ago = dayjs.unix(counterpartyOrder.timestamp).fromNow()

const textColor =
status === "ACTIVE" || status === "MATCHED"
? "green"
: status === "CANCELLED"
? "red"
: "white.60"
? "red"
: "white.60"

return (
<Flex
Expand Down
46 changes: 21 additions & 25 deletions trade.renegade.fi/components/panels/wallets-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { Panel, expandedPanelWidth } from "@/components/panels/panels"
import { ConnectWalletButton, SignInButton } from "@/app/(desktop)/main-nav"

import "simplebar-react/dist/simplebar.min.css"
import { renegade } from "@/app/providers"
import { useTasks } from "@/hooks/use-tasks"
import { renegade } from "@/app/providers"

interface TokenBalanceProps {
tokenAddr: string
Expand Down Expand Up @@ -174,16 +174,19 @@ function RenegadeWalletPanel(props: RenegadeWalletPanelProps) {
const { accountId } = useRenegade()

const formattedBalances = useMemo<Array<[string, bigint]>>(() => {
const nonzero: Array<[string, bigint]> = Object.entries(balances).map(([_, b]) => [b.mint.address, b.amount])
const placeholders: Array<[string, bigint]> = tokenMappings.tokens.filter((t) => !nonzero.some(([a]) => a === t.address)).map((t) => [t.address.replace("0x", ""), BigInt(0)])
const nonzero: Array<[string, bigint]> = Object.entries(balances).map(
([_, b]) => [b.mint.address, b.amount]
)
const placeholders: Array<[string, bigint]> = tokenMappings.tokens
.filter((t) => !nonzero.some(([a]) => a === t.address))
.map((t) => [t.address.replace("0x", ""), BigInt(0)])
return [...nonzero, ...placeholders]
}, [balances])

const showDeposit = useMemo(() => {
return !Object.values(balances).some((b) => b.amount > BigInt(0))
}, [balances])


const Content = useMemo(() => {
if (accountId && !showDeposit) {
return (
Expand Down Expand Up @@ -238,20 +241,13 @@ function RenegadeWalletPanel(props: RenegadeWalletPanelProps) {
{accountId
? "Deposit tokens into your Renegade Account to get started."
: address
? "Sign in to create a Renegade account and view your balances."
: "Connect your Ethereum wallet before signing in."}
? "Sign in to create a Renegade account and view your balances."
: "Connect your Ethereum wallet before signing in."}
</Text>
</Flex>
)
}
}, [
accountId,
address,
isSigningIn,
formattedBalances,
setView,
showDeposit,
])
}, [accountId, address, isSigningIn, formattedBalances, setView, showDeposit])

return (
<>
Expand Down Expand Up @@ -314,21 +310,25 @@ function HistorySection() {
>
{tasks.map((task) => {
const textColor =
task.status?.state === "Completed"
? "green" : "white"
task.status?.state === "Completed" ? "green" : "white"

const rightIcon = task.status?.state === "Completed" ? <CheckIcon height='4' /> : <Spinner size='xs' />
const rightIcon =
task.status?.state === "Completed" ? (
<CheckIcon height="4" />
) : (
<Spinner size="xs" />
)
return (
<Flex
key={task.id}
alignItems='center'
alignItems="center"
flexDirection="row"
width="100%"
padding="4%"
borderBottom="var(--secondary-border)"
>
<Flex flexDirection="column">
<Flex alignItems="center" gap='2'>
<Flex alignItems="center" gap="2">
<Text
color={textColor}
fontFamily="Favorit Extended"
Expand All @@ -345,15 +345,11 @@ function HistorySection() {
a few seconds ago
</Text>
</Flex>
<Flex alignItems='center' gap='2'>
<Flex alignItems="center" gap="2">
<Text color="white.80" fontSize="0.8em">
{task.status?.state}
</Text>
{task.status?.state !== "Completed" && (
<>
{rightIcon}
</>
)}
{task.status?.state !== "Completed" && <>{rightIcon}</>}
</Flex>
</Flex>
</Flex>
Expand Down
3 changes: 1 addition & 2 deletions trade.renegade.fi/hooks/use-global-orders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { OrderId } from "@renegade-fi/renegade-js"
import { useEffect, useState } from "react"

import { OrderId } from "@renegade-fi/renegade-js"

export const useGlobalOrders = () => {
const [orders, setOrders] = useState<Record<string, GlobalOrder>>({})
Expand Down
2 changes: 1 addition & 1 deletion trade.renegade.fi/hooks/use-order.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react"
import { useRenegade } from "@/contexts/Renegade/renegade-context"
import { Order, OrderId } from "@renegade-fi/renegade-js"
import { useEffect, useState } from "react"

import { safeLocalStorageGetItem, safeLocalStorageSetItem } from "@/lib/utils"

Expand Down
25 changes: 14 additions & 11 deletions trade.renegade.fi/hooks/use-tasks.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import { useRenegade } from "@/contexts/Renegade/renegade-context"
import { useEffect, useState } from "react"
import { useRenegade } from "@/contexts/Renegade/renegade-context"

import { renegade } from "@/app/providers"

export const useTasks = () => {
const [tasks, setTasks] = useState<{
id?: string | undefined;
status?: {
task_type?: string | undefined;
state?: string | undefined;
} | undefined;
committed?: boolean | undefined;
}[]>([])
const [tasks, setTasks] = useState<
{
id?: string | undefined
status?:
| {
task_type?: string | undefined
state?: string | undefined
}
| undefined
committed?: boolean | undefined
}[]
>([])
const { accountId } = useRenegade()

useEffect(() => {
if (!accountId) return
const interval = setInterval(async () => {
const _tasks = await renegade
.queryTaskQueue(accountId)
const _tasks = await renegade.queryTaskQueue(accountId)
setTasks(_tasks)
}, 5000)

Expand Down

0 comments on commit 9b7fffc

Please sign in to comment.