Skip to content

Commit

Permalink
Merge pull request #49 from SimpleHold/nano_support
Browse files Browse the repository at this point in the history
Nano support
  • Loading branch information
Dylan-Simplehold authored Apr 15, 2022
2 parents f1207be + a739748 commit 305442d
Show file tree
Hide file tree
Showing 30 changed files with 772 additions and 109 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "extension",
"version": "1.21.0",
"version": "1.22.0",
"description": "extension",
"private": false,
"repository": "https://github.com/SimpleHold/extension.git",
Expand Down Expand Up @@ -45,6 +45,7 @@
"detect-browser": "^5.2.0",
"digibyte-lib": "https://github.com/DigiByte-Core/digibyte-lib",
"lodash": "^4.17.21",
"nanocurrency": "^2.5.0",
"neblio-lib": "https://github.com/NeblioTeam/bitcore-lib#neblcore-lib",
"nerve-sdk-js": "^1.0.8",
"nuls-sdk-js": "^2.5.0",
Expand Down
4 changes: 4 additions & 0 deletions src/assets/currencies/xno.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/CurrencyAddress/CurrencyAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CheckBox from '@components/CheckBox'

// Utils
import { short, toUpper } from '@utils/format'
import { getBalance } from '@utils/api'
import { getBalance } from '@utils/currencies'
import { getCurrency } from '@config/currencies'

