Skip to content

Commit

Permalink
attempts auto login if localstorage key is set
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Feb 13, 2024
1 parent 686d811 commit 699d845
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
23 changes: 7 additions & 16 deletions trade.renegade.fi/app/(desktop)/[base]/[quote]/deposit-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import {
useDisclosure
} from "@chakra-ui/react"
import { Token } from "@renegade-fi/renegade-js"
import { useState } from "react"
import { useAccount } from "wagmi"
import { useAccount, useWaitForTransaction } from "wagmi"

const MAX_INT = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935")

Expand Down Expand Up @@ -52,17 +51,11 @@ export default function DepositButton() {
const { config } = usePrepareErc20Approve({
address: Token.findAddressByTicker(baseTicker) as `0x${string}`,
args: [env.NEXT_PUBLIC_DARKPOOL_CONTRACT as `0x${string}`, MAX_INT],
onSettled: () => {
console.log("settled")
setIsLoading(false)
},
onSuccess: () => {
console.log("success")
setIsLoading(false)
}
})
const { write: approve } = useErc20Approve(config)
const [isLoading, setIsLoading] = useState(false)
const { write: approve, isLoading: approveIsLoading, data: approveData } = useErc20Approve(config,)
const { isLoading: txIsLoading } = useWaitForTransaction({
hash: approveData?.hash,
})

const handleApprove = async () => {
if (!accountId || !approve) return
Expand All @@ -73,7 +66,7 @@ export default function DepositButton() {
if (shouldUse) {
buttonOnClick()
} else if (needsApproval) {
setIsLoading(true)
// setIsLoading(true)
handleApprove()
} else {
onOpenStepper()
Expand Down Expand Up @@ -105,9 +98,7 @@ export default function DepositButton() {
transition="0.15s"
backgroundColor="transparent"
isDisabled={isDisabled}
// isLoading={isLocked}
// loadingText="Please wait for task completion"
isLoading={isLoading}
isLoading={approveIsLoading || txIsLoading}
loadingText="Approving"
onClick={handleClick}
rightIcon={<ArrowForwardIcon />}
Expand Down
12 changes: 6 additions & 6 deletions trade.renegade.fi/contexts/Renegade/renegade-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ function RenegadeProvider({ children }: React.PropsWithChildren) {
}
}, [accountId, seed, setAccountId, setSeed])

// React.useEffect(() => {
// initAccount()
// }, [accountId, initAccount, seed])
const [shouldAutoLogin] = useLocalStorage<boolean>('shouldAutoLogin', false)
React.useEffect(() => {
if (shouldAutoLogin) {
initAccount()
}
}, [initAccount, shouldAutoLogin])

const { address } = useAccount()
// Define the setAccount handler. This handler unregisters the previous
Expand All @@ -136,9 +139,7 @@ function RenegadeProvider({ children }: React.PropsWithChildren) {
oldAccountId?: AccountId,
keychain?: Keychain
): Promise<void> {
console.log("Manually setting account: ", keychain)
if (oldAccountId) {
console.log("Unregistering old account: ", oldAccountId)
await renegade.unregisterAccount(oldAccountId)
}
if (!keychain) {
Expand All @@ -147,7 +148,6 @@ function RenegadeProvider({ children }: React.PropsWithChildren) {
}
// Register and initialize the new account.
const accountId = renegade.registerAccount(keychain)
console.log("From SDK: ", accountId)
await renegade.task
.initializeAccount(accountId)
.then(([taskId, taskJob]) => {
Expand Down

0 comments on commit 699d845

Please sign in to comment.