-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added low and insufficient balance UI (#200)
Resovles #180 The tests passes locally [video.webm](https://github.com/user-attachments/assets/40b185bc-403c-4cb0-8fd8-c6455e6a50d4) [video.webm](https://github.com/user-attachments/assets/c9d6fa00-4587-4afe-9d09-5d5e75099f77) [video.webm](https://github.com/user-attachments/assets/417c9ed6-5220-4d64-8483-ee3b3b35cc6b) [video.webm](https://github.com/user-attachments/assets/1c2a0de4-55bf-43aa-94f8-ef7fba383aa8) [video.webm](https://github.com/user-attachments/assets/cf62a42f-386f-4b8e-9842-f8120339359a) [video.webm](https://github.com/user-attachments/assets/2a82a1c9-9946-41bf-a363-51651391d5e8)
- Loading branch information
1 parent
c51dcad
commit 2062b7e
Showing
26 changed files
with
732 additions
and
163 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
88 changes: 88 additions & 0 deletions
88
instances/treasury-devdao.near/widget/components/BalanceBanner.jsx
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,88 @@ | ||
const { getNearBalances } = VM.require( | ||
"${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/lib.common" | ||
); | ||
|
||
const Container = styled.div` | ||
.low-balance-warning { | ||
background: rgba(255, 158, 0, 0.1); | ||
color: var(--other-warning); | ||
padding-inline: 0.8rem; | ||
padding-block: 0.5rem; | ||
font-weight: 500; | ||
font-size: 13px; | ||
h5 { | ||
color: var(--other-warning) !important; | ||
} | ||
} | ||
.insufficient-balance-warning { | ||
background-color: rgba(217, 92, 74, 0.08); | ||
color: var(--other-red); | ||
padding-inline: 0.8rem; | ||
padding-block: 0.5rem; | ||
font-weight: 500; | ||
font-size: 13px; | ||
h5 { | ||
color: var(--other-red) !important; | ||
} | ||
} | ||
`; | ||
|
||
function formatNearAmount(amount) { | ||
return parseFloat( | ||
Big(amount ?? "0") | ||
.div(Big(10).pow(24)) | ||
.toFixed(2) | ||
); | ||
} | ||
|
||
function BalanceBanner({ accountId, treasuryDaoID }) { | ||
if (!treasuryDaoID || typeof getNearBalances !== "function" || !accountId) { | ||
return <></>; | ||
} | ||
|
||
const nearBalances = getNearBalances(accountId); | ||
|
||
const LOW_BALANCE_LIMIT = 0.7; // 0.7N | ||
const INSUFFICIENT_BALANCE_LIMIT = 0.1; // 0.1N | ||
|
||
const profile = Social.getr(`${accountId}/profile`); | ||
const name = profile.name ?? accountId; | ||
|
||
return ( | ||
<Container> | ||
{!nearBalances || | ||
!nearBalances.availableParsed || | ||
nearBalances.availableParsed === "0.00" || | ||
parseFloat(nearBalances.availableParsed) > LOW_BALANCE_LIMIT ? ( | ||
<></> | ||
) : parseFloat(nearBalances.availableParsed) < | ||
INSUFFICIENT_BALANCE_LIMIT ? ( | ||
<div className="insufficient-balance-warning d-flex gap-3 p-3 rounded-3 m-3"> | ||
<i class="bi bi-exclamation-octagon error-icon h4 mb-0"></i> | ||
<div> | ||
<h5>Insufficient Funds</h5> | ||
Hey {name}, you don't have enough NEAR to complete actions on your | ||
treasury. You need at least {INSUFFICIENT_BALANCE_LIMIT}N. Please | ||
add more funds to your account and try again | ||
</div> | ||
</div> | ||
) : ( | ||
<div className="low-balance-warning d-flex gap-3 p-3 rounded-3 m-3"> | ||
<i class="bi bi-exclamation-triangle warning-icon h4 mb-0"></i> | ||
<div> | ||
<h5>Low Balance</h5> | ||
Hey {name}, your NEAR balance is {nearBalances.availableParsed}N, | ||
which is getting low. The minimum balance required is{" "} | ||
{INSUFFICIENT_BALANCE_LIMIT}N. Please add more NEAR to your account | ||
soon to avoid any issues completing actions on your treasury. | ||
</div> | ||
</div> | ||
)} | ||
</Container> | ||
); | ||
} | ||
|
||
return { BalanceBanner }; |
74 changes: 74 additions & 0 deletions
74
instances/treasury-devdao.near/widget/components/InsufficientBannerModal.jsx
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,74 @@ | ||
const { getNearBalances } = VM.require( | ||
"${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/lib.common" | ||
); | ||
|
||
const { Modal, ModalContent, ModalHeader, ModalFooter } = VM.require( | ||
"${REPL_BASE_DEPLOYMENT_ACCOUNT}/widget/lib.modal" | ||
); | ||
|
||
function formatNearAmount(amount) { | ||
return parseFloat( | ||
Big(amount ?? "0") | ||
.div(Big(10).pow(24)) | ||
.toFixed(2) | ||
); | ||
} | ||
|
||
const { ActionButton, checkForDeposit, treasuryDaoID, callbackAction } = props; | ||
|
||
const nearBalances = getNearBalances(context.accountId); | ||
const profile = Social.getr(`${context.accountId}/profile`); | ||
const name = profile.name ?? context.accountId; | ||
const daoPolicy = useCache( | ||
() => Near.asyncView(treasuryDaoID, "get_policy"), | ||
"get_policy", | ||
{ subscribe: false } | ||
); | ||
|
||
const [showModal, setShowModal] = useState(false); | ||
const ADDITIONAL_AMOUNT = checkForDeposit | ||
? formatNearAmount(daoPolicy?.proposal_bond) | ||
: 0; | ||
|
||
const INSUFFICIENT_BALANCE_LIMIT = ADDITIONAL_AMOUNT + 0.1; // 0.1N | ||
|
||
function checkBalance() { | ||
if (parseFloat(nearBalances?.availableParsed) < INSUFFICIENT_BALANCE_LIMIT) { | ||
setShowModal(true); | ||
} else { | ||
callbackAction(); | ||
} | ||
} | ||
|
||
const WarningModal = () => ( | ||
<Modal sty> | ||
<ModalHeader> | ||
<div className="d-flex align-items-center justify-content-between mb-2"> | ||
<div className="d-flex gap-3"> | ||
<i class="bi bi-exclamation-octagon error-icon h4 mb-0"></i> | ||
Insufficient Funds | ||
</div> | ||
<i | ||
className="bi bi-x-lg h4 mb-0 cursor-pointer" | ||
onClick={() => setShowModal(false)} | ||
></i> | ||
</div> | ||
</ModalHeader> | ||
<ModalContent> | ||
Hey {name}, you don't have enough NEAR to complete actions on your | ||
treasury. You need at least {INSUFFICIENT_BALANCE_LIMIT}N{" "} | ||
{checkForDeposit && | ||
", which includes the proposal bond needed to create a proposal"} | ||
. Please add more funds to your account and try again. | ||
</ModalContent> | ||
</Modal> | ||
); | ||
|
||
return ( | ||
<> | ||
<div onClick={checkBalance}> | ||
<ActionButton /> | ||
</div> | ||
{showModal && <WarningModal />} | ||
</> | ||
); |
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.