// Styles
Expand All @@ -33,7 +33,7 @@ const CurrencyAddress: React.FC<Props> = (props) => {
const currency = getCurrency(symbol)

const onGetBalance = async (): Promise<void> => {
const request = await getBalance(address, currency?.chain)
const request = await getBalance(symbol, address, currency?.chain)

setBalance(request.balance)
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/CurrencyLogo/CurrencyLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const CurrencyLogo: React.FC<Props> = (props) => {

const [logo, setLogo] = React.useState<string | null>(null)

const getChainogo = chain ? getCurrencyByChain(chain) : null
const getChainLogo = chain ? getCurrencyByChain(chain) : null
const currency = chain ? getToken(symbol, chain) : getCurrency(symbol)

React.useEffect(() => {
Expand All @@ -47,7 +47,7 @@ const CurrencyLogo: React.FC<Props> = (props) => {
<Styles.LogoRow
width={size}
height={size}
background={background || currency?.background || getChainogo?.background}
background={background || currency?.background || getChainLogo?.background}
br={br}
>
{currency || logo ? (
Expand All @@ -57,9 +57,9 @@ const CurrencyLogo: React.FC<Props> = (props) => {
<Styles.LetterLogo>{toUpper(name[0])}</Styles.LetterLogo>
) : null}
</Styles.LogoRow>
{getChainogo ? (
{getChainLogo ? (
<Styles.TokenRow size={size}>
<Styles.TokenLogo size={size} src={getChainogo.logo} />
<Styles.TokenLogo size={size} src={getChainLogo.logo} />
</Styles.TokenRow>
) : null}
</Styles.Container>
Expand Down
29 changes: 21 additions & 8 deletions src/components/WalletCard/WalletCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import CurrencyLogo from '@components/CurrencyLogo'
import Skeleton from '@components/Skeleton'

// Utils
import { getBalance } from '@utils/api'
import { updateWalletActivationStatus } from '@utils/currencies/nano'
import { getBalance } from '@utils/currencies'
import { toUpper, numberFriendly, formatEstimated, getFormatBalance } from '@utils/format'
import {
updateBalance,
Expand Down Expand Up @@ -94,6 +95,7 @@ const WalletCard: React.FC<Props> = React.memo((props) => {
const [balance, setBalance] = React.useState<number | null>(null)
const [estimated, setEstimated] = React.useState<number | null>(null)
const [pendingBalance, setPendingBalance] = React.useState<number>(0)
const [notActivatedStatus, setActivationStatus] = React.useState<boolean>(!!isNotActivated)

const walletData: TTxWallet = {
chain: getWalletChain(symbol, chain),
Expand All @@ -104,23 +106,34 @@ const WalletCard: React.FC<Props> = React.memo((props) => {
}

React.useEffect(() => {
checkActivatedStatus()
loadBalance()
}, [])

const checkActivatedStatus = () => {
if (symbol === 'xno') {
updateWalletActivationStatus(address).then(res => {
if (res) {
setActivationStatus(true)
}
})
}
}

const loadBalance = async (): Promise<void> => {
const savedData = getLatestBalance(address, chain, symbol)

const isFetchReady = checkIfTimePassed(savedData.lastBalanceCheck || 0, { seconds: 20 })
const isFullData = !Object.entries(savedData).find(v => v[1] === null)

let data = isNotActivated ? emptyData : savedData
let data = notActivatedStatus ? emptyData : savedData

const isFetchRequired = !isNotActivated && (isFetchReady || !isFullData)
const isFetchRequired = !notActivatedStatus && (isFetchReady || !isFullData)

if (isFetchRequired) {
updateLast('lastBalanceCheck', address, chain)

const fetchedData = await getBalance(address, currency?.chain || chain, tokenSymbol, contractAddress)
const fetchedData = await getBalance(symbol, address, currency?.chain || chain, tokenSymbol, contractAddress)
data = { ...data, ...fetchedData }
}

Expand Down Expand Up @@ -185,7 +198,7 @@ const WalletCard: React.FC<Props> = React.memo((props) => {
<Styles.Wrapper onClick={openWallet}>
<Styles.Container className={'container'}>
<CurrencyLogo size={40} symbol={symbol} chain={chain} name={name} />
<Styles.Row gridColumns={isNotActivated ? 'auto' : 'repeat(2,1fr)'}>
<Styles.Row gridColumns={notActivatedStatus ? 'auto' : 'repeat(2,1fr)'}>
<Styles.AddressInfo>
<Styles.CurrencyInfo>
{hardware ? (
Expand All @@ -199,17 +212,17 @@ const WalletCard: React.FC<Props> = React.memo((props) => {
) : null}
<Styles.WalletName className='wallet-name'>{walletName}</Styles.WalletName>
</Styles.CurrencyInfo>
{isNotActivated ? (
{notActivatedStatus ? (
<Styles.ActivateBlock>
<Styles.ActivateLabel>Need activation</Styles.ActivateLabel>
<Styles.ActivateLabel>Activation is required</Styles.ActivateLabel>
</Styles.ActivateBlock>
) : (
<Styles.AddressRow>
<Styles.Address>{address}</Styles.Address>
</Styles.AddressRow>
)}
</Styles.AddressInfo>
{!isNotActivated ? (
{!notActivatedStatus ? (
<Styles.Balances>
<Skeleton width={110} height={16} type='gray' br={4} isLoading={balance === null}>
<Styles.BalanceRow>
Expand Down
10 changes: 10 additions & 0 deletions src/config/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import toncoinLogo from '@assets/currencies/toncoin.svg'
import ravencoinLogo from '@assets/currencies/rvn.svg'
import digibyteLogo from '@assets/currencies/dgb.svg'
import ftmLogo from '@assets/currencies/ftm.svg'
import xnoLogo from '@assets/currencies/xno.svg'

// Utils
import { toLower } from '@utils/format'
Expand Down Expand Up @@ -314,6 +315,15 @@ const currencies: ICurrency[] = [
chain: 'ftm',
minSendAmount: 1000,
isCustomFee: true,
},
{
name: 'Nano',
symbol: 'xno',
logo: xnoLogo,
background: '#209CE9',
chain: 'xno',
minSendAmount: 1000000000000000,
isCustomFee: false,
}
]

Expand Down
3 changes: 2 additions & 1 deletion src/drawers/Wallets/components/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CurrencyLogo from '@components/CurrencyLogo'
import Skeleton from '@components/Skeleton'

// Utils
import { getBalance } from '@utils/api'
import { getBalance } from '@utils/currencies'
import { toUpper, numberFriendly, short, formatEstimated } from '@utils/format'
import { updateBalance, THardware } from '@utils/wallet'

Expand Down Expand Up @@ -58,6 +58,7 @@ const Wallet: React.FC<Props> = (props) => {

const fetchBalance = async (): Promise<void> => {
const { balance, balance_usd, balance_btc, pending } = await getBalance(
symbol,
address,
currency?.chain || chain,
chain ? symbol : undefined,
Expand Down
30 changes: 15 additions & 15 deletions src/externalPages/RestoreBackup/RestoreBackup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const initialState: IState = {
activeDrawer: null,
password: '',
passwordErrorLabel: null,
isPageActive: false,
isPageActive: false
}

const RestoreBackup: React.FC = () => {
Expand Down Expand Up @@ -77,15 +77,15 @@ const RestoreBackup: React.FC = () => {

const onConfirm = (): void => {
logEvent({
name: START_RESTORE_CONFIRM,
name: START_RESTORE_CONFIRM
})

updateState({ activeDrawer: 'confirm' })
}

const onConfirmRestore = (): void => {
logEvent({
name: START_RESTORE_PASSWORD,
name: START_RESTORE_PASSWORD
})

if (state.passwordErrorLabel) {
Expand Down Expand Up @@ -137,7 +137,7 @@ const RestoreBackup: React.FC = () => {
}

return (
<ExternalPageContainer onClose={onClose} headerStyle="white">
<ExternalPageContainer onClose={onClose} headerStyle='white'>
<>
<Styles.Body>
<Styles.Title>Restore</Styles.Title>
Expand All @@ -151,9 +151,9 @@ const RestoreBackup: React.FC = () => {
<AgreeTerms isAgreed={state.isAgreed} setIsAgreed={toggleAgreed} mt={20} />

<Styles.Actions>
<Button label="Cancel" onClick={onClose} isLight mr={7.5} />
<Button label='Cancel' onClick={onClose} isLight mr={7.5} />
<Button
label="Confirm"
label='Confirm'
onClick={onConfirm}
disabled={!state.backupData.length || !state.isAgreed}
ml={7.5}
Expand All @@ -163,7 +163,7 @@ const RestoreBackup: React.FC = () => {
<Styles.DividerLine />

<Styles.QuestionBlock>
<SVG src="../../assets/icons/ask.svg" width={15} height={15} title="ask" />
<SVG src='../../assets/icons/ask.svg' width={15} height={15} title='ask' />
<Styles.Question>Why I see this page?</Styles.Question>
</Styles.QuestionBlock>

Expand All @@ -176,28 +176,28 @@ const RestoreBackup: React.FC = () => {
<ConfirmDrawer
isActive={state.activeDrawer === 'confirm'}
onClose={onCloseDrawer}
title="Enter the password to restore your wallet"
title='Enter the password to restore your wallet'
textInputValue={state.password}
onChangeText={setPassword}
onConfirm={onConfirmRestore}
textInputType="password"
inputLabel="Enter password"
textInputType='password'
inputLabel='Enter password'
isButtonDisabled={!validatePassword(state.password)}
inputErrorLabel={state.passwordErrorLabel}
openFrom="browser"
openFrom='browser'
/>
<FailDrawer
isActive={state.activeDrawer === 'fail'}
onClose={onCloseDrawer}
text="The backup file is broken. We cannot restore your wallet. Check your backup file and try again."
openFrom="browser"
text='The backup file is broken. We cannot restore your wallet. Check your backup file and try again.'
openFrom='browser'
/>
<SuccessDrawer
isActive={state.activeDrawer === 'success'}
onClose={() => null}
icon={puzzleIcon}
text="We successfully restored your wallet. Go to the extension by clicking on the SimpleHold icon in the extensions menu and enjoy your crypto!"
openFrom="browser"
text='We successfully restored your wallet. Go to the extension by clicking on the SimpleHold icon in the extensions menu and enjoy your crypto!'
openFrom='browser'
disableClose
/>
</>
Expand Down
4 changes: 3 additions & 1 deletion src/externalPages/Send/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import NetworkFeeShared from '@shared/NetworkFee'

// Utils
import { getWallets, IWallet, getWalletName } from '@utils/wallet'
import { getBalance, getUnspentOutputs } from '@utils/api'
import { getUnspentOutputs } from '@utils/api'
import { getBalance } from '@utils/currencies'
import { getCurrentTab, updateTab, getUrl } from '@utils/extension'
import { toLower, toUpper, plus } from '@utils/format'
import {
Expand Down Expand Up @@ -436,6 +437,7 @@ const Send: React.FC = () => {

if (getCurrencyInfo) {
const { balance, balance_usd } = await getBalance(
symbol,
address,
getCurrencyInfo?.chain,
chain ? symbol : undefined,
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.21.0",
"version": "1.22.0",
"icons": {
"16": "assets/logo/favicon-16.png",
"32": "assets/logo/favicon-32.png",
Expand Down
6 changes: 4 additions & 2 deletions src/pages/ImportPrivateKey/ImportPrivateKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SuccessDrawer from '@drawers/Success'

// Utils
import { validatePassword } from '@utils/validate'
import { checkExistWallet, addNew as addNewWallet, IWallet, getWallets } from '@utils/wallet'
import { checkExistWallet, addNew as addNewWallet, IWallet, getWallets, activateAddress } from '@utils/wallet'
import { decrypt } from '@utils/crypto'
import { setUserProperties } from '@utils/amplitude'
import { toLower, toUpper } from '@utils/format'
Expand All @@ -37,6 +37,7 @@ import { ITokensBalance } from '@utils/api/types'

// Styles
import Styles from './styles'
import { getActivationStatus } from 'utils/currencies/nano'

const initialState: IState = {
privateKey: '',
Expand Down Expand Up @@ -91,6 +92,7 @@ const ImportPrivateKey: React.FC = () => {
if (chain && !isSkipFindTokens) {
return await findAddressTokens(getAddress, state.privateKey)
}

return updateState({ activeDrawer: 'confirm' })
}

Expand Down Expand Up @@ -177,7 +179,7 @@ const ImportPrivateKey: React.FC = () => {
chain,
tokenName,
contractAddress,
decimals
decimals,
)

if (walletsList) {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/NewWallet/NewWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { decrypt } from '@utils/crypto'
import { addNew as addNewWallet, IWallet } from '@utils/wallet'
import { toUpper } from '@utils/format'
import { generate, checkWithPhrase } from '@utils/currencies'
import * as theta from '@utils/currencies/theta'
import { getItem, setItem } from '@utils/storage'
import * as theta from '@utils/currencies/theta'
import * as vechain from '@utils/currencies/vechain'

// Config
Expand Down Expand Up @@ -138,7 +138,7 @@ const NewWallet: React.FC = () => {
name: ADD_ADDRESS_CONFIRM,
})

if (symbol !== "hbar") {
if (['xno', 'hbar'].indexOf(symbol) !== -1) {
setItem('backupStatus', 'notDownloaded')
}

Expand All @@ -154,7 +154,7 @@ const NewWallet: React.FC = () => {
}

const onDownloadBackup = (): void => {
if (symbol === "hbar") {
if (['xno', 'hbar'].indexOf(symbol) !== -1) {
return history.push('/wallets')
}
return history.replace('/download-backup', {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Send/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import AboutFeeDrawer from '@drawers/AboutFee'
// Utils
import { toLower, toUpper, plus } from '@utils/format'
import { validateMany } from '@utils/validate'
import { getBalance, getUnspentOutputs } from '@utils/api'
import { getBalance } from '@utils/currencies'
import { getUnspentOutputs } from '@utils/api'
import { updateBalance, getWallets } from '@utils/wallet'
import {
getExtraIdName,
Expand Down Expand Up @@ -338,6 +339,7 @@ const SendPage: React.FC = () => {
})

const { balance, balance_usd, balance_btc } = await getBalance(
symbol,
state.selectedAddress,
currency?.chain || tokenChain,
tokenChain ? symbol : undefined,
Expand Down
Loading

0 comments on commit 305442d

Please sign in to comment.