Skip to content

Commit

Permalink
Merge pull request #31 from SimpleHold/fix-generate-wallets
Browse files Browse the repository at this point in the history
Fix generate wallets
  • Loading branch information
lukas-ss authored Sep 28, 2021
2 parents 0a01dcd + 8ffbe86 commit de8048b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 70 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "extension",
"version": "1.13.4",
"version": "1.13.5",
"description": "extension",
"private": false,
"repository": "https://github.com/SimpleHold/extension.git",
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "SimpleHold",
"version": "1.13.4",
"version": "1.13.5",
"icons": {
"16": "assets/logo/favicon-16.png",
"32": "assets/logo/favicon-32.png",
Expand Down
92 changes: 37 additions & 55 deletions src/pages/NewWallet/NewWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import { validatePassword } from '@utils/validate'
import { decrypt } from '@utils/crypto'
import { addNew as addNewWallet, IWallet } from '@utils/wallet'
import { toUpper } from '@utils/format'
import {
generate,
importPrivateKey,
importRecoveryPhrase,
checkWithPhrase,
} from '@utils/currencies'
import { generate, checkWithPhrase } from '@utils/currencies'
import * as theta from '@utils/currencies/theta'
import { getItem, setItem } from '@utils/storage'

Expand Down Expand Up @@ -100,62 +95,49 @@ const NewWallet: React.FC = () => {
const generateAddress = await generate(symbol, chain)

if (generateAddress) {
const { privateKey, mnemonic, isNotActivated } = generateAddress
const { privateKey, mnemonic, isNotActivated, address } = generateAddress

const backup = getItem('backup')

if (backup && privateKey) {
const decryptBackup = decrypt(backup, state.password)

if (decryptBackup) {
let address

if (mnemonic) {
const tryImportPhrase = importRecoveryPhrase(symbol, mnemonic)
if (tryImportPhrase) {
address = tryImportPhrase.address
}
} else {
address = await importPrivateKey(symbol, privateKey, chain)
}

if (address || isNotActivated) {
updateState({ isButtonLoading: false })

const getCurrencyInfo = chain ? getCurrencyByChain(chain) : null
const currenciesList = getCurrenciesList(getCurrencyInfo)

const walletsList = addNewWallet(
address || '',
privateKey,
decryptBackup,
state.password,
currenciesList,
false,
chain,
tokenName,
contractAddress,
decimals,
mnemonic,
isNotActivated
)

if (walletsList) {
const walletAmount = JSON.parse(walletsList).filter(
(wallet: IWallet) => wallet.symbol === symbol
).length

setUserProperties({ [`NUMBER_WALLET_${toUpper(symbol)}`]: `${walletAmount}` })

logEvent({
name: ADD_ADDRESS_CONFIRM,
})

setItem('backupStatus', 'notDownloaded')

updateState({ activeDrawer: 'success' })
return
}
updateState({ isButtonLoading: false })

const getCurrencyInfo = chain ? getCurrencyByChain(chain) : null
const currenciesList = getCurrenciesList(getCurrencyInfo)

const walletsList = addNewWallet(
address,
privateKey,
decryptBackup,
state.password,
currenciesList,
false,
chain,
tokenName,
contractAddress,
decimals,
mnemonic,
isNotActivated
)

if (walletsList) {
const walletAmount = JSON.parse(walletsList).filter(
(wallet: IWallet) => wallet.symbol === symbol
).length

setUserProperties({ [`NUMBER_WALLET_${toUpper(symbol)}`]: `${walletAmount}` })

logEvent({
name: ADD_ADDRESS_CONFIRM,
})

setItem('backupStatus', 'notDownloaded')

updateState({ activeDrawer: 'success' })
return
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/utils/currencies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ export const generate = async (
symbol: string,
chain?: string
): Promise<TGenerateAddress | null> => {
if (isEthereumLike(symbol, chain)) {
return ethereumLike.generateAddress()
}

const provider = getProvider(symbol)

if (provider?.generateWallet) {
return await provider.generateWallet()
}

if (isEthereumLike(symbol, chain)) {
return ethereumLike.generateAddress()
}

return bitcoinLike.generateWallet(symbol)
}

Expand Down Expand Up @@ -324,16 +324,16 @@ export const getExplorerLink = (
tokenChain?: string,
contractAddress?: string
) => {
if (isEthereumLike(symbol, tokenChain)) {
return ethereumLike.getExplorerLink(address, symbol, tokenChain, contractAddress)
}

const provider = getProvider(symbol)

if (provider?.getExplorerLink) {
return provider.getExplorerLink(address)
}

if (isEthereumLike(symbol, tokenChain)) {
return ethereumLike.getExplorerLink(address, symbol, tokenChain, contractAddress)
}

return `https://blockchair.com/${chain}/address/${address}`
}

Expand All @@ -343,17 +343,17 @@ export const getTransactionLink = (
chain: string,
tokenChain?: string
): string => {
if (isEthereumLike(symbol, tokenChain)) {
return ethereumLike.getTransactionLink(hash, chain, tokenChain)
}

const provider = getProvider(symbol)

if (provider?.getTransactionLink) {
return provider.getTransactionLink(hash)
}

if (isEthereumLike(symbol, tokenChain)) {
return ethereumLike.getTransactionLink(hash, chain, tokenChain)
} else {
return `https://blockchair.com/${chain}/transaction/${hash}`
}
return `https://blockchair.com/${chain}/transaction/${hash}`
}

export const getNetworkFeeSymbol = (symbol: string, tokenChain?: string): string => {
Expand Down

0 comments on commit de8048b

Please sign in to comment.