Skip to content

Commit 8a343a3

Browse files
committed
Add ledger connection hint, remove logs
1 parent 2dad9a3 commit 8a343a3

File tree

6 files changed

+83
-64
lines changed

6 files changed

+83
-64
lines changed

src/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface WalletCheckModal {
3939
action?: () => Promise<{ message: string } | undefined>
4040
loading?: Promise<undefined>
4141
icon?: string
42+
hint?: string
4243
}
4344

4445
export interface WalletSelectModalData {

src/modules/check/connect.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@ function connect() {
1212
loading: wallet.loading,
1313
icon: `
1414
<svg height="14" viewBox="0 0 18 14" width="18" xmlns="http://www.w3.org/2000/svg"><g fill="currentColor"><path d="m10.29375 4.05351563c0-.04921875 0-.09140625 0-.13007813 0-1.0546875 0-2.109375 0-3.1640625 0-.43945312.3480469-.76992188.7804688-.7453125.2003906.01054688.3585937.10546875.4992187.24609375.5800781.58359375 1.1566406 1.16367188 1.7367187 1.74023438 1.4695313 1.46953125 2.9390625 2.93906249 4.4050782 4.40859375.1335937.13359375.2425781.27421875.2707031.46757812.0351562.20742188-.0246094.421875-.1652344.58007813-.0246094.028125-.0492187.05273437-.0738281.08085937-2.0601563 2.06367188-4.1203125 4.1238281-6.1804688 6.1875-.2109375.2109375-.4570312.3023438-.7453125.2179688-.2707031-.0808594-.4464843-.2707032-.5132812-.5484375-.0140625-.0738282-.0175781-.1441407-.0140625-.2179688 0-1.0335937 0-2.0707031 0-3.1042969 0-.0386719 0-.08085935 0-.13359372h-5.06953125c-.49570313 0-.80507813-.309375-.80507813-.80859375 0-1.42382813 0-2.84414063 0-4.26796875 0-.49570313.30585938-.8015625.8015625-.8015625h4.93593748z"/><path d="m5.69882812 13.978125h-4.01132812c-.928125 0-1.6875-.8753906-1.6875-1.9511719v-10.06171872c0-1.07578125.75585938-1.95117188 1.6875-1.95117188h4.01132812c.34101563 0 .61523438.31992188.61523438.71015625 0 .39023438-.27421875.71015625-.61523438.71015625h-4.01132812c-.253125 0-.45703125.23554688-.45703125.52734375v10.06171875c0 .2917969.20390625.5273437.45703125.5273437h4.01132812c.34101563 0 .61523438.3199219.61523438.7101563s-.27773438.7171875-.61523438.7171875z"/></g></svg>
15-
`
15+
`,
16+
hint: connectHint(wallet.name)
1617
}
1718
}
1819
}
1920
}
2021

22+
function connectHint(walletName: string) {
23+
switch (walletName) {
24+
case 'Ledger':
25+
return 'Make sure your Ledger wallet is plugged in, unlocked and has the Ethereum app open and then click connect.'
26+
default:
27+
return undefined
28+
}
29+
}
30+
2131
export default connect

src/modules/select/wallets/ledger.ts

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async function ledgerProvider(options: {
8989
getAccounts: (callback: any) => {
9090
getAccounts()
9191
.then((res: Array<any> | undefined) => callback(null, res))
92-
.catch(err => callback(err, null))
92+
.catch((err: string) => callback(err, null))
9393
},
9494
signTransaction: (transactionData: any, callback: any) => {
9595
signTransaction(transactionData)
@@ -165,58 +165,60 @@ async function ledgerProvider(options: {
165165
listener && listener(addresses())
166166
}
167167

168-
async function getAccounts(numberToGet: number = 1, getMore?: boolean) {
169-
console.log('get accounts called:', { numberToGet, getMore: getMore })
170-
if (!enabled) {
171-
return [null]
172-
}
168+
function getAccounts(
169+
numberToGet: number = 1,
170+
getMore?: boolean
171+
): Promise<any[]> {
172+
return new Promise(async (resolve, reject) => {
173+
if (!enabled) {
174+
resolve([null])
175+
}
173176

174-
const addressesAlreadyFetched = addressToPath.size
177+
const addressesAlreadyFetched = addressToPath.size
175178

176-
if (addressesAlreadyFetched > 0 && !getMore) {
177-
console.log('already have 1 address')
178-
return addresses()
179-
}
179+
if (addressesAlreadyFetched > 0 && !getMore) {
180+
return addresses()
181+
}
180182

181-
const paths = []
182-
183-
if (numberToGet > 1) {
184-
for (
185-
let i = addressesAlreadyFetched;
186-
i < numberToGet + addressesAlreadyFetched;
187-
i++
188-
) {
189-
const ledgerPath = `${basePath}/0'/${i}`
190-
const bipPath = `${basePath}/${i}'/0/0`
191-
paths.push(ledgerPath, bipPath)
183+
const paths = []
184+
185+
if (numberToGet > 1) {
186+
for (
187+
let i = addressesAlreadyFetched;
188+
i < numberToGet + addressesAlreadyFetched;
189+
i++
190+
) {
191+
const ledgerPath = `${basePath}/0'/${i}`
192+
const bipPath = `${basePath}/${i}'/0/0`
193+
paths.push(ledgerPath, bipPath)
194+
}
195+
} else {
196+
paths.push(`${basePath}/0'/0`)
192197
}
193-
} else {
194-
paths.push(`${basePath}/0'/0`)
195-
}
196198

197-
console.log('creating transport')
198-
const transport = await TransportU2F.create()
199-
const eth = new Eth(transport)
200-
console.log('transport created')
201-
202-
for (const path of paths) {
203-
try {
204-
console.log('getting address for path:', path)
205-
const { address } = await eth.getAddress(path)
206-
addressToPath.set(address.toLowerCase(), path)
207-
} catch (err) {
208-
console.log({ err })
199+
const transport = await TransportU2F.create()
200+
const eth = new Eth(transport)
201+
202+
for (const path of paths) {
203+
try {
204+
const { address } = await eth.getAddress(path)
205+
addressToPath.set(address.toLowerCase(), path)
206+
} catch (err) {
207+
return reject({
208+
message: 'An error occurred when trying to get account information'
209+
})
210+
}
209211
}
210-
}
211212

212-
const allAddresses = addresses()
213+
const allAddresses = addresses()
213214

214-
const listener = listeners.get('accountsChanged')
215-
listener && listener(allAddresses)
215+
const listener = listeners.get('accountsChanged')
216+
listener && listener(allAddresses)
216217

217-
transport.close()
218+
transport.close()
218219

219-
return allAddresses
220+
resolve(allAddresses)
221+
})
220222
}
221223

