-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from alleslabs/pages/account-delegation
feat: delegation
- Loading branch information
Showing
51 changed files
with
1,862 additions
and
67 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
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,37 @@ | ||
import { Flex, Image } from "@chakra-ui/react"; | ||
import { useWallet } from "@cosmos-kit/react"; | ||
|
||
import { getChainApiPath } from "env"; | ||
import { ExplorerLink } from "lib/components/ExplorerLink"; | ||
import type { ValidatorInfo } from "lib/types"; | ||
|
||
interface ValidatorBadgeProps { | ||
validator: ValidatorInfo; | ||
} | ||
|
||
export const ValidatorBadge = ({ validator }: ValidatorBadgeProps) => { | ||
const { currentChainName } = useWallet(); | ||
|
||
return ( | ||
<Flex alignItems="center" gap={2}> | ||
<Image | ||
boxSize={10} | ||
src={`https://raw.githubusercontent.com/cosmostation/chainlist/master/chain/${getChainApiPath( | ||
currentChainName | ||
)}/${validator.validatorAddress}.png`} | ||
alt={validator.moniker} | ||
fallbackSrc={`https://ui-avatars.com/api/?name=${ | ||
validator.moniker ?? "" | ||
}&background=9793F3&color=fff`} | ||
borderRadius="50%" | ||
/> | ||
<ExplorerLink | ||
value={validator.moniker ?? validator.validatorAddress} | ||
copyValue={validator.validatorAddress} | ||
type="validator_address" | ||
textFormat="ellipsis" | ||
showCopyOnHover | ||
/> | ||
</Flex> | ||
); | ||
}; |
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
76 changes: 76 additions & 0 deletions
76
src/lib/pages/account-details/components/delegations/DelegationsBody.tsx
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,76 @@ | ||
import { Flex, RadioGroup, Stack } from "@chakra-ui/react"; | ||
import { useState } from "react"; | ||
|
||
import { DelegationsTable, UnbondingsTable } from "../tables"; | ||
import type { Delegation, Unbonding } from "lib/pages/account-details/data"; | ||
import type { TokenWithValue } from "lib/pages/account-details/type"; | ||
import { AmpTrackUseRadio } from "lib/services/amplitude"; | ||
import type { Option } from "lib/types"; | ||
|
||
import { RadioCard } from "./RadioCard"; | ||
|
||
interface DelegationsBodyProps { | ||
totalDelegations: Option<Record<string, TokenWithValue>>; | ||
delegations: Option<Delegation[]>; | ||
totalUnbondings: Option<Record<string, TokenWithValue>>; | ||
unbondings: Option<Unbonding[]>; | ||
rewards: Option<Record<string, TokenWithValue[]>>; | ||
isLoadingDelegations: boolean; | ||
isLoadingUnbondings: boolean; | ||
defaultToken: TokenWithValue; | ||
} | ||
|
||
export const DelegationsBody = ({ | ||
totalDelegations, | ||
delegations, | ||
totalUnbondings, | ||
unbondings, | ||
rewards, | ||
isLoadingDelegations, | ||
isLoadingUnbondings, | ||
defaultToken, | ||
}: DelegationsBodyProps) => { | ||
// NOTE: set between "Delegated" and "Unbonding" | ||
const [value, setValue] = useState("Delegated"); | ||
|
||
return ( | ||
<Flex direction="column" gap={8}> | ||
<RadioGroup | ||
onChange={(newValue) => { | ||
AmpTrackUseRadio(newValue.toLocaleLowerCase()); | ||
setValue(newValue); | ||
}} | ||
value={value} | ||
overflowX="scroll" | ||
> | ||
<Stack direction="row"> | ||
<RadioCard | ||
value="Delegated" | ||
total={totalDelegations} | ||
defaultToken={defaultToken} | ||
isLoading={isLoadingDelegations} | ||
/> | ||
<RadioCard | ||
value="Unbonding" | ||
total={totalUnbondings} | ||
defaultToken={defaultToken} | ||
isLoading={isLoadingUnbondings} | ||
/> | ||
</Stack> | ||
</RadioGroup> | ||
{value === "Delegated" ? ( | ||
<DelegationsTable | ||
delegations={delegations} | ||
rewards={rewards} | ||
defaultToken={defaultToken} | ||
isLoading={isLoadingDelegations} | ||
/> | ||
) : ( | ||
<UnbondingsTable | ||
unbondings={unbondings} | ||
isLoading={isLoadingUnbondings} | ||
/> | ||
)} | ||
</Flex> | ||
); | ||
}; |
51 changes: 51 additions & 0 deletions
51
src/lib/pages/account-details/components/delegations/NonRedelegatableSection.tsx
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,51 @@ | ||
import { Box, Text } from "@chakra-ui/react"; | ||
|
||
import { NonRedelegatablesTable } from "../tables"; | ||
import type { Redelegation } from "lib/pages/account-details/data"; | ||
import type { NonRedelegatable } from "lib/pages/account-details/type"; | ||
|
||
interface NonRedelegatableSectionProps { | ||
redelegations: Redelegation[]; | ||
} | ||
|
||
export const NonRedelegatableSection = ({ | ||
redelegations, | ||
}: NonRedelegatableSectionProps) => { | ||
const nonRedelegatables = redelegations | ||
.reduceRight<NonRedelegatable[]>((prev, redelegation) => { | ||
if ( | ||
prev.find( | ||
(value) => | ||
value.dstValidator.validatorAddress === | ||
redelegation.dstValidator.validatorAddress | ||
) | ||
) | ||
return prev; | ||
return prev.concat({ | ||
dstValidator: redelegation.dstValidator, | ||
completionTime: redelegation.completionTime, | ||
}); | ||
}, []) | ||
.reverse(); | ||
|
||
return ( | ||
<Box | ||
px={6} | ||
py={4} | ||
bgColor="pebble.900" | ||
border="1px solid" | ||
borderColor="pebble.700" | ||
borderRadius="8px" | ||
> | ||
<Text variant="body2"> | ||
This account cannot redelegate from | ||
<span style={{ fontWeight: 700 }}> | ||
{" "} | ||
these validators to other validators{" "} | ||
</span> | ||
until their active redelegations have completed. | ||
</Text> | ||
<NonRedelegatablesTable nonRedelegatables={nonRedelegatables} /> | ||
</Box> | ||
); | ||
}; |
51 changes: 51 additions & 0 deletions
51
src/lib/pages/account-details/components/delegations/RadioCard.tsx
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,51 @@ | ||
import { Flex, Radio, Text, Heading, Spinner } from "@chakra-ui/react"; | ||
|
||
import type { TokenWithValue } from "lib/pages/account-details/type"; | ||
import type { Option } from "lib/types"; | ||
import { | ||
formatPrice, | ||
formatUTokenWithPrecision, | ||
getTokenLabel, | ||
} from "lib/utils"; | ||
|
||
interface RadioCardProps { | ||
value: string; | ||
total: Option<Record<string, TokenWithValue>>; | ||
defaultToken: TokenWithValue; | ||
isLoading: boolean; | ||
} | ||
|
||
export const RadioCard = ({ | ||
value, | ||
total, | ||
defaultToken, | ||
isLoading, | ||
}: RadioCardProps) => { | ||
const token = total?.[defaultToken.denom] ?? defaultToken; | ||
return ( | ||
<Radio variant="card" value={value} overflowX="hidden"> | ||
<Flex alignItems="center" gap={2} justifyContent="space-between"> | ||
<Flex direction="column" gap={1}> | ||
<Text variant="body2" textColor="pebble.400" fontWeight="500"> | ||
{value} | ||
</Text> | ||
{isLoading ? ( | ||
<Spinner mt={2} alignSelf="center" size="md" speed="0.65s" /> | ||
) : ( | ||
<Flex alignItems="end" gap={1}> | ||
<Heading variant="h6" as="h6"> | ||
{formatUTokenWithPrecision(token.amount, token.precision || 0)} | ||
</Heading> | ||
<Text variant="body2" textColor="text.main"> | ||
{getTokenLabel(token.denom)} | ||
</Text> | ||
</Flex> | ||
)} | ||
</Flex> | ||
<Text variant="body2" textColor="text.dark"> | ||
({token.value ? formatPrice(token.value) : "-"}) | ||
</Text> | ||
</Flex> | ||
</Radio> | ||
); | ||
}; |
Oops, something went wrong.
f77d319
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
terra-celatone-frontend-staging – ./
terra-celatone-frontend-staging.vercel.app
terra-staging.celat.one
terra-celatone-frontend-staging-git-develop-alleslabs.vercel.app
terra-celatone-frontend-staging-alleslabs.vercel.app
f77d319
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
osmosis-celatone-frontend-staging – ./
osmosis-celatone-frontend-staging-git-develop-alleslabs.vercel.app
osmosis-staging.celat.one
celatone-frontend-staging.vercel.app
osmosis-celatone-frontend-staging-alleslabs.vercel.app
celatone-staging.osmosis.zone