Skip to content

Commit

Permalink
feat(app): add support for mnemonic wallet
Browse files Browse the repository at this point in the history
The mnemonic wallet should only be used for testing.
  • Loading branch information
No-Cash-7970 committed Oct 1, 2024
1 parent 4ff1427 commit db4ca6b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 8 deletions.
12 changes: 11 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,15 @@ NEXT_PUBLIC_WC_PROJECT_ID=
# If the API key is not set, Magic support will not be enabled.
NEXT_PUBLIC_MAGIC_API_KEY=

# Feature flags
##### Feature flags #####

# Language switcher
NEXT_PUBLIC_FEAT_LANG_SWITCHER=true

# Mnemonic wallet - Entering a mnemonic instead of using a wallet
NEXT_PUBLIC_FEAT_MNEMONIC_WALLET=false
# Persist mnemonic wallet to local storage. If not "true", the user will be asked repeatedly for the
# mnemonic every time they need to connect to a wallet or sign a transaction. If "true", the user is
# asked for the mnemonic once because the mnemonic is dangerously stored in local storage in plain
# text. This is ignored if NEXT_PUBLIC_FEAT_MNEMONIC_WALLET is not "true".
NEXT_PUBLIC_FEAT_MNEMONIC_WALLET_PERSIST=false
12 changes: 11 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,15 @@ NEXT_PUBLIC_WC_PROJECT_ID=
# If the API key is not set, Magic support will not be enabled.
NEXT_PUBLIC_MAGIC_API_KEY=

# Feature flags
##### Feature flags #####

# Language switcher
NEXT_PUBLIC_FEAT_LANG_SWITCHER=true

# Mnemonic wallet - Entering a mnemonic instead of using a wallet
NEXT_PUBLIC_FEAT_MNEMONIC_WALLET=true
# Persist mnemonic wallet to local storage. If not "true", the user will be asked repeatedly for the
# mnemonic every time they need to connect to a wallet or sign a transaction. If "true", the user is
# asked for the mnemonic once because the mnemonic is dangerously stored in local storage in plain
# text. This is ignored if NEXT_PUBLIC_FEAT_MNEMONIC_WALLET is not "true".
NEXT_PUBLIC_FEAT_MNEMONIC_WALLET_PERSIST=true
12 changes: 11 additions & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,15 @@ NEXT_PUBLIC_WC_PROJECT_ID=
# If the API key is not set, Magic support will not be enabled.
NEXT_PUBLIC_MAGIC_API_KEY=

# Feature flags
##### Feature flags #####

# Language switcher
NEXT_PUBLIC_FEAT_LANG_SWITCHER=true

# Mnemonic wallet - Entering a mnemonic instead of using a wallet
NEXT_PUBLIC_FEAT_MNEMONIC_WALLET=false
# Persist mnemonic wallet to local storage. If not "true", the user will be asked repeatedly for the
# mnemonic every time they need to connect to a wallet or sign a transaction. If "true", the user is
# asked for the mnemonic once because the mnemonic is dangerously stored in local storage in plain
# text. This is ignored if NEXT_PUBLIC_FEAT_MNEMONIC_WALLET is not "true".
NEXT_PUBLIC_FEAT_MNEMONIC_WALLET_PERSIST=false
12 changes: 11 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,15 @@ NEXT_PUBLIC_WC_PROJECT_ID=
# If the API key is not set, Magic support will not be enabled.
NEXT_PUBLIC_MAGIC_API_KEY=

# Feature flags
##### Feature flags #####

# Language switcher
NEXT_PUBLIC_FEAT_LANG_SWITCHER=true

# Mnemonic wallet - Entering a mnemonic instead of using a wallet
NEXT_PUBLIC_FEAT_MNEMONIC_WALLET=false
# Persist mnemonic wallet to local storage. If not "true", the user will be asked repeatedly for the
# mnemonic every time they need to connect to a wallet or sign a transaction. If "true", the user is
# asked for the mnemonic once because the mnemonic is dangerously stored in local storage in plain
# text. This is ignored if NEXT_PUBLIC_FEAT_MNEMONIC_WALLET is not "true".
NEXT_PUBLIC_FEAT_MNEMONIC_WALLET_PERSIST=false
12 changes: 11 additions & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,15 @@ NEXT_PUBLIC_WC_PROJECT_ID=
# If the API key is not set, Magic support will not be enabled.
NEXT_PUBLIC_MAGIC_API_KEY=

