Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Mar 1, 2024
1 parent d0cc6b3 commit ea51ce2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default function DepositButton() {
address: Token.findAddressByTicker(baseTicker) as `0x${string}`,
args: [address ?? "0x"],
})
// TODO: Adjust decimals
console.log("Balance on L1: ", formatUnits(l1Balance ?? BigInt(0), 18))

// Get L1 ERC20 Allowance
Expand Down
2 changes: 1 addition & 1 deletion trade.renegade.fi/components/panels/wallets-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function TokenBalance(props: TokenBalanceProps) {

const formattedAmount = formatAmount(props.amount, new Token({ address: props.tokenAddr }))
const ticker = Token.findTickerByAddress(`${props.tokenAddr}`)
const usdPrice = useUSDPrice(ticker, Number(props.amount))
const usdPrice = useUSDPrice(ticker, parseFloat(formatAmount(props.amount, new Token({ address: props.tokenAddr }))))

const isZero = props.amount === BigInt(0)

Expand Down
32 changes: 12 additions & 20 deletions trade.renegade.fi/components/place-order-button.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
"use client"

import { useMemo } from "react"
import { useExchange } from "@/contexts/Exchange/exchange-context"
import { useOrder } from "@/contexts/Order/order-context"
import { Direction } from "@/contexts/Order/types"
import { useRenegade } from "@/contexts/Renegade/renegade-context"
import { ArrowForwardIcon } from "@chakra-ui/icons"
import { Button, useDisclosure } from "@chakra-ui/react"
import { Exchange, Order, OrderId } from "@renegade-fi/renegade-js"
import { useMemo } from "react"
import { toast } from "sonner"
import { v4 as uuidv4 } from "uuid"
import { useAccount as useAccountWagmi } from "wagmi"

import { findBalanceByTicker, parseAmount, safeLocalStorageGetItem, safeLocalStorageSetItem } from "@/lib/utils"
import { useBalance } from "@/hooks/use-balance"
import { useButton } from "@/hooks/use-button"
import { renegade } from "@/app/providers"
import { CreateStepper } from "@/components/steppers/create-stepper/create-stepper"
import { OrderStepper } from "@/components/steppers/order-stepper/order-stepper"
import { renegade } from "@/app/providers"
import { LocalOrder } from "@/components/steppers/order-stepper/steps/confirm-step"
import { parseUnits } from "viem"
import { useBalance } from "@/hooks/use-balance"
import { useButton } from "@/hooks/use-button"
import { findBalanceByTicker, formatAmount, parseAmount, safeLocalStorageGetItem, safeLocalStorageSetItem } from "@/lib/utils"

export function PlaceOrderButton() {
const { address } = useAccountWagmi()
Expand Down Expand Up @@ -96,22 +95,15 @@ export function PlaceOrderButton() {
}

const hasInsufficientBalance = useMemo(() => {
const baseBalance = findBalanceByTicker(balances, baseTicker)
const quoteBalance = findBalanceByTicker(balances, quoteTicker)
const baseBalance = findBalanceByTicker(balances, baseTicker).amount
const quoteBalance = findBalanceByTicker(balances, quoteTicker).amount
const price = priceReport?.midpointPrice ? priceReport.midpointPrice * parseFloat(baseTokenAmount) : 0
if (direction === Direction.SELL) {
// TODO: Check this
return baseBalance.amount < parseFloat(baseTokenAmount)
return baseBalance < parseAmount(baseTokenAmount, base)
}
if (!priceReport?.midpointPrice) return false
return quoteBalance.amount < priceReport?.midpointPrice
}, [
balances,
baseTicker,
baseTokenAmount,
direction,
priceReport?.midpointPrice,
quoteTicker,
])
// TODO: Check this
return parseFloat(formatAmount(quoteBalance, quote)) < price
}, [balances, base, baseTicker, baseTokenAmount, direction, priceReport?.midpointPrice, quote, quoteTicker])

const isSignedIn = accountId !== undefined
let placeOrderButtonContent: string
Expand Down
2 changes: 1 addition & 1 deletion trade.renegade.fi/contexts/Deposit/deposit-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function DepositProvider({ children }: PropsWithChildren) {

const handleSetBaseTokenAmount = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
if (!isNaN(parseFloat(value)) && isFinite(parseFloat(value)) && (value === '' || parseFloat(value) >= 0)) {
if (value === '' || (!isNaN(parseFloat(value)) && isFinite(parseFloat(value)) && parseFloat(value) >= 0)) {
setBaseTokenAmount(value);
}
};
Expand Down
4 changes: 3 additions & 1 deletion trade.renegade.fi/contexts/Order/order-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ function OrderProvider({ children }: PropsWithChildren) {

const handleSetBaseTokenAmount = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;
if (!isNaN(parseFloat(value)) && isFinite(parseFloat(value)) && (value === '' || parseFloat(value) >= 0)) {
// Check if the input is either an empty string or a valid positive number (including decimals)
if (value === '' || (!isNaN(parseFloat(value)) && isFinite(parseFloat(value)) && parseFloat(value) >= 0)) {
setBaseTokenAmount(value);
}
};


return (
<OrderStateContext.Provider
value={{
Expand Down
2 changes: 1 addition & 1 deletion trade.renegade.fi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@chakra-ui/react": "^2.8.0",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@renegade-fi/renegade-js": "^0.4.17",
"@renegade-fi/renegade-js": "^0.4.18",
"@t3-oss/env-nextjs": "^0.6.0",
"connectkit": "^1.4.0",
"dayjs": "^1.11.10",
Expand Down
8 changes: 4 additions & 4 deletions trade.renegade.fi/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1721,10 +1721,10 @@
resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f"
integrity sha512-P1st0aksCrn9sGZhp8GMYwBnQsbvAWsZAX44oXNNvLHGqAOcoVxmjZiohstwQ7SqKnbR47akdNi+uleWD8+g6A==

"@renegade-fi/renegade-js@^0.4.17":
version "0.4.17"
resolved "https://registry.yarnpkg.com/@renegade-fi/renegade-js/-/renegade-js-0.4.17.tgz#9f1fba9ec6993dcc5d26253ddd162c72f5f8defa"
integrity sha512-2Vwn8NW4WO8eEX8wrz1XtGRVe2ftDJBgxbeBqm7ZcsbqdsfjgyxnEaICCgsY1jzkvf09tqQcCoy5jv5XfeQ4oQ==
"@renegade-fi/renegade-js@^0.4.18":
version "0.4.18"
resolved "https://registry.yarnpkg.com/@renegade-fi/renegade-js/-/renegade-js-0.4.18.tgz#b1c2696350cdfded58cc0b8daca06813c05161bc"
integrity sha512-duybbs++qCzQy0+URK5/n+E2QOwYYKUqvJ16agUxp42kJUt+Zx65o2RMDYeSI5z/7Ze8q1YsWbXwQrkEDVj9hQ==
dependencies:
"@noble/hashes" "^1.3.0"
axios "^1.3.5"
Expand Down

0 comments on commit ea51ce2

Please sign in to comment.