-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4985a75
commit 3ff60d5
Showing
10 changed files
with
316 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useCallback, useState } from "react"; | ||
import { useTranslation } from "@hooks"; | ||
import { useCardano, useSnackbar } from "@/context"; | ||
|
||
export const useDelegateTodRep = () => { | ||
const { | ||
buildSignSubmitConwayCertTx, | ||
buildVoteDelegationCert, | ||
} = useCardano(); | ||
const { t } = useTranslation(); | ||
const { addSuccessAlert, addErrorAlert } = useSnackbar(); | ||
|
||
const [isDelegating, setIsDelegating] = useState(false); | ||
|
||
const delegate = useCallback(async (dRepId: string | undefined) => { | ||
if (!dRepId) return; | ||
setIsDelegating(true); | ||
try { | ||
const certBuilder = await buildVoteDelegationCert(dRepId); | ||
const result = await buildSignSubmitConwayCertTx({ | ||
certBuilder, | ||
type: "delegate", | ||
resourceId: dRepId, | ||
}); | ||
if (result) { | ||
addSuccessAlert(t("alerts.delegate.success")); | ||
} | ||
} catch (error) { | ||
addErrorAlert(t("alerts.delegate.failed")); | ||
} finally { | ||
setIsDelegating(false); | ||
} | ||
}, [ | ||
addErrorAlert, | ||
addSuccessAlert, | ||
buildSignSubmitConwayCertTx, | ||
buildVoteDelegationCert, | ||
t, | ||
]); | ||
|
||
return { | ||
delegate, | ||
isDelegating, | ||
}; | ||
}; |
Oops, something went wrong.