Skip to content

Commit

Permalink
feat: Integrate phantom connection and account derivation - round 2 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tian000 authored Aug 20, 2024
1 parent 0f886fd commit 3cc087a
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 90 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"@scure/bip32": "^1.3.0",
"@scure/bip39": "^1.2.0",
"@skip-router/core": "^5.1.0",
"@solana/web3.js": "^1.93.0",
"@statsig/js-client": "1.4.0",
"@statsig/react-bindings": "1.4.0",
"@tanstack/react-query": "^5.37.1",
Expand All @@ -117,6 +118,7 @@
"crypto-js": "^4.1.1",
"ethers": "^6.6.1",
"export-to-csv": "^1.2.3",
"fast-json-stable-stringify": "^2.1.0",
"graz": "^0.0.43",
"jsdom": "^24.1.0",
"lodash": "^4.17.21",
Expand Down
42 changes: 23 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/constants/account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { DydxAddress, EvmAddress } from './wallets';
import { SolAddress } from './wallets';

export enum OnboardingSteps {
ChooseWallet = 'ChooseWallet',
Expand Down Expand Up @@ -43,6 +44,16 @@ export type EvmDerivedAddresses = {
};
};

export type SolDerivedAddresses = {
version?: string;
} & Record<
SolAddress,
{
encryptedSignature?: string;
dydxAddress?: DydxAddress;
}
>;

export type Hdkey = {
mnemonic: string;
privateKey: Uint8Array | null;
Expand Down
3 changes: 3 additions & 0 deletions src/constants/localStorage.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export enum LocalStorageKey {
// Onboarding / Accounts
EvmAddress = 'dydx.EvmAddress',
SolAddress = 'dydx.SolAddress',
DydxAddress = 'dydx.DydxAddress',
OnboardingSelectedWalletType = 'dydx.OnboardingSelectedWalletType',
WalletConnectionType = 'dydx.WalletConnectionType',
OnboardingHasAcknowledgedTerms = 'dydx.OnboardingHasAcknowledgedTerms',
EvmDerivedAddresses = 'dydx.EvmDerivedAddresses',
SolDerivedAddresses = 'dydx.SolDerivedAddresses',

// Gas
SelectedGasDenom = 'dydx.SelectedGasDenom',
Expand Down Expand Up @@ -39,6 +41,7 @@ export enum LocalStorageKey {

export const LOCAL_STORAGE_VERSIONS = {
[LocalStorageKey.EvmDerivedAddresses]: 'v2',
[LocalStorageKey.SolDerivedAddresses]: 'v1',
[LocalStorageKey.NotificationPreferences]: 'v2',
[LocalStorageKey.TransferNotifications]: 'v1',
[LocalStorageKey.Notifications]: 'v1',
Expand Down
13 changes: 13 additions & 0 deletions src/constants/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
MathWalletIcon,
MetaMaskIcon,
OkxWalletIcon,
PhantomIcon,
RainbowIcon,
TokenPocketIcon,
TrustWalletIcon,
Expand All @@ -36,6 +37,7 @@ export enum WalletConnectionType {
InjectedEip1193 = 'injectedEip1193',
WalletConnect2 = 'walletConnect2',
TestWallet = 'TestWallet',
Phantom = 'Phantom',
}

export enum WalletErrorType {
Expand Down Expand Up @@ -69,6 +71,9 @@ export const walletConnectionTypes: Record<WalletConnectionType, WalletConnectio
name: 'WalletConnect 2.0',
wagmiConnectorId: 'walletConnect',
},
[WalletConnectionType.Phantom]: {
name: 'Phantom',
},
[WalletConnectionType.CosmosSigner]: {
name: 'CosmosSigner',
},
Expand Down Expand Up @@ -102,6 +107,7 @@ export enum WalletType {
TestWallet = 'TEST_WALLET',
OtherWallet = 'OTHER_WALLET',
Privy = 'PRIVY',
Phantom = 'PHANTOM',
}

const WALLET_CONNECT_EXPLORER_RECOMMENDED_WALLETS = {
Expand Down Expand Up @@ -277,6 +283,12 @@ export const wallets: Record<WalletType, WalletConfig> = {
icon: EmailIcon,
connectionTypes: [WalletConnectionType.Privy],
},
[WalletType.Phantom]: {
type: WalletType.Phantom,
stringKey: STRING_KEYS.PHANTOM,
icon: PhantomIcon,
connectionTypes: [WalletConnectionType.Phantom],
},
};

// Injected EIP-1193 Providers
Expand Down Expand Up @@ -332,6 +344,7 @@ export const getSignTypedData = (selectedDydxChainId: DydxChainId) =>
export type PrivateInformation = ReturnType<typeof onboarding.deriveHDKeyFromEthereumSignature>;

export type EvmAddress = `0x${string}`;
export type SolAddress = `${string}`;
export type DydxAddress = `dydx${string}`;

export const DYDX_CHAIN_INFO: Parameters<typeof suggestChain>[0] = {
Expand Down
Loading

0 comments on commit 3cc087a

Please sign in to comment.