Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
Resolve: [Swap] Ledger's walletIndex get lost (#1901)
Browse files Browse the repository at this point in the history
`walletIndex` is required on different places now (not optional as before)
  • Loading branch information
veado authored Oct 29, 2021
1 parent f30453b commit 7ba6658
Show file tree
Hide file tree
Showing 63 changed files with 307 additions and 152 deletions.
2 changes: 1 addition & 1 deletion src/main/api/ledger/binance/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const send = async ({
amount,
asset,
memo,
walletIndex = 0
walletIndex
}: {
transport: Transport
amount: BaseAmount
Expand Down
2 changes: 1 addition & 1 deletion src/main/api/ledger/thorchain/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LedgerErrorType } from '@thorchain/ledger-thorchain'
import { LedgerErrorId } from '../../../../shared/api/types'

// TODO(@veado) Get path by using `xchain-thorchain`
export const getDerivationPath = (walletIndex = 0) => [44, 931, 0, 0, walletIndex]
export const getDerivationPath = (walletIndex: number) => [44, 931, 0, 0, walletIndex]

export const fromLedgerErrorType = (error: number): LedgerErrorId => {
switch (error) {
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/deposit/add/SymDeposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@ export const SymDeposit: React.FC<Props> = (props) => {
// Decimal needs to be converted back for using orginal decimal of this asset (provided by `assetBalance`)
asset: convertBaseAmountDecimal(assetAmountToDepositMax1e8, assetDecimal)
},
memos
memos,
// TODO (@asgx-team) Get it from props when we will support Ledger for sym. deposit
walletType: 'keystore',
walletIndex: 0
}
})
),
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/deposit/withdraw/Withdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ export const Withdraw: React.FC<Props> = ({
subscribeWithdrawState(
withdraw$({
network,
memo
memo,
// TODO (@asgdx-team) Get walletType|index from props when we introduce Ledger for withdrawing
walletType: 'keystore',
walletIndex: 0
})
)
}, [closePasswordModal, subscribeWithdrawState, withdraw$, network, memo])
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/components/swap/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export const Swap = ({
const oAddress: O.Option<Address> = useTargetAssetLedger ? oTargetLedgerAddress : oTargetWalletAddress
return FP.pipe(
sequenceTOption(assetsToSwap, oPoolAddress, oAddress, oSourceAssetWB),
O.map(([{ source, target }, poolAddress, address, { walletType, walletAddress }]) => {
O.map(([{ source, target }, poolAddress, address, { walletType, walletAddress, walletIndex }]) => {
return {
poolAddress,
asset: source,
Expand All @@ -369,7 +369,8 @@ export const Swap = ({
limit: Utils.getSwapLimit(swapResultAmountMax1e8, slipTolerance)
}),
walletType,
sender: walletAddress
sender: walletAddress,
walletIndex
}
})
)
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/components/wallet/assets/AssetDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ export const AssetDetails: React.FC<Props> = (props): JSX.Element => {
const walletActionDepositClick = useCallback(() => {
FP.pipe(
oWalletAddress,
O.map((walletAddress) => walletRoutes.deposit.path({ walletType, walletAddress })),
O.map((walletAddress) =>
walletRoutes.deposit.path({ walletType, walletAddress, walletIndex: walletIndex.toString() })
),
O.map(history.push)
)
}, [oWalletAddress, history.push, walletType])
}, [oWalletAddress, history.push, walletType, walletIndex])

const isNonNativeRuneAsset: boolean = useMemo(
() => AssetHelper.isNonNativeRuneAsset(asset, network),
Expand Down
20 changes: 13 additions & 7 deletions src/renderer/components/wallet/txs/send/Send.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { RDStatus, getMockRDValueFactory } from '../../../../../shared/mock/rdBy
import { mockValidatePassword$ } from '../../../../../shared/mock/wallet'
import { WalletType } from '../../../../../shared/wallet/types'
import { mockWalletBalance } from '../../../../helpers/test/testWalletHelper'
import { SendTxParams } from '../../../../services/binance/types'
import { SendTxParams } from '../../../../services/chain/types'
import { WalletBalances } from '../../../../services/clients'
import { ErrorId, TxHashRD, WalletBalance } from '../../../../services/wallet/types'
import { Send } from './Send'
Expand Down Expand Up @@ -125,12 +125,18 @@ const defaultComponentProps = {
balances,
balance: bnbAsset,
feesWithRates: RD.success({ fees, rates }),
onSubmit: ({ recipient, amount, asset, memo }: SendTxParams) =>
console.log(
`to: ${recipient}, amount ${formatAssetAmount({ amount: baseToAsset(amount) })}, asset: ${assetToString(
asset
)}, memo: ${memo}`
),
onSubmit: (p: SendTxParams) => {
const { recipient, amount, asset, memo, walletIndex, walletType, sender } = p
console.log(`
to: ${recipient},
amount ${formatAssetAmount({ amount: baseToAsset(amount) })},
asset: ${assetToString(asset)},
memo: ${memo},
sender: ${sender},
walletType: ${walletType},
walletIndex: ${walletIndex}
`)
},

isLoading: false,
addressValidation: (_: unknown) => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const rates: FeeRates = {

const defaultProps: ComponentProps = {
walletType: 'keystore',
walletIndex: 0,
balances: [bchBalance, runeBalance],
balance: bchBalance,
onSubmit: ({ recipient, amount, feeOption, memo }: SendTxParams) =>
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/wallet/txs/send/SendFormBCH.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type FormValues = {

export type Props = {
walletType: WalletType
walletIndex: number
balances: WalletBalances
balance: WalletBalance
onSubmit: (p: SendTxParams) => void
Expand All @@ -64,6 +65,7 @@ export type Props = {
export const SendFormBCH: React.FC<Props> = (props): JSX.Element => {
const {
walletType,
walletIndex,
balances,
balance,
onSubmit,
Expand Down Expand Up @@ -267,13 +269,14 @@ export const SendFormBCH: React.FC<Props> = (props): JSX.Element => {

onSubmit({
walletType,
walletIndex,
recipient: form.getFieldValue('recipient'),
asset: balance.asset,
amount: assetToBase(assetAmount(form.getFieldValue('amount'))),
feeOption: selectedFeeOptionKey,
memo: form.getFieldValue('memo')
})
}, [selectedFeeOptionKey, onSubmit, form, balance, walletType])
}, [onSubmit, walletType, walletIndex, form, balance.asset, selectedFeeOptionKey])

const renderPwModal = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {

import { mockValidatePassword$ } from '../../../../../shared/mock/wallet'
import { mockWalletBalance } from '../../../../helpers/test/testWalletHelper'
import { SendTxParams } from '../../../../services/binance/types'
import { SendTxParams } from '../../../../services/chain/types'
import { WalletBalance } from '../../../../services/wallet/types'
import { SendFormBNB, Props as SendFormBNBProps } from './SendFormBNB'

Expand All @@ -33,16 +33,17 @@ const runeBalance: WalletBalance = mockWalletBalance({

const defaultProps: SendFormBNBProps = {
walletType: 'keystore',
walletAddress: 'bnb-address',
walletIndex: 0,
walletAddress: 'bnb-address',
balances: [bnbBalance, runeBalance],
balance: bnbBalance,
onSubmit: ({ recipient, amount, asset, memo }: SendTxParams) =>
onSubmit: ({ recipient, amount, asset, memo }: SendTxParams) => {
console.log(
`to: ${recipient}, amount ${formatAssetAmount({ amount: baseToAsset(amount) })}, asset: ${assetToString(
asset
)}, memo: ${memo}`
),
)
},

isLoading: false,
addressValidation: (_: string) => true,
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/wallet/txs/send/SendFormBNB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type Props = {
balances: WalletBalances
balance: WalletBalance
walletAddress: Address
walletIndex?: number
walletIndex: number
onSubmit: (p: SendTxParams) => void
isLoading: boolean
sendTxStatusMsg: string
Expand Down Expand Up @@ -186,12 +186,12 @@ export const SendFormBNB: React.FC<Props> = (props): JSX.Element => {

onSubmit({
walletType,
walletIndex,
sender: walletAddress,
recipient: form.getFieldValue('recipient'),
asset: balance.asset,
amount: amountToSend,
memo: form.getFieldValue('memo'),
walletIndex: walletIndex
memo: form.getFieldValue('memo')
})
}, [onSubmit, walletType, walletAddress, form, balance.asset, amountToSend, walletIndex])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const rates: FeeRates = {

const defaultProps: ComponentProps = {
walletType: 'keystore',
walletIndex: 0,
balances: [btcBalance, runeBalance],
balance: btcBalance,
onSubmit: ({ recipient, amount, feeOption, memo }: SendTxParams) =>
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/wallet/txs/send/SendFormBTC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type FormValues = {

export type Props = {
walletType: WalletType
walletIndex: number
balances: WalletBalances
balance: WalletBalance
onSubmit: (p: SendTxParams) => void
Expand All @@ -64,6 +65,7 @@ export type Props = {
export const SendFormBTC: React.FC<Props> = (props): JSX.Element => {
const {
walletType,
walletIndex,
balances,
balance,
onSubmit,
Expand Down Expand Up @@ -267,13 +269,14 @@ export const SendFormBTC: React.FC<Props> = (props): JSX.Element => {

onSubmit({
walletType,
walletIndex,
recipient: form.getFieldValue('recipient'),
asset: balance.asset,
amount: assetToBase(assetAmount(form.getFieldValue('amount'))),
feeOption: selectedFeeOption,
memo: form.getFieldValue('memo')
})
}, [onSubmit, walletType, form, balance.asset, selectedFeeOption])
}, [onSubmit, walletType, walletIndex, form, balance.asset, selectedFeeOption])

const renderPwModal = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { assetAmount, AssetETH, assetToBase } from '@xchainjs/xchain-util'
import { mockValidatePassword$ } from '../../../../../shared/mock/wallet'
import { THORCHAIN_DECIMAL } from '../../../../helpers/assetHelper'
import { mockWalletBalance } from '../../../../helpers/test/testWalletHelper'
import { SendTxParams } from '../../../../services/ethereum/types'
import { SendTxParams } from '../../../../services/chain/types'
import { WalletBalance } from '../../../../services/wallet/types'
import { SendFormETH } from './index'
import { Props as SendFormETHProps } from './SendFormETH'
Expand All @@ -33,6 +33,7 @@ const fees: Fees = {

const defaultProps: SendFormETHProps = {
walletType: 'keystore',
walletIndex: 0,
balances: [ethBalance, runeBalance],
balance: ethBalance,
fees: RD.success(fees),
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/wallet/txs/send/SendFormETH.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type FormValues = {

export type Props = {
walletType: WalletType
walletIndex: number
balances: WalletBalances
balance: WalletBalance
onSubmit: (p: SendTxParams) => void
Expand All @@ -64,6 +65,7 @@ export type Props = {
export const SendFormETH: React.FC<Props> = (props): JSX.Element => {
const {
walletType,
walletIndex,
balances,
balance,
onSubmit,
Expand Down Expand Up @@ -289,6 +291,7 @@ export const SendFormETH: React.FC<Props> = (props): JSX.Element => {
O.map(([amount, recipient]) => {
onSubmit({
walletType,
walletIndex,
recipient,
asset: balance.asset,
amount,
Expand All @@ -298,7 +301,7 @@ export const SendFormETH: React.FC<Props> = (props): JSX.Element => {
return true
})
)
}, [amountToSend, sendAddress, onSubmit, walletType, balance.asset, selectedFeeOption, form])
}, [amountToSend, sendAddress, onSubmit, walletType, walletIndex, balance.asset, selectedFeeOption, form])

const renderPwModal = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const rates: FeeRates = {

const defaultProps: ComponentProps = {
walletType: 'keystore',
walletIndex: 0,
balances: [ltcBalance, runeBalance],
balance: ltcBalance,
onSubmit: ({ recipient, amount, feeOption, memo }: SendTxParams) =>
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/wallet/txs/send/SendFormLTC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type FormValues = {

export type Props = {
walletType: WalletType
walletIndex: number
balances: WalletBalances
balance: WalletBalance
onSubmit: (p: SendTxParams) => void
Expand All @@ -64,6 +65,7 @@ export type Props = {
export const SendFormLTC: React.FC<Props> = (props): JSX.Element => {
const {
walletType,
walletIndex,
balances,
balance,
onSubmit,
Expand Down Expand Up @@ -264,13 +266,14 @@ export const SendFormLTC: React.FC<Props> = (props): JSX.Element => {

onSubmit({
walletType,
walletIndex,
recipient: form.getFieldValue('recipient'),
asset: balance.asset,
amount: amountToSend,
feeOption: selectedFeeOption,
memo: form.getFieldValue('memo')
})
}, [onSubmit, walletType, form, balance.asset, amountToSend, selectedFeeOption])
}, [onSubmit, walletType, walletIndex, form, balance.asset, amountToSend, selectedFeeOption])

const renderPwModal = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {

import { mockValidatePassword$ } from '../../../../../shared/mock/wallet'
import { mockWalletBalance } from '../../../../helpers/test/testWalletHelper'
import { SendTxParams } from '../../../../services/binance/types'
import { SendTxParams } from '../../../../services/chain/types'
import { WalletBalance } from '../../../../services/wallet/types'
import { SendFormTHOR as Component, Props as ComponentProps } from './SendFormTHOR'

Expand All @@ -23,6 +23,7 @@ const runeBalance: WalletBalance = mockWalletBalance({

const defaultProps: ComponentProps = {
walletType: 'keystore',
walletIndex: 0,
balances: [runeBalance],
balance: runeBalance,
onSubmit: ({ recipient, amount, asset, memo }: SendTxParams) =>
Expand Down
5 changes: 4 additions & 1 deletion src/renderer/components/wallet/txs/send/SendFormTHOR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type FormValues = {

export type Props = {
walletType: WalletType
walletIndex: number
balances: WalletBalances
balance: WalletBalance
onSubmit: (p: SendTxParams) => void
Expand All @@ -62,6 +63,7 @@ export type Props = {
export const SendFormTHOR: React.FC<Props> = (props): JSX.Element => {
const {
walletType,
walletIndex,
balances,
balance,
onSubmit,
Expand Down Expand Up @@ -183,12 +185,13 @@ export const SendFormTHOR: React.FC<Props> = (props): JSX.Element => {

onSubmit({
walletType,
walletIndex,
recipient: form.getFieldValue('recipient'),
asset: balance.asset,
amount: amountToSend,
memo: form.getFieldValue('memo')
})
}, [onSubmit, form, balance.asset, amountToSend, walletType])
}, [onSubmit, form, balance.asset, amountToSend, walletType, walletIndex])

const renderPwModal = useMemo(
() =>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/hooks/useLedger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useLedger = (chain: Chain) => {
const { askLedgerAddress$, getLedgerAddress$, verifyLedgerAddress, removeLedgerAddress } = useWalletContext()

const verifyAddress = useCallback(
(walletIndex = 0) => verifyLedgerAddress(chain, network, walletIndex),
(walletIndex) => verifyLedgerAddress(chain, network, walletIndex),
[chain, verifyLedgerAddress, network]
)
const removeAddress = useCallback(() => removeLedgerAddress(chain, network), [chain, removeLedgerAddress, network])
Expand Down
Loading

0 comments on commit 7ba6658

Please sign in to comment.