-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
9 changed files
with
315 additions
and
60 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
111 changes: 111 additions & 0 deletions
111
...nents/networks/components/network_grid/components/network_card/stake_accounts.module.scss
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,111 @@ | ||
@import "src/styles/sass.scss"; | ||
|
||
.statusActivating { | ||
background: #007fff; | ||
} | ||
|
||
.statusActive { | ||
background: #1ec490; | ||
} | ||
|
||
.statusDeactivating { | ||
background: #e4a11e; | ||
} | ||
|
||
.statusActivating, | ||
.statusActive, | ||
.statusDeactivating { | ||
align-items: flex-start; | ||
border-radius: 4px; | ||
color: #fff; | ||
display: inline-block; | ||
font-size: 12px; | ||
gap: 10px; | ||
padding: 2px 4px; | ||
} | ||
|
||
.stakeAccount { | ||
align-items: center; | ||
background: rgba(255, 255, 255, 0.34); | ||
box-shadow: | ||
0 6px 14px -6px rgba(2, 38, 225, 0.12), | ||
0 10px 32px -4px rgba(2, 38, 225, 0.1); | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
padding: 12px; | ||
width: 100%; | ||
} | ||
|
||
.external { | ||
img { | ||
height: 20px; | ||
width: 20px; | ||
} | ||
} | ||
|
||
.stakeIcon { | ||
height: 20px; | ||
width: 20px; | ||
} | ||
|
||
.title { | ||
align-items: center; | ||
display: flex; | ||
flex-direction: row; | ||
gap: 4px; | ||
justify-content: flex-start; | ||
|
||
span { | ||
color: #25282d; | ||
font-size: 12px; | ||
font-weight: 600; | ||
line-height: 16px; | ||
text-shadow: | ||
0 8px 22px rgba(2, 38, 225, 0.12), | ||
0 14px 64px rgba(2, 38, 225, 0.12); | ||
} | ||
} | ||
|
||
.left { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 4px; | ||
} | ||
|
||
.status { | ||
display: flex; | ||
justify-content: flex-start; | ||
} | ||
|
||
.value { | ||
color: #25282d; | ||
font-size: 16px; | ||
font-weight: 600; | ||
letter-spacing: 0.032px; | ||
line-height: 20px; | ||
text-align: right; | ||
text-shadow: | ||
0 8px 22px rgba(2, 38, 225, 0.12), | ||
0 14px 64px rgba(2, 38, 225, 0.12); | ||
} | ||
|
||
.numbers { | ||
align-items: flex-end; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 4px; | ||
justify-content: space-between; | ||
} | ||
|
||
.extra { | ||
color: #059c78; | ||
font-size: 14px; | ||
font-weight: 400; | ||
letter-spacing: 0.308px; | ||
line-height: 20px; | ||
text-align: right; | ||
text-shadow: | ||
0 8px 22px rgba(2, 38, 225, 0.12), | ||
0 14px 64px rgba(2, 38, 225, 0.12); | ||
} |
154 changes: 154 additions & 0 deletions
154
...ng/components/networks/components/network_grid/components/network_card/stake_accounts.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,154 @@ | ||
import useTranslation from "next-translate/useTranslation"; | ||
import { useEffect, useMemo } from "react"; | ||
|
||
import { useStakingRef } from "@src/screens/staking/lib/staking_sdk/context"; | ||
import { fetchCoinPriceForNetwork } from "@src/screens/staking/lib/staking_sdk/context/actions"; | ||
import type { NetworkClaimableRewards } from "@src/screens/staking/lib/staking_sdk/context/selectors"; | ||
import { | ||
getClaimableRewardsForNetwork, | ||
getStakeAccountsForNetwork, | ||
getStakedDataForNetwork, | ||
getUnbondingTokensForNetwork, | ||
} from "@src/screens/staking/lib/staking_sdk/context/selectors"; | ||
import { networkKeyToNetworkId } from "@src/screens/staking/lib/staking_sdk/core"; | ||
import type { Coin } from "@src/screens/staking/lib/staking_sdk/core/base"; | ||
import { WalletId } from "@src/screens/staking/lib/staking_sdk/core/base"; | ||
import { formatCoin } from "@src/screens/staking/lib/staking_sdk/formatters"; | ||
import type { StakeAccount } from "@src/screens/staking/lib/staking_sdk/staking_client_types"; | ||
import { getExplorerLink } from "@src/screens/staking/lib/staking_sdk/utils/accounts"; | ||
import type { Network, NetworkKey } from "@src/utils/network_info"; | ||
|
||
import * as styles from "./stake_accounts.module.scss"; | ||
|
||
type Props = { | ||
network: Network; | ||
onClose: () => void; | ||
}; | ||
|
||
const StakeAccounts = ({ network, onClose }: Props) => { | ||
const stakingNetworkId = networkKeyToNetworkId[network.key as NetworkKey]; | ||
|
||
const stakingRef = useStakingRef(); | ||
|
||
const { t } = useTranslation("staking"); | ||
|
||
const { stakeAccounts } = useMemo(() => { | ||
const wallet = WalletId.Keplr; | ||
|
||
const result = { | ||
claimableRewards: null as NetworkClaimableRewards | null, | ||
stakeAccounts: null as null | StakeAccount[], | ||
stakedData: null as Coin | null, | ||
unbondingTokens: null as { period: string; text: string } | null, | ||
}; | ||
|
||
if (!!stakingNetworkId && !!wallet) { | ||
result.stakeAccounts = getStakeAccountsForNetwork( | ||
stakingRef.current.state, | ||
stakingNetworkId, | ||
); | ||
|
||
result.stakedData = getStakedDataForNetwork( | ||
stakingRef.current.state, | ||
stakingNetworkId, | ||
); | ||
|
||
result.claimableRewards = | ||
getClaimableRewardsForNetwork( | ||
stakingRef.current.state, | ||
stakingNetworkId, | ||
) || null; | ||
|
||
const unbonding = getUnbondingTokensForNetwork( | ||
stakingRef.current.state, | ||
stakingNetworkId, | ||
); | ||
|
||
if (unbonding) { | ||
result.unbondingTokens = { | ||
period: unbonding.period | ||
? new Date(Number(unbonding.period) * 1000).toLocaleString() | ||
: "", | ||
text: formatCoin(unbonding.coin, { decimals: 4 }), | ||
}; | ||
} | ||
} | ||
|
||
return result; | ||
}, [stakingNetworkId, stakingRef]); | ||
|
||
useEffect(() => { | ||
fetchCoinPriceForNetwork(stakingRef.current, stakingNetworkId); | ||
}, [stakingRef, stakingNetworkId]); | ||
|
||
return ( | ||
<div> | ||
<div> | ||
<button onClick={onClose}>{"<"}</button> {t("accounts")}{" "} | ||
{stakeAccounts?.length} | ||
</div> | ||
<div> | ||
{stakeAccounts?.map((account) => { | ||
const shortenedAddress = `${account.address.slice(0, 8)}...`; | ||
|
||
const explorerLink = getExplorerLink( | ||
account.address, | ||
stakingNetworkId, | ||
); | ||
|
||
const statusLabel = | ||
{ | ||
activating: t("stakeAccount.status.activating"), | ||
active: t("stakeAccount.status.active"), | ||
deactivating: t("stakeAccount.status.deactivating"), | ||
}[account.status] || account.status; | ||
|
||
const statusStyle = | ||
{ | ||
activating: styles.statusActivating, | ||
active: styles.statusActive, | ||
deactivating: styles.statusDeactivating, | ||
}[account.status] || null; | ||
|
||
return ( | ||
<div className={styles.stakeAccount} key={account.address}> | ||
<div className={styles.left}> | ||
<div className={styles.title}> | ||
<img | ||
alt="" | ||
className={styles.stakeIcon} | ||
src="/icons/stake_account.svg" | ||
/> | ||
<span>{shortenedAddress}</span> | ||
{!!explorerLink && ( | ||
<> | ||
{" "} | ||
<a | ||
className={styles.external} | ||
href={explorerLink} | ||
target="_blank" | ||
> | ||
<img alt="" src="/icons/external.svg" /> | ||
</a> | ||
</> | ||
)} | ||
</div> | ||
<div className={styles.status}> | ||
{!!statusStyle && ( | ||
<span className={statusStyle}>{statusLabel}</span> | ||
)} | ||
</div> | ||
</div> | ||
<div className={styles.numbers}> | ||
<div className={styles.value}>{formatCoin(account)}</div> | ||
<div className={styles.extra}>+123</div> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StakeAccounts; |
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
Oops, something went wrong.