222224
function getBalance(address: string) {
@@ -260,7 +262,6 @@ async function ledgerProvider(options: {
260262

261263
return `0x${transaction.serialize().toString('hex')}`
262264
} catch (error) {
263-
console.log({ error })
264265
throw new Error(error)
265266
} finally {
266267
transport.close()

src/modules/select/wallets/trezor.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -282,27 +282,21 @@ async function trezorProvider(options: {
282282
async function signTransaction(transactionData: any) {
283283
const path = [...addressToPath.values()][0]
284284

285-
try {
286-
const transaction = new EthereumTx(transactionData, {
287-
chain: networkName(networkId)
288-
})
289-
const trezorResult = await trezorSignTransaction(path, transactionData)
285+
const transaction = new EthereumTx(transactionData, {
286+
chain: networkName(networkId)
287+
})
288+
const trezorResult = await trezorSignTransaction(path, transactionData)
290289

291-
if (!trezorResult.success) {
292-
console.log('error', trezorResult.payload.error)
293-
throw new Error(trezorResult.payload.error)
294-
}
290+
if (!trezorResult.success) {
291+
throw new Error(trezorResult.payload.error)
292+
}
295293

296-
const signature = trezorResult.payload
297-
transaction.v = signature.v
298-
transaction.r = signature.r
299-
transaction.s = signature.s
294+
const signature = trezorResult.payload
295+
transaction.v = signature.v
296+
transaction.r = signature.r
297+
transaction.s = signature.s
300298

301-
return `0x${transaction.serialize().toString('hex')}`
302-
} catch (error) {
303-
console.log({ error })
304-
throw new Error(error)
305-
}
299+
return `0x${transaction.serialize().toString('hex')}`
306300
}
307301

308302
return provider

src/validation.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ export function validateModal(modal: WalletCheckModal): never | void {
359359
icon,
360360
loading,
361361
html,
362+
hint,
362363
...otherParams
363364
} = modal
364365

@@ -371,7 +372,9 @@ export function validateModal(modal: WalletCheckModal): never | void {
371372
'eventCode',
372373
'action',
373374
'icon',
374-
'heading'
375+
'loading',
376+
'html',
377+
'hint'
375378
],
376379
'modal'
377380
)
@@ -407,6 +410,13 @@ export function validateModal(modal: WalletCheckModal): never | void {
407410
optional: true
408411
})
409412

413+
validateType({
414+
name: 'hint',
415+
value: hint,
416+
type: 'string',
417+
optional: true
418+
})
419+
410420
if (button) {
411421
const { onclick, text, ...restParams } = button
412422
invalidParams(restParams, ['onclick', 'text'], 'button')

src/views/WalletCheck.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@
270270
<p class="bn-onboard-custom bn-onboard-prepare-description">
271271
{@html activeModal.description}
272272
</p>
273+
{#if activeModal.hint}
274+
<p>{activeModal.hint}</p>
275+
{/if}
273276
{#if errorMsg}
274277
<span
275278
class:bn-onboard-dark-mode-background={$app.darkMode}

0 commit comments

Comments
 (0)