From 2f43e8da59e5e800c53ce0d20345d6477ac2a087 Mon Sep 17 00:00:00 2001
From: Tomek Marciniak <16132011+mrcnk@users.noreply.github.com>
Date: Wed, 6 Nov 2024 14:33:00 +0100
Subject: [PATCH] chore(web connector): unify sendable schema with klesia
(#220)
* chore(web connector): unify sendable schema with klesia
* feat(web connector): add mina_switchChain
---
.github/workflows/apps-extension-ci.yml | 4 +-
.github/workflows/apps-extension-e2e.yml | 4 +-
.github/workflows/packages-ui-ci.yml | 2 +-
apps/extension/e2e/provider-enable.spec.ts | 133 -
apps/extension/package.json | 2 +-
.../src/background/handlers/wallet.ts | 16 +-
.../src/background/handlers/web-provider.ts | 25 +-
apps/extension/src/background/index.ts | 4 +-
package.json | 4 +-
packages/features/package.json | 3 +-
.../features/src/common/hooks/use-account.ts | 8 +-
.../src/common/hooks/use-transaction.ts | 7 +-
.../src/common/hooks/use-transactions.ts | 6 +-
.../src/components/address-dropdown.tsx | 2 +-
packages/features/src/components/menu-bar.tsx | 6 +-
.../features/src/components/menu-drawer.tsx | 4 +-
.../src/components/settings-page-layout.tsx | 4 +-
.../src/error-renderer/views/error.tsx | 3 -
.../routes/seed-backup-confirmation.tsx | 5 +-
.../src/onboarding/routes/seed-import.tsx | 5 +-
packages/features/src/router.tsx | 156 +-
.../send/components/transaction-result.tsx | 4 +-
.../hooks/use-transaction-confirmation.tsx | 18 +-
packages/features/src/send/routes/send.tsx | 6 +-
packages/features/src/send/views/send.tsx | 6 +-
packages/features/src/typings.d.ts | 2 +-
.../features/src/wallet/routes/networks.tsx | 8 +-
.../features/src/wallet/views/networks.tsx | 21 +-
packages/key-management/README.md | 3 +-
packages/key-management/package.json | 4 -
packages/key-management/src/KeyAgentBase.ts | 11 -
.../key-management/src/SessionKeyAgentBase.ts | 10 -
.../chains/Ethereum/credentialDerivation.ts | 91 -
.../src/chains/Ethereum/guards.ts | 19 -
.../src/chains/Ethereum/index.ts | 3 -
.../src/chains/Ethereum/keyDerivation.ts | 22 -
.../src/chains/Ethereum/keyDerivationUtils.ts | 8 -
.../src/chains/Ethereum/signingOperations.ts | 62 -
.../src/chains/Ethereum/types.ts | 98 -
.../key-management/src/chains/Mina/guards.ts | 4 +-
packages/key-management/src/chains/index.ts | 1 -
packages/key-management/src/types.ts | 49 +-
.../ethereum/credential-derivation.test.ts | 181 -
.../test/ethereum/in-memory-key-agent.test.ts | 206 -
.../test/ethereum/key-agent-base.test.ts | 201 -
.../pallad-core/src/Pallad/providers/types.ts | 6 -
packages/providers/src/index.ts | 1 -
.../account-info/account-info-provider.ts | 68 -
.../src/optimism/account-info/index.ts | 1 -
.../chain-history/chain-history-provider.ts | 67 -
.../src/optimism/chain-history/index.ts | 1 -
packages/providers/src/optimism/index.ts | 4 -
.../src/optimism/node-status/index.ts | 1 -
.../node-status/node-status-provider.ts | 30 -
.../src/optimism/utils/health-check-utils.ts | 32 -
.../providers/src/optimism/utils/index.ts | 1 -
.../chain-history-provider.ts | 5 +-
.../providers/src/unified-providers/types.ts | 7 +-
.../account-info-provider.test.ts | 40 -
.../chain-history-provider.test.ts | 49 -
.../account-info-provider.test.ts | 2 +-
.../chain-history-provider.test.ts | 4 +-
.../unified-provider.test.ts | 4 +-
packages/vault/package.json | 3 +-
packages/vault/src/account/accountState.ts | 2 +-
packages/vault/src/account/accountStore.ts | 24 +-
packages/vault/src/network-info/README.md | 82 +-
packages/vault/src/network-info/default.ts | 38 +-
.../src/network-info/network-info-state.ts | 20 +-
.../src/network-info/network-info-store.ts | 71 +-
packages/vault/src/token-info/default.ts | 6 +-
.../vault/src/token-info/token-info-state.ts | 10 +-
.../vault/src/token-info/token-info-store.ts | 22 +-
packages/vault/src/vault/README.md | 132 +-
.../src/vault/utils/get-current-wallet.ts | 2 +-
.../vault/utils/get-wallet-account-info.ts | 8 +-
.../vault/utils/get-wallet-transactions.ts | 5 +-
.../vault/src/vault/utils/restart-wallet.ts | 8 +-
.../vault/src/vault/utils/restore-wallet.ts | 8 +-
.../vault/src/vault/utils/switch-network.ts | 18 +-
.../src/vault/utils/sync-account-info.ts | 4 +-
.../src/vault/utils/sync-transactions.ts | 2 +-
packages/vault/src/vault/utils/sync-wallet.ts | 14 +-
packages/vault/src/vault/vaultState.ts | 13 +-
packages/vault/src/vault/vaultStore.ts | 45 +-
.../network-info/network-info-store.test.ts | 191 -
packages/vault/test/wallet/walletFlow.test.ts | 16 +-
packages/vault/tsconfig.json | 2 +-
packages/web-provider/package.json | 6 +-
.../src/mina-network/constants/index.ts | 1 -
.../src/mina-network/constants/rpc.ts | 22 -
.../web-provider/src/mina-network/index.ts | 1 -
.../src/mina-network/mina-provider.ts | 31 +-
.../web-provider/src/vault-service/types.ts | 21 +-
.../src/vault-service/vault-service.ts | 119 +-
pnpm-lock.yaml | 4269 ++++++++---------
96 files changed, 2309 insertions(+), 4671 deletions(-)
delete mode 100644 apps/extension/e2e/provider-enable.spec.ts
delete mode 100644 packages/key-management/src/chains/Ethereum/credentialDerivation.ts
delete mode 100644 packages/key-management/src/chains/Ethereum/guards.ts
delete mode 100644 packages/key-management/src/chains/Ethereum/index.ts
delete mode 100644 packages/key-management/src/chains/Ethereum/keyDerivation.ts
delete mode 100644 packages/key-management/src/chains/Ethereum/keyDerivationUtils.ts
delete mode 100644 packages/key-management/src/chains/Ethereum/signingOperations.ts
delete mode 100644 packages/key-management/src/chains/Ethereum/types.ts
delete mode 100644 packages/key-management/test/ethereum/credential-derivation.test.ts
delete mode 100644 packages/key-management/test/ethereum/in-memory-key-agent.test.ts
delete mode 100644 packages/key-management/test/ethereum/key-agent-base.test.ts
delete mode 100644 packages/providers/src/optimism/account-info/account-info-provider.ts
delete mode 100644 packages/providers/src/optimism/account-info/index.ts
delete mode 100644 packages/providers/src/optimism/chain-history/chain-history-provider.ts
delete mode 100644 packages/providers/src/optimism/chain-history/index.ts
delete mode 100644 packages/providers/src/optimism/index.ts
delete mode 100644 packages/providers/src/optimism/node-status/index.ts
delete mode 100644 packages/providers/src/optimism/node-status/node-status-provider.ts
delete mode 100644 packages/providers/src/optimism/utils/health-check-utils.ts
delete mode 100644 packages/providers/src/optimism/utils/index.ts
delete mode 100644 packages/providers/test/optimism/account-info/account-info-provider.test.ts
delete mode 100644 packages/providers/test/optimism/chain-history/chain-history-provider.test.ts
delete mode 100644 packages/vault/test/network-info/network-info-store.test.ts
delete mode 100644 packages/web-provider/src/mina-network/constants/index.ts
delete mode 100644 packages/web-provider/src/mina-network/constants/rpc.ts
diff --git a/.github/workflows/apps-extension-ci.yml b/.github/workflows/apps-extension-ci.yml
index b11ccd0a..9ca8a595 100644
--- a/.github/workflows/apps-extension-ci.yml
+++ b/.github/workflows/apps-extension-ci.yml
@@ -34,7 +34,7 @@ jobs:
test_and_build:
name: "Build and test"
env:
- VITE_APP_DEFAULT_NETWORK: Mainnet
+ VITE_APP_DEFAULT_NETWORK_ID: mina:mainnet
NODE_OPTIONS: "--max_old_space_size=4096"
runs-on: ubuntu-latest
steps:
@@ -51,7 +51,7 @@ jobs:
TURBO_API: "http://127.0.0.1:9080"
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: pallad
- run: VITE_APP_DEFAULT_NETWORK=$VITE_APP_DEFAULT_NETWORK pnpm build:extension
+ run: VITE_APP_DEFAULT_NETWORK_ID=$VITE_APP_DEFAULT_NETWORK_ID pnpm build:extension
- name: Run unit tests
run: pnpm test:unit
- uses: actions/upload-artifact@v4
diff --git a/.github/workflows/apps-extension-e2e.yml b/.github/workflows/apps-extension-e2e.yml
index b257203c..66651da5 100644
--- a/.github/workflows/apps-extension-e2e.yml
+++ b/.github/workflows/apps-extension-e2e.yml
@@ -10,7 +10,7 @@ jobs:
name: Run E2E tests
env:
VITE_APP_E2E: true
- VITE_APP_DEFAULT_NETWORK: Devnet
+ VITE_APP_DEFAULT_NETWORK_ID: mina:devnet
NODE_OPTIONS: "--max_old_space_size=4096"
runs-on: ubuntu-latest
steps:
@@ -25,7 +25,7 @@ jobs:
TURBO_API: "http://127.0.0.1:9080"
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: pallad
- run: VITE_APP_E2E=$VITE_APP_E2E VITE_APP_DEFAULT_NETWORK=$VITE_APP_DEFAULT_NETWORK pnpm build:extension
+ run: VITE_APP_E2E=$VITE_APP_E2E VITE_APP_DEFAULT_NETWORK_ID=$VITE_APP_DEFAULT_NETWORK_ID pnpm build:extension
- name: Install Chromium for Playwright
working-directory: apps/extension
run: pnpm test:e2e:install
diff --git a/.github/workflows/packages-ui-ci.yml b/.github/workflows/packages-ui-ci.yml
index 6548ad74..8942a3b0 100644
--- a/.github/workflows/packages-ui-ci.yml
+++ b/.github/workflows/packages-ui-ci.yml
@@ -20,7 +20,7 @@ jobs:
pages: write
id-token: write
env:
- VITE_APP_DEFAULT_NETWORK: Devnet
+ VITE_APP_DEFAULT_NETWORK_ID: mina:devnet
steps:
- uses: actions/checkout@v4
- name: Setup Pages
diff --git a/apps/extension/e2e/provider-enable.spec.ts b/apps/extension/e2e/provider-enable.spec.ts
deleted file mode 100644
index 325f1a09..00000000
--- a/apps/extension/e2e/provider-enable.spec.ts
+++ /dev/null
@@ -1,133 +0,0 @@
-import { expect, test } from "./extension"
-import { OnboardingPom } from "./pom/onboarding"
-
-const VALIDATOR = "B62qjsV6WQwTeEWrNrRRBP6VaaLvQhwWTnFi4WP4LQjGvpfZEumXzxb"
-
-// Note: These tests are manual
-test.skip("enable window.mina and handle pop-up on a specific webpage", async ({
- page,
- extensionId,
-}) => {
- // Restore the wallet or perform any setup required by your extension before interacting with the webpage.
- const onboardingPom = new OnboardingPom({ page, extensionId })
- await onboardingPom.restoreTestWallet()
-
- // Navigate to the webpage where the injected script should be interacted with.
- await page.goto("https://google.com")
-
- // Verify that window.mina is available
- const minaExists = await page.evaluate(() => window.mina !== undefined)
- expect(minaExists).toBe(true)
-
- // Trigger window.mina.enable() which should open the pop-up
- //const enableResponse = await page.evaluate(() => window.mina.enable())
- /**
- Click "Yes" manually
- */
- //expect(enableResponse.result.length).toBe(1)
- //expect(enableResponse.result[0]).toBe(VALIDATOR)
-
- const account = await page.evaluate(() =>
- window.mina.request({ method: "mina_accounts" }),
- )
- expect(account.result.length).toBe(1)
- expect(account.result[0]).toBe(VALIDATOR)
-
- const responseChainId = await page.evaluate(() =>
- window.mina.request({ method: "mina_chainId" }),
- )
- expect(responseChainId.result).not.toBe("...")
-
- const responseBalance = await page.evaluate(() =>
- window.mina.request({ method: "mina_getBalance" }),
- )
- expect(responseBalance.result).not.toBe(undefined)
-
- const responseRequestNetwork = await page.evaluate(() =>
- window.mina.request({ method: "mina_requestNetwork" }),
- )
- expect(responseRequestNetwork.result.chainId).not.toBe(undefined)
-
- const responseAddChain = await page.evaluate(() =>
- window.mina.request({
- method: "mina_addChain",
- params: {
- nodeEndpoint: {
- providerName: "mina-node",
- url: "https://devnet.zeko.io/graphql",
- },
- archiveNodeEndpoint: {
- providerName: "mina-node",
- url: "",
- },
- networkName: "ZekoDevNet",
- networkType: "testnet",
- chainId: "69420",
- },
- }),
- )
- expect(responseAddChain.result.networkName).toBe("ZekoDevNet")
-
- const responseSwitchChain = await page.evaluate(() =>
- window.mina.request({
- method: "mina_switchChain",
- params: {
- chainId: "69420",
- },
- }),
- )
- expect(responseSwitchChain.result.networkName).toBe("ZekoDevNet")
-
- const responseBalanceZeko = await page.evaluate(() =>
- window.mina.request({ method: "mina_getBalance" }),
- )
- expect(responseBalanceZeko.result).not.toBe(0)
-
- await page.evaluate(() =>
- window.mina.request({
- method: "mina_setState",
- params: {
- objectName: "New Example Credential",
- object: {
- "@context": ["https://www.w3.org/2018/credentials/v1"],
- id: "http://example.edu/credentials/3732",
- type: ["VerifiableCredential", "UniversityDegreeCredential"],
- issuer: "University of Example",
- issuanceDate: "2010-01-01T00:00:00Z",
- credentialSubject: {
- id: "did:mina:B62qjsV6WQwTeEWrNrRRBP6VaaLvQhwWTnFi4WP4LQjGvpfZEumXzxb",
- degree: {
- type: "BachelorDegree",
- name: "Bachelor of Science and Arts",
- },
- },
- proof: {
- type: "Kimchi",
- created: "2023-09-19T12:40:16Z",
- proof: {
- publicInput: ["0"],
- publicOutput: ["1"],
- maxProofsVerified: 0,
- proof: "KChzdGF0ZW1...SkpKSkp",
- },
- },
- },
- },
- }),
- )
- /**
- Enter password manually
- */
-
- const responseGetState = await page.evaluate(() =>
- window.mina.request({
- method: "mina_getState",
- params: { query: { issuer: "University of Example" }, props: [] },
- }),
- )
- /**
- Enter password manually
- */
-
- expect(responseGetState.result.length).toBe(2)
-})
diff --git a/apps/extension/package.json b/apps/extension/package.json
index cfc0deea..472ab75b 100644
--- a/apps/extension/package.json
+++ b/apps/extension/package.json
@@ -15,7 +15,7 @@
"test:e2e:ui": "playwright test --ui"
},
"dependencies": {
- "@mina-js/providers": "https://pkg.pr.new/palladians/mina-js/@mina-js/providers@7fe60e8",
+ "@mina-js/providers": "https://pkg.pr.new/palladians/mina-js/@mina-js/providers@a51d3b4",
"@palladxyz/common": "workspace:*",
"@palladxyz/features": "workspace:*",
"@palladxyz/key-management": "workspace:*",
diff --git a/apps/extension/src/background/handlers/wallet.ts b/apps/extension/src/background/handlers/wallet.ts
index b0a3e082..cc4ec202 100644
--- a/apps/extension/src/background/handlers/wallet.ts
+++ b/apps/extension/src/background/handlers/wallet.ts
@@ -1,5 +1,5 @@
import { useVault } from "@palladxyz/vault"
-import type { NetworkName } from "@palladxyz/vault"
+import type { NetworkId } from "@palladxyz/vault"
import { createMinaProvider } from "@palladxyz/web-provider"
import { serializeError } from "serialize-error"
import type { Handler } from "./"
@@ -14,14 +14,14 @@ export const palladSwitchNetwork: Handler = async ({ data }) => {
try {
const provider = await createMinaProvider()
await useVault.persist.rehydrate()
- const { switchNetwork, getChainId } = useVault.getState()
- const network = data.network as NetworkName
+ const { switchNetwork, getNetworkId } = useVault.getState()
+ const network = data.networkId as NetworkId
await switchNetwork(network)
await useVault.persist.rehydrate()
- const chainId = getChainId()
+ const networkId = getNetworkId()
provider.emit("pallad_event", {
data: {
- chainId: chainId,
+ networkId,
},
type: "chainChanged",
})
@@ -34,11 +34,11 @@ export const palladConnected: Handler = async () => {
try {
const provider = await createMinaProvider()
await useVault.persist.rehydrate()
- const { getChainId } = useVault.getState()
- const chainId = getChainId()
+ const { getNetworkId } = useVault.getState()
+ const networkId = getNetworkId()
provider.emit("pallad_event", {
data: {
- chainId: chainId,
+ networkId,
},
type: "connect",
})
diff --git a/apps/extension/src/background/handlers/web-provider.ts b/apps/extension/src/background/handlers/web-provider.ts
index 06e71669..74109615 100644
--- a/apps/extension/src/background/handlers/web-provider.ts
+++ b/apps/extension/src/background/handlers/web-provider.ts
@@ -1,21 +1,22 @@
import {
AccountsRequestParamsSchema,
- ChainIdRequestParamsSchema,
ChainInformationRequestParamsSchema,
CreateNullifierRequestParamsSchema,
GetBalanceRequestParamsSchema,
GetStateRequestParamsSchema,
+ NetworkIdRequestParamsSchema,
RequestAccountsRequestParamsSchema,
SendTransactionRequestParamsSchema,
SetStateRequestParamsSchema,
SignFieldsRequestParamsSchema,
SignRequestParamsSchema,
SignTransactionRequestParamsSchema,
+ SwitchChainRequestParamsSchema,
} from "@mina-js/providers"
+import { createMinaProvider } from "@palladxyz/web-provider"
import { serializeError } from "serialize-error"
import { z } from "zod"
import type { Handler } from "."
-import { createMinaProvider } from "../../../../../packages/web-provider/src"
export const OriginSchema = z.string().url()
@@ -50,8 +51,18 @@ export const minaRequestNetwork: Handler = async ({ data }) => {
}
}
-export const minaSwitchChain = async () => {
- return { error: serializeError(new Error("4200 - Unsupported Method")) }
+export const minaSwitchChain: Handler = async ({ data }) => {
+ try {
+ const provider = await createMinaProvider()
+ const payload = SwitchChainRequestParamsSchema.parse({
+ method: "mina_switchChain",
+ params: data.params,
+ context: data.context,
+ })
+ return await provider.request(payload)
+ } catch (error: unknown) {
+ return { error: serializeError(error) }
+ }
}
export const minaGetState: Handler = async ({ data }) => {
@@ -68,11 +79,11 @@ export const minaGetState: Handler = async ({ data }) => {
}
}
-export const minaChainId: Handler = async ({ data }) => {
+export const minaNetworkId: Handler = async ({ data }) => {
try {
const provider = await createMinaProvider()
- const payload = ChainIdRequestParamsSchema.parse({
- method: "mina_chainId",
+ const payload = NetworkIdRequestParamsSchema.parse({
+ method: "mina_networkId",
context: data.context,
})
return await provider.request(payload)
diff --git a/apps/extension/src/background/index.ts b/apps/extension/src/background/index.ts
index 7d57059b..3d2f7768 100644
--- a/apps/extension/src/background/index.ts
+++ b/apps/extension/src/background/index.ts
@@ -4,10 +4,10 @@ import { runtime, tabs } from "webextension-polyfill"
import {
minaAccounts,
minaAddChain,
- minaChainId,
minaCreateNullifier,
minaGetBalance,
minaGetState,
+ minaNetworkId,
minaRequestAccounts,
minaRequestNetwork,
minaSendTransaction,
@@ -31,7 +31,7 @@ onMessage("mina_addChain", minaAddChain)
onMessage("mina_requestNetwork", minaRequestNetwork)
onMessage("mina_switchChain", minaSwitchChain)
onMessage("mina_getState", minaGetState)
-onMessage("mina_chainId", minaChainId)
+onMessage("mina_networkId", minaNetworkId)
onMessage("mina_accounts", minaAccounts)
onMessage("mina_requestAccounts", minaRequestAccounts)
onMessage("mina_sign", minaSign)
diff --git a/package.json b/package.json
index cdd0d25e..52b8a382 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
"format": "pnpm biome check --write .",
"format:unsafe": "pnpm biome check --write --unsafe .",
"f": "pnpm format",
- "cleanup": "turbo run cleanup && rimraf node_modules",
+ "cleanup": "turbo run cleanup && rimraf node_modules .turbo",
"prepare": "husky install",
"preinstall": "npx only-allow pnpm"
},
@@ -28,7 +28,7 @@
"@tsconfig/strictest": "2.0.5",
"@turbo/gen": "2.0.9",
"@vitest/coverage-v8": "2.0.5",
- "@mina-js/utils": "https://pkg.pr.new/palladians/mina-js/@mina-js/utils@7fe60e8",
+ "@mina-js/utils": "https://pkg.pr.new/palladians/mina-js/@mina-js/utils@a51d3b4",
"autoprefixer": "10.4.19",
"happy-dom": "14.12.3",
"husky": "9.1.4",
diff --git a/packages/features/package.json b/packages/features/package.json
index 5585d5ee..56da3725 100644
--- a/packages/features/package.json
+++ b/packages/features/package.json
@@ -43,7 +43,7 @@
"@palladxyz/pallad-core": "workspace:*",
"@palladxyz/vault": "workspace:*",
"@total-typescript/ts-reset": "0.5.1",
- "@zxcvbn-ts/core": "^3.0.4",
+ "@zxcvbn-ts/core": "3.0.4",
"array-shuffle": "3.0.0",
"class-variance-authority": "0.7.0",
"clsx": "2.1.1",
@@ -62,7 +62,6 @@
"react-dom": "18.3.1",
"react-error-boundary": "4.0.13",
"react-hook-form": "7.52.1",
- "react-mixpanel-browser": "4.1.0",
"react-qr-code": "2.0.15",
"react-router": "6.25.1",
"react-router-dom": "6.25.1",
diff --git a/packages/features/src/common/hooks/use-account.ts b/packages/features/src/common/hooks/use-account.ts
index 523a0ac4..41e3949b 100644
--- a/packages/features/src/common/hooks/use-account.ts
+++ b/packages/features/src/common/hooks/use-account.ts
@@ -11,7 +11,7 @@ import { useAppStore } from "../store/app"
export const useAccount = () => {
const navigate = useNavigate()
const currentWallet = useVault((state) => state.getCurrentWallet())
- const currentNetworkName = useVault((state) => state.currentNetworkName)
+ const currentNetworkId = useVault((state) => state.currentNetworkId)
const getAccountsInfo = useVault((state) => state.getAccountsInfo)
const restartWallet = useVault((state) => state.restartWallet)
const _syncWallet = useVault((state) => state._syncWallet)
@@ -20,7 +20,7 @@ export const useAccount = () => {
)
const fetchWallet = async () => {
await _syncWallet()
- const accountInfo = getAccountsInfo(currentNetworkName, publicKey)
+ const accountInfo = getAccountsInfo(currentNetworkId, publicKey)
const chain = currentWallet.credential.credential?.chain
const props = getAccountProperties(
accountInfo.accountInfo,
@@ -30,7 +30,7 @@ export const useAccount = () => {
}
const publicKey = getPublicKey(currentWallet)
const swr = useSWR(
- publicKey ? [publicKey, "account", currentNetworkName] : null,
+ publicKey ? [publicKey, "account", currentNetworkId] : null,
async () => await fetchWallet(),
{
refreshInterval: 30000,
@@ -73,7 +73,7 @@ export const useAccount = () => {
publicKey,
lockWallet,
restartCurrentWallet,
- network: currentNetworkName,
+ networkId: currentNetworkId,
stakeDelegated,
}
}
diff --git a/packages/features/src/common/hooks/use-transaction.ts b/packages/features/src/common/hooks/use-transaction.ts
index 37beae7d..97357511 100644
--- a/packages/features/src/common/hooks/use-transaction.ts
+++ b/packages/features/src/common/hooks/use-transaction.ts
@@ -7,13 +7,14 @@ export const useTransaction = ({ hash }: { hash: string }) => {
const _syncTransactions = useVault((state) => state._syncTransactions)
const getTransaction = useVault((state) => state.getTransaction)
const publicKey = getPublicKey(currentWallet)
- const currentNetworkName = useVault((state) => state.currentNetworkName)
+ const networkId = useVault((state) => state.currentNetworkId)
const syncAndGetTransaction = async () => {
+ if (!providerConfig) return
await _syncTransactions(providerConfig, publicKey)
- return getTransaction(currentNetworkName, publicKey, hash, "MINA") // TODO: remove hardcoded 'MINA'
+ return getTransaction(networkId, publicKey, hash, "MINA") // TODO: remove hardcoded 'MINA'
}
return useSWR(
- publicKey ? ["transaction", hash, currentNetworkName] : null,
+ publicKey ? ["transaction", hash, networkId] : null,
async () => await syncAndGetTransaction(),
)
}
diff --git a/packages/features/src/common/hooks/use-transactions.ts b/packages/features/src/common/hooks/use-transactions.ts
index fdae52d5..74e0d188 100644
--- a/packages/features/src/common/hooks/use-transactions.ts
+++ b/packages/features/src/common/hooks/use-transactions.ts
@@ -5,9 +5,9 @@ export const useTransactions = () => {
const currentWallet = useVault((state) => state.getCurrentWallet())
const getTransactions = useVault((state) => state.getTransactions)
const publicKey = getPublicKey(currentWallet)
- const currentNetworkName = useVault((state) => state.currentNetworkName)
+ const networkId = useVault((state) => state.currentNetworkId)
return useSWR(
- publicKey ? [publicKey, "transactions", currentNetworkName] : null,
- () => getTransactions(currentNetworkName, publicKey, "MINA"), // TODO: remove hardcoded 'MINA'
+ publicKey ? [publicKey, "transactions", networkId] : null,
+ () => getTransactions(networkId, publicKey, "MINA"), // TODO: remove hardcoded 'MINA'
)
}
diff --git a/packages/features/src/components/address-dropdown.tsx b/packages/features/src/components/address-dropdown.tsx
index 51d2074d..1817a022 100644
--- a/packages/features/src/components/address-dropdown.tsx
+++ b/packages/features/src/components/address-dropdown.tsx
@@ -28,7 +28,7 @@ export const AddressDropdown = ({
toast.success("Address Copied")
}
const openInExplorer = () => {
- const url = currentNetworkInfo.explorer.accountUrl.replace(
+ const url = currentNetworkInfo?.explorer.accountUrl.replace(
"{publicKey}",
publicKey,
)
diff --git a/packages/features/src/components/menu-bar.tsx b/packages/features/src/components/menu-bar.tsx
index 14fe966d..f6dc1037 100644
--- a/packages/features/src/components/menu-bar.tsx
+++ b/packages/features/src/components/menu-bar.tsx
@@ -45,7 +45,7 @@ type MenuBarProps = {
onNetworkClicked?: () => void
networkManagement?: boolean
publicAddress?: string
- currentNetwork?: string
+ networkId?: string
}
export const MenuBar = ({
@@ -55,7 +55,7 @@ export const MenuBar = ({
onNetworkClicked,
networkManagement = false,
publicAddress,
- currentNetwork,
+ networkId,
}: MenuBarProps) => {
const navigate = useNavigate()
const goHome = () => navigate("/dashboard")
@@ -93,7 +93,7 @@ export const MenuBar = ({
className="flex flex-col btn min-h-10 h-10"
onClick={onNetworkClicked}
>
-
{currentNetwork}
+ {networkId}
{networkManagement ? (
) : (
diff --git a/packages/features/src/components/menu-drawer.tsx b/packages/features/src/components/menu-drawer.tsx
index cd46e031..343d3d85 100644
--- a/packages/features/src/components/menu-drawer.tsx
+++ b/packages/features/src/components/menu-drawer.tsx
@@ -6,7 +6,7 @@ import { Link, useNavigate } from "react-router-dom"
export const MenuDrawer = () => {
const navigate = useNavigate()
- const currentNetworkName = useVault((state) => state.currentNetworkName)
+ const networkId = useVault((state) => state.currentNetworkId)
return (
@@ -45,7 +45,7 @@ export const MenuDrawer = () => {
to="/networks"
className="btn btn-primary min-h-10 h-10 bg-white hover:bg-white shadow-none border-none gap-2"
>
- {currentNetworkName}
+ {networkId}
diff --git a/packages/features/src/components/settings-page-layout.tsx b/packages/features/src/components/settings-page-layout.tsx
index 4ab691d0..adf6370f 100644
--- a/packages/features/src/components/settings-page-layout.tsx
+++ b/packages/features/src/components/settings-page-layout.tsx
@@ -15,7 +15,7 @@ export const SettingsPageLayout = ({
onCloseClicked,
headerContent = null,
}: SettingsPageHeaderProps) => {
- const currentNetworkName = useVault((state) => state.currentNetworkName)
+ const networkId = useVault((state) => state.currentNetworkId)
return (
@@ -23,7 +23,7 @@ export const SettingsPageLayout = ({
{title}
diff --git a/packages/features/src/error-renderer/views/error.tsx b/packages/features/src/error-renderer/views/error.tsx
index fe7b6c67..5ff34202 100644
--- a/packages/features/src/error-renderer/views/error.tsx
+++ b/packages/features/src/error-renderer/views/error.tsx
@@ -1,14 +1,11 @@
import type { FallbackProps } from "react-error-boundary"
-import { useMixpanel } from "react-mixpanel-browser"
export const ErrorView = ({ error, resetErrorBoundary }: FallbackProps) => {
- const mixpanel = useMixpanel()
const stringifiedError = JSON.stringify(
error,
Object.getOwnPropertyNames(error),
)
const report = async () => {
- await mixpanel.track("Boundary Error", { error: stringifiedError })
resetErrorBoundary()
}
return (
diff --git a/packages/features/src/onboarding/routes/seed-backup-confirmation.tsx b/packages/features/src/onboarding/routes/seed-backup-confirmation.tsx
index a49f75e5..8470ba0e 100644
--- a/packages/features/src/onboarding/routes/seed-backup-confirmation.tsx
+++ b/packages/features/src/onboarding/routes/seed-backup-confirmation.tsx
@@ -5,7 +5,6 @@ import { sessionPersistence } from "@palladxyz/vault"
import { DEFAULT_NETWORK, KeyAgents, useVault } from "@palladxyz/vault"
import { useMemo, useState } from "react"
import { useForm } from "react-hook-form"
-import { useMixpanel } from "react-mixpanel-browser"
import { useNavigate } from "react-router-dom"
import { useAppStore } from "@/common/store/app"
@@ -18,7 +17,6 @@ const getConfirmationIndex = () => {
}
export const SeedBackupConfirmationRoute = () => {
- const mixpanel = useMixpanel()
const [restoring, setRestoring] = useState(false)
const restoreWallet = useVault((state) => state.restoreWallet)
const [confirmationIndex] = useState(getConfirmationIndex())
@@ -68,8 +66,7 @@ export const SeedBackupConfirmationRoute = () => {
KeyAgents.InMemory,
"Test", // TODO: make this a configurable credential name or random if not provided
)
- mixpanel.track("WalletCreated")
- await setVaultStateInitialized()
+ setVaultStateInitialized()
return navigate("/onboarding/finish")
} finally {
setRestoring(false)
diff --git a/packages/features/src/onboarding/routes/seed-import.tsx b/packages/features/src/onboarding/routes/seed-import.tsx
index 46d17aa6..f8324ce3 100644
--- a/packages/features/src/onboarding/routes/seed-import.tsx
+++ b/packages/features/src/onboarding/routes/seed-import.tsx
@@ -5,7 +5,6 @@ import { sessionPersistence } from "@palladxyz/vault"
import { DEFAULT_NETWORK, KeyAgents, useVault } from "@palladxyz/vault"
import { useState } from "react"
import { type SubmitHandler, useForm } from "react-hook-form"
-import { useMixpanel } from "react-mixpanel-browser"
import { useNavigate } from "react-router-dom"
import { shallow } from "zustand/shallow"
@@ -17,7 +16,6 @@ import type { MnemonicInputData } from "../types"
import { SeedImportView } from "../views/seed-import"
export const SeedImportRoute = () => {
- const mixpanel = useMixpanel()
const [restoring, setRestoring] = useState(false)
const restoreWallet = useVault((state) => state.restoreWallet)
const navigate = useNavigate()
@@ -60,8 +58,7 @@ export const SeedImportRoute = () => {
KeyAgents.InMemory,
"Test", // TODO: make this a configurable credential name or random if not provided
)
- mixpanel.track("WalletRestored")
- await setVaultStateInitialized()
+ setVaultStateInitialized()
return navigate("/onboarding/finish")
} finally {
setRestoring(false)
diff --git a/packages/features/src/router.tsx b/packages/features/src/router.tsx
index 659ff9ef..f98bb0f1 100644
--- a/packages/features/src/router.tsx
+++ b/packages/features/src/router.tsx
@@ -3,11 +3,9 @@ import { MemoryRouter, Outlet, Route, Routes } from "react-router-dom"
import dayjs from "dayjs"
import relativeTime from "dayjs/plugin/relativeTime"
import { ErrorBoundary } from "react-error-boundary"
-import { MixpanelProvider } from "react-mixpanel-browser"
import { Toaster } from "sonner"
import { AddressBookRoute } from "./address-book/routes/address-book"
import { NewAddressRoute } from "./address-book/routes/new-address"
-import { useAppStore } from "./common/store/app"
import { ErrorView } from "./error-renderer/views/error"
import { UnlockWalletRoute } from "./lock/routes/unlock-wallet"
import { NotFoundRoute } from "./not-found/routes/not-found"
@@ -45,96 +43,86 @@ import { OverviewRoute } from "./wallet/routes/overview"
dayjs.extend(relativeTime)
export const Router = () => {
- const shareData = useAppStore((state) => state.shareData)
- const mixpanelConfig = {
- track_pageview: true,
- opt_out_tracking_by_default: shareData ?? false,
- }
return (
-
-
-
-
-
-
- } />
- } />
- } />
- } />
- } />
+
+
+
+
+
+ } />
+ } />
+ } />
+ } />
+ } />
+ }
+ />
+ }
+ />
+ }
+ />
+ }
+ />
+ } />
+ } />
+ } />
+ }
+ />
+ }>
+ } />
+ } />
+
+ }>
+ } />
+ } />
+ } />
}
+ path="backup_security"
+ element={}
/>
+ } />
}
+ path="import_security"
+ element={}
/>
}
+ path="confirmation"
+ element={}
/>
- }
- />
- } />
- } />
- } />
- }
- />
- }>
- } />
- } />
+ } />
+
+ } />
+ }>
+ } />
+ }>
+ } />
+ } />
+ } />
- }>
- } />
- } />
- } />
- }
- />
- } />
- }
- />
- }
- />
- } />
+ }>
+ } />
+ } />
+ } />
- } />
- }>
- } />
- }>
- } />
- } />
- } />
-
- }>
- } />
- } />
- } />
-
- }
- />
- } />
-
- } />
-
-
-
-
-
+ }
+ />
+ } />
+
+ } />
+
+
+
+
)
}
diff --git a/packages/features/src/send/components/transaction-result.tsx b/packages/features/src/send/components/transaction-result.tsx
index 1ab4fdcd..028bddf8 100644
--- a/packages/features/src/send/components/transaction-result.tsx
+++ b/packages/features/src/send/components/transaction-result.tsx
@@ -25,11 +25,11 @@ export const TransactionResult = ({
}: TransactionResultProps) => {
return (
-
+
{title}
-
+
{result.label}
{result.content}
diff --git a/packages/features/src/send/hooks/use-transaction-confirmation.tsx b/packages/features/src/send/hooks/use-transaction-confirmation.tsx
index f29b6736..2e5f8ff6 100644
--- a/packages/features/src/send/hooks/use-transaction-confirmation.tsx
+++ b/packages/features/src/send/hooks/use-transaction-confirmation.tsx
@@ -1,9 +1,8 @@
import type { ChainOperationArgs } from "@palladxyz/key-management"
-import { Mina, TransactionType } from "@palladxyz/mina-core"
+import { TransactionType } from "@palladxyz/mina-core"
import { useVault } from "@palladxyz/vault"
import dayjs from "dayjs"
import type { SubmitHandler, UseFormReturn } from "react-hook-form"
-import { useMixpanel } from "react-mixpanel-browser"
import { useNavigate } from "react-router-dom"
import type { z } from "zod"
@@ -24,13 +23,12 @@ type UseTransactionConfirmationProps = {
export const useTransactionConfirmation = ({
confirmationForm,
}: UseTransactionConfirmationProps) => {
- const mixpanel = useMixpanel()
const navigate = useNavigate()
const sign = useVault((state) => state.sign)
const submitTx = useVault((state) => state.submitTx)
const constructTx = useVault((state) => state.constructTx)
const syncWallet = useVault((state) => state._syncWallet)
- const currentNetworkName = useVault((state) => state.currentNetworkName)
+ const currentNetworkId = useVault((state) => state.currentNetworkId)
const { publicKey, data: accountProperties } = useAccount()
const outgoingTransaction = useTransactionStore(
(state) => state.outgoingTransaction,
@@ -61,7 +59,7 @@ export const useTransactionConfirmation = ({
const operationArgs: ChainOperationArgs = {
operation: "mina_signTransaction",
network: "Mina",
- networkType: currentNetworkName === "Mainnet" ? "mainnet" : "testnet",
+ networkType: currentNetworkId === "mina:mainnet" ? "mainnet" : "testnet",
}
let txBody: TransactionBody
if (type === TransactionType.STAKE_DELEGATION) {
@@ -95,16 +93,6 @@ export const useTransactionConfirmation = ({
expireAt: dayjs().add(8, "hours").toISOString(),
})
await syncWallet()
- mixpanel.track(
- type === Mina.TransactionType.STAKE_DELEGATION
- ? "PortfolioDelegated"
- : "TransactionSent",
- {
- amount: rawTransaction.amount,
- fee: rawTransaction.fee,
- to: type === Mina.TransactionType.STAKE_DELEGATION && rawTransaction.to,
- },
- )
navigate("/transactions/success", {
state: {
hash,
diff --git a/packages/features/src/send/routes/send.tsx b/packages/features/src/send/routes/send.tsx
index b7e67471..d49f32eb 100644
--- a/packages/features/src/send/routes/send.tsx
+++ b/packages/features/src/send/routes/send.tsx
@@ -2,16 +2,14 @@ import { useNavigate } from "react-router-dom"
import { useAccount } from "@/common/hooks/use-account"
import { useFiatPrice } from "@palladxyz/offchain-data"
-import { useVault } from "@palladxyz/vault"
import { useState } from "react"
import { SendView } from "../views/send"
export const SendRoute = () => {
const [advanced, setAdvanced] = useState(false)
const navigate = useNavigate()
- const { data: accountProperties } = useAccount()
+ const { data: accountProperties, networkId } = useAccount()
const { current: rawFiatPrice } = useFiatPrice()
- const currentNetworkName = useVault((state) => state.currentNetworkName)
return (
navigate(-1)}
@@ -19,7 +17,7 @@ export const SendRoute = () => {
fiatPrice={rawFiatPrice}
advanced={advanced}
setAdvanced={setAdvanced}
- currentNetwork={currentNetworkName}
+ networkId={networkId}
/>
)
}
diff --git a/packages/features/src/send/views/send.tsx b/packages/features/src/send/views/send.tsx
index 5fdcb474..43f64680 100644
--- a/packages/features/src/send/views/send.tsx
+++ b/packages/features/src/send/views/send.tsx
@@ -9,7 +9,7 @@ type SendViewProps = {
fiatPrice: number
advanced: boolean
setAdvanced: (advanced: boolean) => void
- currentNetwork: string
+ networkId: string
}
export const SendView = ({
@@ -18,14 +18,14 @@ export const SendView = ({
fiatPrice,
advanced,
setAdvanced,
- currentNetwork,
+ networkId,
}: SendViewProps) => {
return (
{
const navigate = useNavigate()
- const currentNetworkName = useVault((state) => state.currentNetworkName)
+ const networkId = useVault((state) => state.currentNetworkId)
const { fetchWallet } = useAccount()
- const onNetworkSwitch = async (network: string) => {
- await sendMessage("pallad_switchNetwork", { network })
+ const onNetworkSwitch = async (networkId: string) => {
+ await sendMessage("pallad_switchNetwork", { networkId })
await useVault.persist.rehydrate()
await fetchWallet()
navigate("/dashboard")
@@ -18,7 +18,7 @@ export const NetworksRoute = () => {
navigate(-1)}
onNetworkSwitch={onNetworkSwitch}
- currentNetwork={currentNetworkName}
+ networkId={networkId}
/>
)
}
diff --git a/packages/features/src/wallet/views/networks.tsx b/packages/features/src/wallet/views/networks.tsx
index 76216383..6ae40266 100644
--- a/packages/features/src/wallet/views/networks.tsx
+++ b/packages/features/src/wallet/views/networks.tsx
@@ -1,45 +1,38 @@
import MinaIcon from "@/common/assets/mina.svg?react"
-import ZekoIcon from "@/common/assets/zeko.svg?react"
import { MenuBar } from "@/components/menu-bar"
const NETWORKS = [
{
+ id: "mina:mainnet",
icon: MinaIcon,
- value: "Mainnet",
blockchain: "Mina",
network: "Mainnet",
},
{
+ id: "mina:devnet",
icon: MinaIcon,
- value: "Devnet",
blockchain: "Mina",
network: "Devnet",
},
- {
- icon: ZekoIcon,
- value: "ZekoDevNet",
- blockchain: "Zeko",
- network: "Devnet",
- },
]
type NetworksViewProps = {
onCloseClicked: () => void
onNetworkSwitch: (network: string) => Promise
- currentNetwork: string
+ networkId: string
}
export const NetworksView = ({
onCloseClicked,
onNetworkSwitch,
- currentNetwork,
+ networkId,
}: NetworksViewProps) => {
return (
@@ -56,9 +49,9 @@ export const NetworksView = ({
{NETWORKS.map((entry) => (