Skip to content

Commit

Permalink
Merge Submit and Success
Browse files Browse the repository at this point in the history
  • Loading branch information
KaffinPX committed Jun 28, 2024
1 parent 789219e commit 95780b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 42 deletions.
11 changes: 2 additions & 9 deletions src/pages/Wallet/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ import { useState } from "react"
import { Dialog } from "@/components/ui/dialog"
import Sign from "./Send/Sign"
import Submit from "./Send/Submit"
import Success from "./Send/Success"
import useURLParams from "@/hooks/useURLParams"

export enum Tabs {
Creation,
Sign,
Submit,
Success
}

export default function SendDrawer () {
Expand All @@ -32,7 +30,6 @@ export default function SendDrawer () {
const [ recipient, setRecipient ] = useState(params.get('recipient') ?? "")
const [ amount, setAmount ] = useState(params.get('amount') ?? "")
const [ transactions, setTransactions ] = useState<string[]>()
const [ ids, setIds ] = useState<string[]>()
const [ error, setError ] = useState("")
const [ tab, setTab ] = useState(Tabs.Creation)

Expand Down Expand Up @@ -112,13 +109,9 @@ export default function SendDrawer () {
setTransactions(transactions)
setTab(Tabs.Submit)
}} />}
{tab === Tabs.Submit && <Submit transactions={transactions!} onSubmitted={(ids) => {
if (hash === 'send') return window.close()

setIds(ids)
setTab(Tabs.Success)
{tab === Tabs.Submit && <Submit transactions={transactions!} onSubmitted={() => {
if (hash === 'send') window.close()
}} />}
{tab === Tabs.Success && <Success ids={ids!} />}
</Dialog>
</div>
</div>
Expand Down
17 changes: 12 additions & 5 deletions src/pages/Wallet/Send/Submit.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Network } from "lucide-react"
import { NetworkIcon, PackageCheckIcon } from "lucide-react"
import {
DialogContent,
DialogDescription,
Expand All @@ -8,32 +8,39 @@ import {
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import useKaspa from "@/hooks/useKaspa"
import { useState } from "react"

export default function Submit ({ transactions, onSubmitted }: {
transactions: string[]
onSubmitted: (ids: string[]) => void
onSubmitted: () => void
}) {
const kaspa = useKaspa()
const [ ids, setIds ] = useState<string[]>([])

return (
<DialogContent>
<DialogHeader>
<DialogTitle>Submit Transaction</DialogTitle>
<DialogDescription>
Submit your signed transaction batch to network, miners should verify and add it to a block.
Submit your signed transaction(s) to network, miners should add it to a block.
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button variant="link" className={"dark:text-white font-bold"} disabled={ids.length === 0} onClick={() => {
window.open(`https://explorer.kaspa.org/txs/${ids[0]}`)
}}>View it on the explorer</Button>

<Button className={"gap-2"} onClick={({ currentTarget }) => {
currentTarget.disabled = true

kaspa.request('node:submit', [ transactions ]).then((ids) => {
onSubmitted(ids)
setIds(ids)
onSubmitted()
}).catch(() => {
currentTarget.disabled = false
})
}}>
<Network />
{ ids.length === 0 ? <NetworkIcon /> : <PackageCheckIcon /> }
Submit
</Button>
</DialogFooter>
Expand Down
28 changes: 0 additions & 28 deletions src/pages/Wallet/Send/Success.tsx

This file was deleted.

0 comments on commit 95780b7

Please sign in to comment.