Skip to content

Commit

Permalink
Unlock Tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
vkulinich-cl committed Dec 12, 2024
1 parent 6c20fb6 commit d3b8b46
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/i18n/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@
"wallet.assets.table.details.lockedVesting": "Locked in Vesting",
"wallet.assets.table.details.lockedDemocracy": "Locked in Democracy",
"wallet.assets.table.details.unlockable": "Unlockable",
"wallet.assets.table.details.btn": "Clear locks",
"wallet.assets.table.details.clear": "Clear locks",
"wallet.assets.table.details.unlock": "Unlock tokens",
"wallet.assets.table.details.lockedStaking": "Total Locked in Staking",
"wallet.assets.table.details.noprice.tooltip": "Spot price currently not available",
"wallet.assets.table.details.expired_one": "{{count}} Expired lock",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ const NativeLocks = ({
toast,
})

const isUnlockDisabled = !unlocable.ids.length && unlocable.value.isZero()
const title =
!unlocable.ids.length && unlocable.value.gt(0)
? t("wallet.assets.table.details.unlock")
: t("wallet.assets.table.details.clear")

return (
<div sx={{ flex: "row", flexWrap: "wrap", py: 20 }}>
<div
Expand Down Expand Up @@ -401,13 +407,13 @@ const NativeLocks = ({
size="compact"
disabled={
account?.isExternalWalletConnected ||
!unlocable.ids.length ||
isUnlockDisabled ||
unlock.isLoading
}
onClick={() => unlock.mutate()}
isLoading={unlock.isLoading}
>
{t("wallet.assets.table.details.btn")}
{title}
</Button>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,16 @@ export const useUnlockTokens = ({
return useMutation(async () => {
const txs = ids.map((id) => api.tx.democracy.removeVote(id))

if (!txs.length) return null
if (!account?.address) return null

return await createTransaction(
{
tx: api.tx.utility.batchAll([
...txs,
...(account?.address
? [api.tx.democracy.unlock(account.address)]
: []),
]),
tx: txs.length
? api.tx.utility.batchAll([
...txs,
api.tx.democracy.unlock(account.address),
])
: api.tx.democracy.unlock(account.address),
},
{
toast,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import BN from "bignumber.js"
import { Button } from "components/Button/Button"
import { Separator } from "components/Separator/Separator"
import { BN_0, BN_NAN } from "utils/constants"
import { BN_NAN } from "utils/constants"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"
import { TOAST_MESSAGES } from "state/toasts"
import { ToastMessage } from "state/store"
Expand Down Expand Up @@ -91,6 +91,12 @@ const NativeAssetDetails = ({
toast,
})

const isUnlockDisabled = !unlocable.ids.length && unlocable.value.isZero()
const title =
!unlocable.ids.length && unlocable.value.gt(0)
? t("wallet.assets.table.details.unlock")
: t("wallet.assets.table.details.clear")

return (
<SContainer hasChain={false} isNativeAsset>
<div>
Expand Down Expand Up @@ -140,7 +146,9 @@ const NativeAssetDetails = ({
</SLocksContainer>
) : null}
</div>
<div sx={{ flex: "row", justify: "space-between", align: "center" }}>
<div
sx={{ flex: "row", justify: "space-between", align: "center", gap: 4 }}
>
<div>
<Text fs={14} lh={14} fw={500} color="basic300">
{t("wallet.assets.table.details.unlockable")}
Expand All @@ -150,14 +158,14 @@ const NativeAssetDetails = ({
{unlocable.isLoading ? (
<Skeleton height={14} width={30} />
) : (
t("value.token", { value: unlocable.value ?? BN_0 })
t("value.token", { value: unlocable.value })
)}
</Text>
<Text fs={11} lh={14} fw={500} color="whiteish500">
{unlocable.isLoading ? (
<Skeleton height={10} width={20} />
) : (
<DisplayValue value={unlocable.displayValue ?? BN_0} />
<DisplayValue value={unlocable.displayValue} />
)}
</Text>
{unlocable.votesUnlocked ? (
Expand All @@ -176,13 +184,13 @@ const NativeAssetDetails = ({
size="compact"
disabled={
account?.isExternalWalletConnected ||
!unlocable.ids.length ||
isUnlockDisabled ||
unlock.isLoading
}
onClick={() => unlock.mutate()}
isLoading={unlock.isLoading}
>
{t("wallet.assets.table.details.btn")}
{title}
</Button>
</div>
<div css={{ gridColumn: "1/4", height: 1 }}>
Expand Down

0 comments on commit d3b8b46

Please sign in to comment.