-
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.
- Loading branch information
1 parent
393a6ca
commit a2ba519
Showing
5 changed files
with
136 additions
and
10 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
66 changes: 66 additions & 0 deletions
66
instances/treasury-devdao.near/widget/pages/dashboard/Portfolio.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,66 @@ | ||
const treasuryAccount = "${REPL_TREASURY}"; | ||
const Portfolio = () => { | ||
const tokensAPI = fetch( | ||
`https://api3.nearblocks.io/v1/account/${treasuryAccount}/inventory` | ||
); | ||
const loading = ( | ||
<Widget src={"${REPL_DEVHUB}/widget/devhub.components.molecule.Spinner"} /> | ||
); | ||
const tokens = tokensAPI?.body?.inventory?.fts ?? []; | ||
return ( | ||
<div className="card card-body flex-1"> | ||
<div className="h5">Portfolio</div> | ||
<div className=""> | ||
{tokensAPI === null ? ( | ||
<div className="d-flex justify-content-center align-items-center w-100 h-100"> | ||
{loading} | ||
</div> | ||
) : ( | ||
<div className="mt-2"> | ||
{!tokens.length ? ( | ||
<div className="fw-bold"> | ||
{treasuryAccount} doesn't own any FTs. | ||
</div> | ||
) : ( | ||
<div className="d-flex flex-column"> | ||
{tokens.map((item, index) => { | ||
const { ft_meta, amount } = item; | ||
const { decimals, symbol, icon, price } = ft_meta; | ||
const tokensNumber = Big(amount) | ||
.div(Big(10).pow(decimals)) | ||
.toFixed(2); | ||
const tokenPrice = price ?? 0; | ||
const currentAmount = Big(tokensNumber) | ||
.mul(tokenPrice) | ||
.toFixed(2); | ||
return ( | ||
<div | ||
className={ | ||
"py-2 d-flex gap-2 align-items-center justify-content-between " + | ||
(index !== tokens.length - 1 && " border-bottom") | ||
} | ||
> | ||
<div className="d-flex gap-2 align-items-center"> | ||
<img src={icon} height={40} /> | ||
<div className=""> | ||
<div className="h6 mb-0">{symbol}</div> | ||
<div className="d-flex gap-2 text-sm text-muted"> | ||
<div>{tokensNumber}</div> | ||
<div>・ ${tokenPrice}</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="fw-bold">${currentAmount}</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
return { Portfolio }; |
26 changes: 26 additions & 0 deletions
26
instances/treasury-devdao.near/widget/pages/dashboard/TransactionHistory.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,26 @@ | ||
const treasuryAccount = "${REPL_TREASURY}"; | ||
const TransactionHistory = () => { | ||
const transactions = fetch( | ||
`https://api3.nearblocks.io/v1/account/${treasuryAccount}/activities?per_page=25` | ||
); | ||
const loading = ( | ||
<Widget src={"${REPL_DEVHUB}/widget/devhub.components.molecule.Spinner"} /> | ||
); | ||
|
||
return ( | ||
<div className="card card-body flex-1"> | ||
<div className="h5">Transaction History</div> | ||
<div className=""> | ||
{transactions === null ? ( | ||
<div className="d-flex justify-content-center align-items-center w-100 h-100"> | ||
{loading} | ||
</div> | ||
) : ( | ||
<div></div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
return { TransactionHistory }; |
43 changes: 42 additions & 1 deletion
43
instances/treasury-devdao.near/widget/pages/dashboard/index.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 |
---|---|---|
@@ -1 +1,42 @@ | ||
return <h1>Dashboard</h1>; | ||
const { Portfolio } = VM.require( | ||
"${REPL_TREASURY}/widget/pages.dashboard.Portfolio" | ||
) || { Portfolio: () => <></> }; | ||
|
||
const treasuryAccount = "${REPL_TREASURY}"; | ||
const { TransactionHistory } = VM.require( | ||
"${REPL_TREASURY}/widget/pages.dashboard.TransactionHistory" | ||
) || { TransactionHistory: () => <></> }; | ||
|
||
const Wrapper = styled.div` | ||
min-height: 80vh; | ||
.flex-1 { | ||
flex: 1; | ||
} | ||
.text-sm { | ||
font-size: 12px; | ||
} | ||
.page-header { | ||
color: var(--page-header-color); | ||
} | ||
.border-bottom { | ||
border-bottom: 1px solid rgba(226, 230, 236, 1); | ||
} | ||
`; | ||
|
||
return ( | ||
<Wrapper className="d-flex flex-column gap-3"> | ||
<div className="d-flex justify-content-between gap-2 mt-3"> | ||
<h4 className="page-header mb-0 fw-bold">Dashboard</h4> | ||
<div className="bg-black text-white p-1 px-2 h6 rounded-2"> | ||
{treasuryAccount} | ||
</div> | ||
</div> | ||
<div className="d-flex gap-2"> | ||
<Portfolio /> | ||
<TransactionHistory /> | ||
</div> | ||
</Wrapper> | ||
); |