# Feature flags
##### Feature flags #####

# Language switcher
NEXT_PUBLIC_FEAT_LANG_SWITCHER=true

# Mnemonic wallet - Entering a mnemonic instead of using a wallet
NEXT_PUBLIC_FEAT_MNEMONIC_WALLET=true
# Persist mnemonic wallet to local storage. If not "true", the user will be asked repeatedly for the
# mnemonic every time they need to connect to a wallet or sign a transaction. If "true", the user is
# asked for the mnemonic once because the mnemonic is dangerously stored in local storage in plain
# text. This is ignored if NEXT_PUBLIC_FEAT_MNEMONIC_WALLET is not "true".
NEXT_PUBLIC_FEAT_MNEMONIC_WALLET_PERSIST=true
22 changes: 19 additions & 3 deletions src/app/[lang]/components/wallet/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type SupportedWallets,
} from '@txnlab/use-wallet-react';
import { useAtomValue } from 'jotai';
import { nodeConfigAtom } from '@/app/lib/node-config';
import { MAINNET, nodeConfigAtom } from '@/app/lib/node-config';

/** Wrapper for initializing the use-wallet library. Also serves as a provider to convert the
* use-wallet wallet provider to a client component so it can be used in server components with
Expand Down Expand Up @@ -58,7 +58,24 @@ export default function WalletProvider({ sitename, children }: {
});
/*
* Wallets list is now:
* Pera, Defly, Lute, WalletConnect, Kibisis, Magic, Exodus, KMD
* Pera, Defly, Lute, WalletConnect?, Kibisis, Magic, Exodus, KMD
*/
}

// TODO: Disable for Voi MainNet too
// Add mnemonic as a supported wallet if it is enabled in the environment variables
// AND the network is not MainNet
if (process.env.NEXT_PUBLIC_FEAT_MNEMONIC_WALLET === 'true'
&& nodeConfig.network !== MAINNET
) {
// Insert mnemonic wallet at the end of the list of supported wallets
supportedWallets.push({
id: WalletId.MNEMONIC,
options: { persistToStorage: process.env.NEXT_PUBLIC_FEAT_MNEMONIC_WALLET_PERSIST === 'true'}
});
/*
* Wallets list is now:
* Pera, Defly, Lute, WalletConnect?, Kibisis, Magic?, Exodus, KMD, Mnemonic
*/
}

Expand All @@ -69,7 +86,6 @@ export default function WalletProvider({ sitename, children }: {
baseServer: nodeConfig.nodeServer,
port: nodeConfig.nodePort,
headers: nodeConfig.nodeHeaders,

},
options: {
// Setting `debug` to `true` same as setting `logLevel` to `LogLevel.DEBUG`
Expand Down
2 changes: 2 additions & 0 deletions src/app/i18n/locales/en/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ wallet:
kibisis: Kibisis
walletconnect: WalletConnect
magic: Magic
mnemonic: Mnemonic
type:
mobile: Mobile wallet
mobile_web: Mobile & web wallet
Expand All @@ -80,6 +81,7 @@ wallet:
cli_sandbox: CLI wallet for Sandbox
protocol: Wallet connection protocol
waas: Wallet-as-a-service
mnemonic: Dangerously enter the mnemonic
magic_prompt:
fail: Failed to authenticate using Magic.
heading: Magic
Expand Down
2 changes: 2 additions & 0 deletions src/app/i18n/locales/es/app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ wallet:
kibisis: Kibisis
walletconnect: WalletConnect
magic: Magic
mnemonic: Mnemonic
type:
mobile: Billetera móvil
mobile_web: Billetera móvil y web
Expand All @@ -85,6 +86,7 @@ wallet:
cli_sandbox: Billetera CLI para Sandbox
protocol: Protocolo para conectarse a una billetera
waas: Billetera como servicio
mnemonic: Peligrosamente entrar la mnemotecnia
magic_prompt:
fail: Error al autenticar usando Magic.
heading: Magic
Expand Down
1 change: 1 addition & 0 deletions src/app/lib/wallet-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const walletTypes: {[id: string]: string} = {
[WalletId.KIBISIS]: 'browser_extension',
[WalletId.WALLETCONNECT]: 'protocol',
[WalletId.MAGIC]: 'waas',
[WalletId.MNEMONIC]: 'mnemonic',
};

/** Validation atom that contains the Magic email address */
Expand Down

0 comments on commit db4ca6b

Please sign in to comment.