Skip to content

Commit

Permalink
[ECO-2241] Attempt to fix wallet adapter issues with a version bump a…
Browse files Browse the repository at this point in the history
…nd config update (#279)
  • Loading branch information
xbtmatt authored Oct 3, 2024
1 parent 3e61d93 commit 0b197af
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 152 deletions.
6 changes: 3 additions & 3 deletions src/typescript/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
]
},
"dependencies": {
"@aptos-labs/ts-sdk": "1.22.2",
"@aptos-labs/wallet-adapter-react": "3.4.3",
"@aptos-labs/ts-sdk": "1.27.1",
"@aptos-labs/wallet-adapter-core": "^4.17.0",
"@aptos-labs/wallet-adapter-react": "3.7.0",
"@econia-labs/emojicoin-sdk": "workspace:*",
"@emoji-mart/data": "https://github.com/econia-labs/emoji-mart/raw/emojicoin-dot-fun/packages/emoji-mart-data/emoji-mart-data-v1.2.1.tgz",
"@emoji-mart/react": "https://github.com/econia-labs/emoji-mart/raw/emojicoin-dot-fun/packages/emoji-mart-react/emoji-mart-react-v1.1.1.tgz",
Expand All @@ -40,7 +41,6 @@
"lodash": "^4.17.21",
"lucide-react": "^0.400.0",
"next": "^14.2.4",
"petra-plugin-wallet-adapter": "^0.4.5",
"react": "^18.3.1",
"react-confetti": "^6.1.0",
"react-device-detect": "^2.2.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// cspell:word emojicoindotfun

import { UNIT_OF_TIME_MULTIPLIERS, UnitOfTime } from "@sdk/utils/misc";

// One week.
export const COOKIE_LENGTH = 1000 * 60 * 60 * 24 * 7;
export const COOKIE_FOR_HASHED_ADDRESS = "emojicoindotfun-account-hashed-address";
export const COOKIE_FOR_ACCOUNT_ADDRESS = "emojicoindotfun-account-address";
export const COOKIE_LENGTH = UNIT_OF_TIME_MULTIPLIERS[UnitOfTime.Weeks] * 1;
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
"use server";
import { sha3_256 } from "@noble/hashes/sha3";
import { normalizeHex } from "@sdk/utils";
import { HASH_SEED } from "lib/server-env";

export const hashAddress = async (address: string) => {
// Ensure the HASH_SEED is valid, since we don't import it.
if (!process.env.HASH_SEED || process.env.HASH_SEED.length < 8) {
throw new Error("Environment variable HASH_SEED must be set and at least 8 characters.");
}
const HASH_SEED = process.env.HASH_SEED;
// Use `process.env.HASH_SEED` here to avoid polluting the namespace with @aptos-labs/ts-sdk`
// imports that import functions that aren't supported in the Edge Runtime middleware.
const buffer = Buffer.from(`${address}::${HASH_SEED}`, "utf-8");
const hash = sha3_256(new Uint8Array(buffer));
return normalizeHex(hash);
Expand Down
16 changes: 2 additions & 14 deletions src/typescript/frontend/src/context/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,7 @@ const ThemedApp: React.FC<{ children: React.ReactNode; geoblocked: boolean }> =

const isMobileMenuOpen = isOpen && !isDesktop;

const wallets = useMemo(
() => [
new PontemWallet(),
new RiseWallet(),
new MartianWallet(),
// new AptosConnectWalletPlugin({ network: APTOS_NETWORK }),
],
[]
);
// TODO: Make fetch queries here and pass the data to the event store..?
// It's possible we can also pass a promise down from the server components
// to the clients and then add those to the store as they stream in.
const wallets = useMemo(() => [new PontemWallet(), new RiseWallet(), new MartianWallet()], []);

const queryClient = new QueryClient();

Expand All @@ -63,8 +52,7 @@ const ThemedApp: React.FC<{ children: React.ReactNode; geoblocked: boolean }> =
<UserSettingsProvider>
<AptosWalletAdapterProvider
plugins={wallets}
autoConnect={true}
optInWallets={["Petra"]}
autoConnect={false}
dappConfig={{ network: APTOS_NETWORK }}
>
<WalletModalContextProvider>
Expand Down
7 changes: 4 additions & 3 deletions src/typescript/frontend/src/lib/server-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ if (typeof process.env.REVALIDATION_TIME === "undefined") {
if (process.env.NODE) throw new Error("Environment variable REVALIDATION_TIME is undefined.");
}

if (typeof process.env.HASH_SEED === "undefined") {
throw new Error("Environment variable HASH_SEED is undefined.");
// We don't export `HASH_SEED` here since it would pollute the Edge Runtime namespace with
// incompatible node.js functions. Instead, just verify that it is valid.
if (!process.env.HASH_SEED || process.env.HASH_SEED.length < 8) {
throw new Error("Environment variable HASH_SEED must be set and at least 8 characters.");
}

if (
Expand Down Expand Up @@ -39,7 +41,6 @@ if (GEOBLOCKING_ENABLED) {
export const ALLOWLISTER3K_URL: string | undefined = process.env.ALLOWLISTER3K_URL;
export const GALXE_CAMPAIGN_ID: string | undefined = process.env.GALXE_CAMPAIGN_ID;
export const REVALIDATION_TIME: number = Number(process.env.REVALIDATION_TIME);
export const HASH_SEED: string = process.env.HASH_SEED;
export const VPNAPI_IO_API_KEY: string = process.env.VPNAPI_IO_API_KEY!;

if (APTOS_NETWORK === Network.LOCAL && !EMOJICOIN_INDEXER_URL.includes("localhost")) {
Expand Down
1 change: 0 additions & 1 deletion src/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {
"@aptos-labs/ts-sdk": "1.22.2",
"@types/node": "^20.14.9"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 0b197af

Please sign in to comment.