From d81aa050c0b0cec1a4340f29ef0357bc074e0310 Mon Sep 17 00:00:00 2001 From: Matt <90358481+xbtmatt@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:11:52 -0700 Subject: [PATCH] [ECO-2209] Make insufficient balance for market registration clearer (#263) Co-authored-by: matt --- .../hooks/use-is-market-registered.ts | 2 +- .../hooks/use-register-market.ts | 24 ++++++++++++------- .../components/launch-or-goto.tsx | 2 +- .../memoized-launch/index.tsx | 10 ++++++-- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/typescript/frontend/src/components/pages/launch-emojicoin/hooks/use-is-market-registered.ts b/src/typescript/frontend/src/components/pages/launch-emojicoin/hooks/use-is-market-registered.ts index c1aecc148..8b8c30ff7 100644 --- a/src/typescript/frontend/src/components/pages/launch-emojicoin/hooks/use-is-market-registered.ts +++ b/src/typescript/frontend/src/components/pages/launch-emojicoin/hooks/use-is-market-registered.ts @@ -21,7 +21,7 @@ export const useIsMarketRegistered = () => { const length = sumBytes(emojis); const invalidLength = length === 0 || length > 10; // If not all of the emojis are in the symbol data map, then it can't have been registered. - if (!emojis.some((e) => SYMBOL_DATA.byEmoji(e))) { + if (!emojis.every(SYMBOL_DATA.byEmoji)) { return { invalid: true, registered: false, diff --git a/src/typescript/frontend/src/components/pages/launch-emojicoin/hooks/use-register-market.ts b/src/typescript/frontend/src/components/pages/launch-emojicoin/hooks/use-register-market.ts index 1d3365212..466d521ba 100644 --- a/src/typescript/frontend/src/components/pages/launch-emojicoin/hooks/use-register-market.ts +++ b/src/typescript/frontend/src/components/pages/launch-emojicoin/hooks/use-register-market.ts @@ -33,16 +33,24 @@ export const useRegisterMarket = () => { const { data: gasResult } = useQuery({ queryKey: ["register-market-cost", numMarkets, account?.address, emojiBytes], queryFn: async () => { + if (account === null) { + return undefined; + } const publicKey = new Ed25519PublicKey( - typeof account!.publicKey === "string" ? account!.publicKey : account!.publicKey[0] + typeof account!.publicKey === "string" ? account.publicKey : account.publicKey[0] ); - const r = await RegisterMarket.getGasCost({ - aptosConfig: aptos.config, - registrant: account!.address, - registrantPubKey: publicKey, - emojis: numMarkets === 0 ? [SYMBOL_DATA.byName("Virgo")!.bytes] : emojiBytes, - }); - return r; + try { + const r = await RegisterMarket.getGasCost({ + aptosConfig: aptos.config, + registrant: account.address, + registrantPubKey: publicKey, + emojis: numMarkets === 0 ? [SYMBOL_DATA.byName("Virgo")!.bytes] : emojiBytes, + }); + return r; + } catch (e) { + console.error(e); + return undefined; + } }, staleTime: 1000, enabled: diff --git a/src/typescript/frontend/src/components/pages/launch-emojicoin/memoized-launch/components/launch-or-goto.tsx b/src/typescript/frontend/src/components/pages/launch-emojicoin/memoized-launch/components/launch-or-goto.tsx index 016e44fac..10848f948 100644 --- a/src/typescript/frontend/src/components/pages/launch-emojicoin/memoized-launch/components/launch-or-goto.tsx +++ b/src/typescript/frontend/src/components/pages/launch-emojicoin/memoized-launch/components/launch-or-goto.tsx @@ -45,7 +45,7 @@ export const LaunchButtonOrGoToMarketLink = ({ style={{ cursor: invalid ? "not-allowed" : "pointer" }} scrambleProps={scrambleProps} > - {t("Launch Emojicoin")} + {t(invalid ? "Invalid input" : "Launch Emojicoin")} )} diff --git a/src/typescript/frontend/src/components/pages/launch-emojicoin/memoized-launch/index.tsx b/src/typescript/frontend/src/components/pages/launch-emojicoin/memoized-launch/index.tsx index 9810741fb..58c6418be 100644 --- a/src/typescript/frontend/src/components/pages/launch-emojicoin/memoized-launch/index.tsx +++ b/src/typescript/frontend/src/components/pages/launch-emojicoin/memoized-launch/index.tsx @@ -137,7 +137,13 @@ export const MemoizedLaunchAnimation = ({
- {t("Your balance")} +
+ {t("Your balance")} +
+ {t("Your balance")} +
{sufficientBalance ? "✅" : "❌"}
+
+
{ registerMarket();