Skip to content

Commit

Permalink
[ECO-2185] Fix emoji input bug on mobile and registration bug (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
CRBl69 authored Oct 7, 2024
1 parent 4ba57a9 commit e333481
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const EmojiPickerWithInput = ({
const setPickerInvisible = useEmojiPicker((s) => s.setPickerInvisible);
const nativePicker = useEmojiPicker((s) => s.nativePicker);
const insertEmojiTextInput = useEmojiPicker((s) => s.insertEmojiTextInput);
const setEmojis = useEmojiPicker((s) => s.setEmojis);
const removeEmojiTextInput = useEmojiPicker((s) => s.removeEmojiTextInput);
const textAreaRef = useEmojiPicker((s) => s.textAreaRef);

Expand Down Expand Up @@ -143,7 +144,7 @@ export const EmojiPickerWithInput = ({
[removeEmojiTextInput, textAreaRef]
);

const onKeyDownHandler = async (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
const onKeyUpHandler = async (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
const target = e.target as HTMLTextAreaElement;
if (!target) return;
// I use this so much while developing that I need to account for it.
Expand All @@ -153,10 +154,10 @@ export const EmojiPickerWithInput = ({
e.stopPropagation();
window.location.reload();
}
if (getEmojisInString(e.key).length) {
if (getEmojisInString(e.currentTarget.value).length) {
e.preventDefault();
e.stopPropagation();
insertEmojiTextInput(e.key);
setEmojis(getEmojisInString(e.currentTarget.value));
} else if (e.key === "Enter") {
e.preventDefault();
await handleSubmission(emojis.join(""));
Expand Down Expand Up @@ -217,7 +218,7 @@ export const EmojiPickerWithInput = ({
onPaste={handlePaste}
onCut={handleCut}
inputMode={nativePicker ? "text" : "none"}
onKeyDown={onKeyDownHandler}
onKeyUp={onKeyUpHandler}
onFocus={(e) => {
// Stop the focus from bubbling up to the `Flex` component above. We only want to focus
// this specific text area without triggering a focus on the `Flex` component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ import { useEmojiPicker } from "context/emoji-picker-context";
import { SYMBOL_DATA } from "@sdk/emoji_data";
import { useNumMarkets } from "lib/hooks/queries/use-num-markets";
import { useQuery } from "@tanstack/react-query";
import { type AccountInfo } from "@aptos-labs/wallet-adapter-core";

const tryEd25519PublicKey = (account: AccountInfo) => {
try {
return new Ed25519PublicKey(
typeof account.publicKey === "string" ? account.publicKey : account.publicKey[0]
);
} catch (_) {
return undefined;
}
};

export const useRegisterMarket = () => {
const emojis = useEmojiPicker((state) => state.emojis);
Expand All @@ -36,9 +47,16 @@ export const useRegisterMarket = () => {
if (account === null) {
return undefined;
}
const publicKey = new Ed25519PublicKey(
typeof account!.publicKey === "string" ? account.publicKey : account.publicKey[0]
);
const publicKey = tryEd25519PublicKey(account);
if (!publicKey) {
return {
error: true,
data: {
amount: 0,
unitPrice: 0,
},
};
}
try {
const r = await RegisterMarket.getGasCost({
aptosConfig: aptos.config,
Expand Down
2 changes: 1 addition & 1 deletion src/typescript/sdk/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const QUOTE_VIRTUAL_CEILING = 140_000_000_000n;
export const POOL_FEE_RATE_BPS = 25;
export const MARKET_REGISTRATION_FEE = ONE_APT_BIGINT;
export const MARKET_REGISTRATION_DEPOSIT = 4n * ONE_APT_BIGINT;
export const MARKET_REGISTRATION_GAS_ESTIMATION_NOT_FIRST = 6000;
export const MARKET_REGISTRATION_GAS_ESTIMATION_NOT_FIRST = ONE_APT * 0.005;
export const MARKET_REGISTRATION_GAS_ESTIMATION_FIRST = ONE_APT * 0.6;

/// As defined in the database, aka the enum string.
Expand Down

0 comments on commit e333481

Please sign in to comment.