-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(idea/frontend): program balance (#1604)
- Loading branch information
1 parent
d527cbb
commit 893ae57
Showing
23 changed files
with
247 additions
and
197 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { TransferBalance } from './ui'; | ||
import { TransferBalance, ProgramBalance } from './ui'; | ||
|
||
export { TransferBalance }; | ||
export { TransferBalance, ProgramBalance }; |
10 changes: 10 additions & 0 deletions
10
idea/frontend/src/features/balance/ui/balance/balance.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,10 @@ | ||
.value { | ||
font-family: Kanit; | ||
font-weight: 600; | ||
} | ||
|
||
.unit { | ||
font-family: Kanit; | ||
font-weight: 300; | ||
color: rgba(255, 255, 255, 0.7); | ||
} |
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,26 @@ | ||
import { useBalanceFormat } from '@gear-js/react-hooks'; | ||
import { Balance as BalanceType } from '@polkadot/types/interfaces'; | ||
|
||
import styles from './balance.module.scss'; | ||
|
||
type Props = { | ||
value: BalanceType | undefined; | ||
}; | ||
|
||
function Balance({ value }: Props) { | ||
const { getFormattedBalance } = useBalanceFormat(); | ||
|
||
if (!value) return null; | ||
|
||
const balance = getFormattedBalance(value); | ||
|
||
return ( | ||
<p> | ||
<span className={styles.value}>{balance.value}</span> | ||
| ||
<span className={styles.unit}>{balance.unit}</span> | ||
</p> | ||
); | ||
} | ||
|
||
export { Balance }; |
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,3 @@ | ||
import { Balance } from './balance'; | ||
|
||
export { Balance }; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { TransferBalance } from './transfer-balance'; | ||
import { ProgramBalance } from './program-balance'; | ||
|
||
export { TransferBalance }; | ||
export { TransferBalance, ProgramBalance }; |
3 changes: 3 additions & 0 deletions
3
idea/frontend/src/features/balance/ui/program-balance/index.ts
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,3 @@ | ||
import { ProgramBalance } from './program-balance'; | ||
|
||
export { ProgramBalance }; |
5 changes: 5 additions & 0 deletions
5
idea/frontend/src/features/balance/ui/program-balance/program-balance.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,5 @@ | ||
.balance { | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
} |
35 changes: 35 additions & 0 deletions
35
idea/frontend/src/features/balance/ui/program-balance/program-balance.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,35 @@ | ||
import { HexString } from '@gear-js/api'; | ||
import { useAccount, useBalance } from '@gear-js/react-hooks'; | ||
import { Button } from '@gear-js/ui'; | ||
|
||
import { useModalState } from '@/hooks'; | ||
|
||
import PlusSVG from '../../assets/plus.svg?react'; | ||
import { Balance } from '../balance'; | ||
import { TransferBalanceModal } from '../transfer-balance-modal'; | ||
import styles from './program-balance.module.scss'; | ||
|
||
type Props = { | ||
id: HexString; | ||
}; | ||
|
||
function ProgramBalance({ id }: Props) { | ||
const { account } = useAccount(); | ||
const { balance } = useBalance(id); | ||
|
||
const [isModalOpen, openModal, closeModal] = useModalState(); | ||
|
||
return ( | ||
<> | ||
<div className={styles.balance}> | ||
<Balance value={balance} /> | ||
|
||
{account && <Button icon={PlusSVG} color="transparent" onClick={openModal} />} | ||
</div> | ||
|
||
{isModalOpen && <TransferBalanceModal defaultAddress={id} close={closeModal} />} | ||
</> | ||
); | ||
} | ||
|
||
export { ProgramBalance }; |
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
103 changes: 67 additions & 36 deletions
103
idea/frontend/src/features/balance/ui/transfer-balance-modal/transfer-balance-modal.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
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
Oops, something went wrong.