Skip to content

Commit

Permalink
matched
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Feb 26, 2024
1 parent df6421d commit fdd976d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
8 changes: 4 additions & 4 deletions trade.renegade.fi/components/panels/wallets-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function DepositWithdrawButtons() {
<Text>Deposit</Text>
<ArrowDownIcon />
</Flex>
<Flex
{/* <Flex
alignItems="center"
justifyContent="center"
flexGrow="1"
Expand All @@ -158,7 +158,7 @@ function DepositWithdrawButtons() {
>
<Text>Airdrop</Text>
<ArrowUpIcon />
</Flex>
</Flex> */}
</Flex>
)
}
Expand Down Expand Up @@ -255,8 +255,8 @@ 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>
)
Expand Down
42 changes: 33 additions & 9 deletions trade.renegade.fi/components/place-order-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import { toast } from "sonner"
import { v4 as uuidv4 } from "uuid"
import { useAccount as useAccountWagmi } from "wagmi"

import { findBalanceByTicker } from "@/lib/utils"
import { findBalanceByTicker, safeLocalStorageGetItem, safeLocalStorageSetItem } from "@/lib/utils"
import { useBalance } from "@/hooks/use-balance"
import { useButton } from "@/hooks/use-button"
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"

export function PlaceOrderButton() {
const { address } = useAccountWagmi()
Expand All @@ -41,6 +42,11 @@ export function PlaceOrderButton() {
onOpenSignIn,
signInText: "Sign in to Place Orders",
})
const timestampMap = useMemo(() => {
const o = safeLocalStorageGetItem("timestampMap")
const parsed = o ? JSON.parse(o) : {}
return parsed
}, [])

const handlePlaceOrder = async () => {
if (!accountId) return
Expand All @@ -55,10 +61,29 @@ export function PlaceOrderButton() {
})
renegade.task
.placeOrder(accountId, order)
.then(() => {
const o = safeLocalStorageGetItem(`order-details-${accountId}`)
const parseO: LocalOrder[] = o ? JSON.parse(o) : []
const newO = [
...parseO,
{
id,
base: order.baseToken.address,
quote: order.quoteToken.address,
side: direction,
amount: baseTokenAmount,
},
]
safeLocalStorageSetItem(
`order-details-${accountId}`,
JSON.stringify(newO)
)
timestampMap[id] = order.timestamp
safeLocalStorageSetItem("timestampMap", JSON.stringify(timestampMap))
})
.then(() =>
toast.message(
`Started to place order to ${
direction === "buy" ? "Buy" : "Sell"
`Started to place order to ${direction === "buy" ? "Buy" : "Sell"
} ${baseTokenAmount} ${baseTicker} for ${quoteTicker}`,
{
description: "Check the history tab for the status of the task",
Expand Down Expand Up @@ -94,9 +119,8 @@ export function PlaceOrderButton() {
} else if (hasInsufficientBalance) {
placeOrderButtonContent = "Insufficient Balance"
} else {
placeOrderButtonContent = `Place Order for ${
baseTokenAmount || ""
} ${baseTicker}`
placeOrderButtonContent = `Place Order for ${baseTokenAmount || ""
} ${baseTicker}`
}
const isDisabled = accountId && (!baseTokenAmount || hasInsufficientBalance)

Expand All @@ -115,9 +139,9 @@ export function PlaceOrderButton() {
isDisabled
? { backgroundColor: "transparent" }
: {
borderColor: "white.60",
color: "white",
}
borderColor: "white.60",
color: "white",
}
}
transform={baseTokenAmount ? "translateY(10px)" : "translateY(-10px)"}
visibility={baseTokenAmount ? "visible" : "hidden"}
Expand Down

0 comments on commit fdd976d

Please sign in to comment.