From 314dd6ac0d9c74f2b65813f26992037c28339bf8 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Sun, 26 Jan 2025 10:09:34 +0100 Subject: [PATCH] fixes --- src/frontend/src/api.ts | 9 +- src/frontend/src/common.tsx | 19 ++++ src/frontend/src/icrc1-tokens-wallet.tsx | 110 ++++++++--------------- src/frontend/src/post.tsx | 2 +- src/frontend/src/style.css | 23 ----- src/frontend/src/util.ts | 20 ----- src/frontend/src/wallet.tsx | 3 +- 7 files changed, 63 insertions(+), 123 deletions(-) delete mode 100644 src/frontend/src/util.ts diff --git a/src/frontend/src/api.ts b/src/frontend/src/api.ts index 25a05857..4e257435 100644 --- a/src/frontend/src/api.ts +++ b/src/frontend/src/api.ts @@ -122,16 +122,18 @@ export const ApiGenerator = ( console.error(err); }); - const icrc_canisters: Map = new Map(); + const agentCache: Map = new Map(); const getIcrcCanister = (canisterId: string) => { - const canisterAgent = icrc_canisters.get(canisterId); + const canisterAgent = agentCache.get(canisterId); if (canisterAgent) { return canisterAgent; } - return IcrcLedgerCanister.create({ + const canister = IcrcLedgerCanister.create({ canisterId: Principal.from(canisterId), agent, }); + agentCache.set(canisterId, canister); + return canister; }; const query_raw = async ( @@ -509,7 +511,6 @@ export const ApiGenerator = ( icrc_metadata: async (canisterId: string) => { try { const canister = getIcrcCanister(canisterId); - // console.log(canister.metadata) const meta = await canister.metadata({ certified: false, }); diff --git a/src/frontend/src/common.tsx b/src/frontend/src/common.tsx index 940a46d8..162a069a 100644 --- a/src/frontend/src/common.tsx +++ b/src/frontend/src/common.tsx @@ -1120,3 +1120,22 @@ export const SeedPhraseForm = ({ export const restartApp = async () => { location.reload(); }; + +export function bucket_image_url( + bucket_id: string, + offset: number, + len: number, +) { + // Fall back to the mainnet if the local config doesn't contain the bucket. + let fallback_to_mainnet = !window.backendCache.stats?.buckets?.find( + ([id, _y]) => id == bucket_id, + ); + let host = + MAINNET_MODE || fallback_to_mainnet + ? `https://${bucket_id}.raw.icp0.io` + : `http://127.0.0.1:8080`; + return ( + `${host}/image?offset=${offset}&len=${len}` + + (MAINNET_MODE ? "" : `&canisterId=${bucket_id}`) + ); +} diff --git a/src/frontend/src/icrc1-tokens-wallet.tsx b/src/frontend/src/icrc1-tokens-wallet.tsx index 4142afb9..5fd3e94b 100644 --- a/src/frontend/src/icrc1-tokens-wallet.tsx +++ b/src/frontend/src/icrc1-tokens-wallet.tsx @@ -1,8 +1,7 @@ import * as React from "react"; -import { ButtonWithLoading, CopyToClipboard } from "./common"; +import { ButtonWithLoading, bucket_image_url } from "./common"; import { Principal } from "@dfinity/principal"; import { Icrc1Canister } from "./types"; -import { bucket_image_url } from "./util"; import { Repost } from "./icons"; export const Icrc1TokensWallet = () => { @@ -140,86 +139,51 @@ export const Icrc1TokensWallet = () => { return ( <> -
+
+

ICRC1 TOKENS

loadIcrc1CanisterBalances(undefined, true)} - label={"Refresh balances"} + label={} >
{icrc1Canisters.length > 0 && ( - - - {icrc1Canisters.map(([canisterId, info]) => ( - - - - - - - - - - - ))} - -
{info.symbol} - - - - {canisterId} - - - - loadIcrc1CanisterBalances( - canisterId, - true, - ) - } - label={} - > - - - icrcTransferPrompts( - canisterId, - info, - ) - } - label={"Send"} - > - - {`${(+canisterBalances[canisterId] / Math.pow(10, info.decimals))?.toFixed(info.decimals)}`} - - `Receive`} - > -
+
+ {icrc1Canisters.map(([canisterId, info]) => ( +
+ + {info.symbol} +
+ + {( + Number(canisterBalances[canisterId]) / + Math.pow(10, info.decimals) + )?.toFixed(info.decimals)} + + + icrcTransferPrompts(canisterId, info) + } + label={"Send"} + > +
+ ))} +
)} ); diff --git a/src/frontend/src/post.tsx b/src/frontend/src/post.tsx index a0ce7cf8..84fd1a80 100644 --- a/src/frontend/src/post.tsx +++ b/src/frontend/src/post.tsx @@ -22,6 +22,7 @@ import { FlagButton, ReportBanner, tokens, + bucket_image_url, currentRealm, parseNumber, noiseControlBanner, @@ -45,7 +46,6 @@ import { import { ProposalView } from "./proposals"; import { Feature, Post, PostId, Realm, UserId } from "./types"; import { UserLink, UserList, populateUserNameCache } from "./user_resolve"; -import { bucket_image_url } from "./util"; export const PostView = ({ id, diff --git a/src/frontend/src/style.css b/src/frontend/src/style.css index 4f19fa8d..b3b49cf0 100644 --- a/src/frontend/src/style.css +++ b/src/frontend/src/style.css @@ -1139,10 +1139,6 @@ label svg { .prime h1 { font-size: 200%; } - - .hide-mobile { - display: none; - } } .bottom_spaced { @@ -1171,22 +1167,3 @@ div.thumbnails { margin-top: 0.4em; padding: 0.1em 0 0.1em 0; } - -.icrc1-canisters { - display: table; - width: 100%; - margin: 0; -} - -.icrc1-canisters td { - padding: 0 0.25rem 0.125rem 0; - white-space: nowrap; -} -.icrc1-canisters td:last-of-type { - padding: 0; -} - -.icrc1-canisters button.send { - padding-top: 0.4em; - padding-bottom: 0.4em; -} diff --git a/src/frontend/src/util.ts b/src/frontend/src/util.ts deleted file mode 100644 index 3446cf50..00000000 --- a/src/frontend/src/util.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { MAINNET_MODE } from "./env"; - -export function bucket_image_url( - bucket_id: string, - offset: number, - len: number, -) { - // Fall back to the mainnet if the local config doesn't contain the bucket. - let fallback_to_mainnet = !window.backendCache.stats?.buckets?.find( - ([id, _y]) => id == bucket_id, - ); - let host = - MAINNET_MODE || fallback_to_mainnet - ? `https://${bucket_id}.raw.icp0.io` - : `http://127.0.0.1:8080`; - return ( - `${host}/image?offset=${offset}&len=${len}` + - (MAINNET_MODE ? "" : `&canisterId=${bucket_id}`) - ); -} diff --git a/src/frontend/src/wallet.tsx b/src/frontend/src/wallet.tsx index 0c18d707..0052263d 100644 --- a/src/frontend/src/wallet.tsx +++ b/src/frontend/src/wallet.tsx @@ -311,8 +311,7 @@ export const Wallet = () => {
)}
-

ICRC1 Tokens

- + ); };