Skip to content

Commit

Permalink
fix: generalize payment token
Browse files Browse the repository at this point in the history
  • Loading branch information
X committed May 20, 2024
1 parent 766345e commit f97d728
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/backend/order_book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,6 @@ fn adjust_pools(
// S4: we could infer this from the order.trade_type.
trade_type: OrderType,
) -> Result<(), String> {

// S4: assert that trade_type != order.trade_type.

let (payment_receiver, token_receiver) = if trade_type.buy() {
Expand Down
6 changes: 3 additions & 3 deletions src/backend/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn logs() {
struct BackenData {
volume_day: u128,
trades_day: u64,
icp_locked: u128,
payment_token_locked: u128,
e8s_per_xdr: u64,
fee: u128,
cycle_balance: u64,
Expand All @@ -81,7 +81,7 @@ fn data() {
BackenData {
volume_day: day_orders.clone().map(|order| order.volume()).sum(),
trades_day: day_orders.count() as u64,
icp_locked: state
payment_token_locked: state
.funds_under_management()
.iter()
.find_map(|(id, balance)| (&PAYMENT_TOKEN_ID.to_string() == id).then_some(balance))
Expand All @@ -91,7 +91,7 @@ fn data() {
fee: TX_FEE,
cycle_balance: canister_balance(),
heap_size: heap_address().1,
// We subtract one, because the list of tokens always contains the ICP token
// We subtract one, because the list of tokens always contains the payment token
tokens_listed: state.tokens.len() - 1,
active_traders: state.traders(),
}
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Token } from "./token";
import { ApiGenerator, Backend } from "./api";
import { Principal } from "@dfinity/principal";
import { Listing } from "./listing";
import { PAYMENT_TOKEN_ID } from "./common";

const parseHash = (): string[] => {
const parts = window.location.hash.replace("#", "").split("/");
Expand All @@ -20,7 +21,7 @@ type Data = {
fee: bigint;
volume_day: bigint;
trades_day: number;
icp_locked: bigint;
payment_token_locked: bigint;
cycle_balance: number;
heap_size: number;
tokens_listed: number;
Expand Down Expand Up @@ -53,10 +54,7 @@ const App = () => {
content = <Logs />;
} else if (param == "list") {
content = <Listing tokenId={param2} />;
} else if (
typeof param == "string" &&
param != "ryjl3-tyaaa-aaaaa-aaaba-cai"
) {
} else if (typeof param == "string" && param != PAYMENT_TOKEN_ID) {
content = <Token tokenId={param} />;
}
if (content)
Expand Down
8 changes: 6 additions & 2 deletions src/frontend/src/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Landing = ({}) => {
}, []);
const paymentToken = window.tokenData[PAYMENT_TOKEN_ID];
const {
icp_locked,
payment_token_locked,
trades_day,
volume_day,
fee,
Expand Down Expand Up @@ -68,7 +68,11 @@ export const Landing = ({}) => {
<div className="dbcell">
<span>{paymentToken.symbol} LOCKED</span>
<code>
{token(icp_locked, paymentToken.decimals, false)}{" "}
{token(
payment_token_locked,
paymentToken.decimals,
false,
)}{" "}
</code>
</div>
<div className="dbcell">
Expand Down

0 comments on commit f97d728

Please sign in to comment.