Skip to content

Commit

Permalink
Merge pull request oasisprotocol#1784 from oasisprotocol/ml/trivial/r…
Browse files Browse the repository at this point in the history
…ename-ledger-wallet-type

Rename WalletType.Ledger to WalletType.UsbLedger
  • Loading branch information
lubej authored Nov 30, 2023
2 parents 5a0f690 + 8ca2795 commit 165fe3d
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions .changelog/1784.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rename WalletType.Ledger to WalletType.UsbLedger
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface DerivationFormatterProps {
export const DerivationFormatter = (props: DerivationFormatterProps) => {
const { t } = useTranslation()
const walletTypes: { [type in WalletType]: string } = {
[WalletType.Ledger]: t('toolbar.wallets.type.usbLedger', 'USB Ledger'),
[WalletType.UsbLedger]: t('toolbar.wallets.type.usbLedger', 'USB Ledger'),
[WalletType.BleLedger]: t('toolbar.wallets.type.bluetoothLedger', 'BLE Ledger'),
[WalletType.Mnemonic]: t('toolbar.wallets.type.mnemonic', 'Mnemonic'),
[WalletType.PrivateKey]: t('toolbar.wallets.type.privateKey', 'Private key'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('<AccountSelector />', () => {
address: 'oasis1qq3xrq0urs8qcffhvmhfhz4p0mu7ewc8rscnlwxe',
balance: { available: '100', debonding: '0', delegations: '0', total: '100' },
publicKey: '00',
type: WalletType.Ledger,
type: WalletType.UsbLedger,
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions src/app/lib/__tests__/ledger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ describe('Ledger Library', () => {

it('Should fail if the wallet does not have a path', () => {
const openWallet = () => {
new LedgerSigner({ type: WalletType.Ledger } as Wallet)
new LedgerSigner({ type: WalletType.UsbLedger } as Wallet)
}
expect(openWallet).toThrow(/ not a ledger wallet/)
})

it('Should fail without USB transport', async () => {
const signer = new LedgerSigner({
type: WalletType.Ledger,
type: WalletType.UsbLedger,
path: [44, 474, 0, 0, 0],
pathDisplay: `m/44'/474'/0'/0'/0'`,
publicKey: '00',
Expand All @@ -168,7 +168,7 @@ describe('Ledger Library', () => {

it('Should return the public key', () => {
const signer = new LedgerSigner({
type: WalletType.Ledger,
type: WalletType.UsbLedger,
path: [44, 474, 0, 0, 0],
pathDisplay: `m/44'/474'/0'/0'/0'`,
publicKey: 'aabbcc',
Expand All @@ -188,7 +188,7 @@ describe('Ledger Library', () => {
sign.mockResolvedValueOnce({ return_code: 0x6986, error_message: '' })

const signer = new LedgerSigner({
type: WalletType.Ledger,
type: WalletType.UsbLedger,
path: [44, 474, 0, 0, 0],
pathDisplay: `m/44'/474'/0'/0'/0'`,
publicKey: '00',
Expand All @@ -215,7 +215,7 @@ describe('Ledger Library', () => {
})

const signer = new LedgerSigner({
type: WalletType.Ledger,
type: WalletType.UsbLedger,
path: [44, 474, 0, 0, 0],
pathDisplay: `m/44'/474'/0'/0'/0'`,
publicKey: '00',
Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class LedgerSigner implements ContextSigner {
transportType: LedgerWalletType

constructor(wallet: Wallet) {
if (!wallet.path || (wallet.type !== WalletType.Ledger && wallet.type !== WalletType.BleLedger)) {
if (!wallet.path || (wallet.type !== WalletType.UsbLedger && wallet.type !== WalletType.BleLedger)) {
throw new Error('Given wallet is not a ledger wallet')
}
this.path = wallet.path
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/ConnectDevicePage/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('<ConnectDevicePage />', () => {
expect(screen.getByLabelText('Status is okay')).toBeInTheDocument()
expect(screen.queryByRole('button')).not.toBeInTheDocument()
expect(mockDispatch).toHaveBeenCalledWith({
payload: WalletType.Ledger,
payload: WalletType.UsbLedger,
type: importAccountsActions.enumerateAccountsFromLedger.type,
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/ConnectDevicePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function ConnectDevicePage() {
const device = await requestDevice()
if (device) {
setConnection('connected')
dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.Ledger))
dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.UsbLedger))
}
} catch {
setConnection('error')
Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/OpenWalletPage/Features/FromLedger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function FromLedger() {
type="submit"
label={t('openWallet.importAccounts.selectWallets', 'Select accounts to open')}
onClick={() => {
dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.Ledger))
dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.UsbLedger))
}}
primary
/>
Expand All @@ -48,7 +48,7 @@ export function FromLedger() {
abort={() => {
dispatch(importAccountsActions.clear())
}}
type={WalletType.Ledger}
type={WalletType.UsbLedger}
/>
)}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const renderComponent = (store: any, abortFunction = () => {}) =>
render(
<Provider store={store}>
<ThemeProvider>
<ImportAccountsSelectionModal abort={abortFunction} type={WalletType.Ledger} />
<ImportAccountsSelectionModal abort={abortFunction} type={WalletType.UsbLedger} />
</ThemeProvider>
</Provider>,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function ImportAccountsSelector({ accounts }: ImportAccountsSelectorSelectorProp

interface ImportAccountsSelectionModalProps {
abort: () => void
type: WalletType.Mnemonic | WalletType.Ledger
type: WalletType.Mnemonic | WalletType.UsbLedger
}

interface FormValue extends ChoosePasswordFieldsFormValue {}
Expand All @@ -64,7 +64,7 @@ export function ImportAccountsSelectionModal(props: ImportAccountsSelectionModal

const openAccounts = ({ value }: { value: FormValue }) => {
dispatch(
props.type === WalletType.Ledger
props.type === WalletType.UsbLedger
? walletActions.openWalletsFromLedger({ choosePassword: value.password2 })
: walletActions.openWalletFromMnemonic({ choosePassword: value.password2 }),
)
Expand All @@ -84,7 +84,7 @@ export function ImportAccountsSelectionModal(props: ImportAccountsSelectionModal
const onNext = () => {
dispatch(importAccountsActions.setPage(pageNum + 1))
if (props.type === 'ledger') {
dispatch(importAccountsActions.enumerateMoreAccountsFromLedger(WalletType.Ledger))
dispatch(importAccountsActions.enumerateMoreAccountsFromLedger(WalletType.UsbLedger))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/ParaTimesPage/useParaTimesNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useParaTimesNavigation = (): ParaTimesNavigationHook => {
const { t } = useTranslation()
const dispatch = useDispatch()
const walletType = useSelector(selectType)
const canAccessParaTimesRoute = backend() === BackendAPIs.OasisScan && walletType !== WalletType.Ledger
const canAccessParaTimesRoute = backend() === BackendAPIs.OasisScan && walletType !== WalletType.UsbLedger
const getParaTimesRoutePath = (address: string) => `/account/${address}/paratimes`
const navigateToDeposit = useCallback(() => dispatch(paraTimesActions.navigateToDeposit()), [dispatch])
const navigateToWithdraw = useCallback(() => dispatch(paraTimesActions.navigateToWithdraw()), [dispatch])
Expand Down
10 changes: 5 additions & 5 deletions src/app/state/importaccounts/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('importAccounts Sagas', () => {
[matchers.call.fn(Ledger.deriveAccountUsingOasisApp), validAccount],
[matchers.call.fn(getAccountBalanceWithFallback), {}],
])
.dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.Ledger))
.dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.UsbLedger))
.put.actionType(importAccountsActions.accountGenerated.type)
.put.actionType(importAccountsActions.accountGenerated.type)
.put.actionType(importAccountsActions.accountGenerated.type)
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('importAccounts Sagas', () => {
},
],
])
.dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.Ledger))
.dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.UsbLedger))
.put.like({ action: { payload: { code: WalletErrors.USBTransportNotSupported } } })
.silentRun(50)
})
Expand All @@ -108,7 +108,7 @@ describe('importAccounts Sagas', () => {
[matchers.call.fn(TransportWebUSB.isSupported), true],
[matchers.call.fn(TransportWebUSB.create), Promise.reject(new Error('No device selected'))],
])
.dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.Ledger))
.dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.UsbLedger))
.put.like({ action: { payload: { code: WalletErrors.LedgerNoDeviceSelected } } })
.silentRun(50)
})
Expand All @@ -120,7 +120,7 @@ describe('importAccounts Sagas', () => {
[matchers.call.fn(TransportWebUSB.isSupported), true],
[matchers.call.fn(TransportWebUSB.create), Promise.reject(new Error('Dummy error'))],
])
.dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.Ledger))
.dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.UsbLedger))
.put.like({ action: { payload: { code: WalletErrors.USBTransportError, message: 'Dummy error' } } })
.silentRun(50)
})
Expand All @@ -139,7 +139,7 @@ describe('importAccounts Sagas', () => {
[matchers.call.fn(Ledger.getOasisApp), undefined],
[matchers.call.fn(Ledger.deriveAccountUsingOasisApp), Promise.reject(new Error('Dummy error'))],
])
.dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.Ledger))
.dispatch(importAccountsActions.enumerateAccountsFromLedger(WalletType.UsbLedger))
.put.like({ action: { payload: { code: WalletErrors.UnknownError, message: 'Dummy error' } } })
.silentRun(50)
})
Expand Down
4 changes: 2 additions & 2 deletions src/app/state/transaction/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function* getSigner() {
if (wallet.type === WalletType.PrivateKey || wallet.type === WalletType.Mnemonic) {
const bytes = hex2uint(privateKey!)
signer = yield* call(signerFromPrivateKey, bytes)
} else if (wallet.type === WalletType.Ledger || wallet.type === WalletType.BleLedger) {
} else if (wallet.type === WalletType.UsbLedger || wallet.type === WalletType.BleLedger) {
signer = new LedgerSigner(wallet)
} else {
throw new ExhaustedTypeError('Invalid wallet type', wallet.type)
Expand Down Expand Up @@ -190,7 +190,7 @@ export function* doTransaction(action: PayloadAction<TransactionPayload>) {

yield* setStep(TransactionStep.Signing)

if (activeWallet.type === WalletType.Ledger || activeWallet.type === WalletType.BleLedger) {
if (activeWallet.type === WalletType.UsbLedger || activeWallet.type === WalletType.BleLedger) {
yield* call(sign, signer as LedgerSigner, tw)
} else {
yield* call(OasisTransaction.sign, chainContext, signer as Signer, tw)
Expand Down
2 changes: 1 addition & 1 deletion src/app/state/wallet/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function* openWalletsFromLedger({ payload }: PayloadAction<OpenSelectedAc
yield* call(addWallet, {
address: account.address,
publicKey: account.publicKey,
type: WalletType.Ledger,
type: WalletType.UsbLedger,
balance: account.balance!,
path: account.path,
pathDisplay: account.pathDisplay,
Expand Down
4 changes: 2 additions & 2 deletions src/app/state/wallet/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { BalanceDetails } from '../account/types'

export enum WalletType {
Ledger = 'ledger',
UsbLedger = 'ledger',
BleLedger = 'ble_ledger',
PrivateKey = 'private_key',
Mnemonic = 'mnemonic',
}

export type LedgerWalletType = WalletType.Ledger | WalletType.BleLedger
export type LedgerWalletType = WalletType.UsbLedger | WalletType.BleLedger

export interface BalanceUpdatePayload {
address: string
Expand Down
2 changes: 1 addition & 1 deletion src/utils/walletExtensionV0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export async function decryptWithPasswordV0(password: string, extensionV0State:
return {
publicKey: acc.publicKey,
address: acc.address,
type: WalletType.Ledger,
type: WalletType.UsbLedger,
path: [44, 474, 0, 0, acc.ledgerHdIndex],
pathDisplay: `m/44'/474'/0'/0'/${acc.ledgerHdIndex}'`,
balance: {
Expand Down

0 comments on commit 165fe3d

Please sign in to comment.