-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add derivation path helper to web-tools (#6800)
Add derivation path helper to web-tools
- Loading branch information
1 parent
70a5aab
commit c7b0ae2
Showing
6 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/web-tools": minor | ||
--- | ||
|
||
Adding derivation path helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, { useCallback, useState } from "react"; | ||
import { findCryptoCurrencyById, listCryptoCurrencies } from "@ledgerhq/cryptoassets"; | ||
import { getDerivationModesForCurrency, getDerivationScheme, runDerivationScheme } from "@ledgerhq/coin-framework/derivation"; | ||
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets"; | ||
|
||
export const getStaticProps = async () => ({ props: {} }); | ||
|
||
const App = () => { | ||
const [accountIndex, setAccountIndex] = useState("ACCOUNT"); | ||
const onAccountIndexChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => { | ||
setAccountIndex(e.target.value); | ||
}, []); | ||
const [addressIndex, setAddressIndex] = useState("ADDRESS"); | ||
const onAddressIndexChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => { | ||
setAddressIndex(e.target.value); | ||
}, []); | ||
|
||
|
||
const [currencyId, setCurrencyId] = useState(""); | ||
const [derivationsPerCurrency, setDerivationsPerCurrency] = useState<{currency: { name: string, id: string }, derivations: {name: string, path: string}[]}[]>([]); | ||
const onCurrencyChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => { | ||
setCurrencyId(e.target.value); | ||
}, []); | ||
const onSubmit = useCallback(() => { | ||
const currencies = !currencyId ? listCryptoCurrencies() : [findCryptoCurrencyById(currencyId)]; | ||
setDerivationsPerCurrency(currencies.map(currency => { | ||
if (!currency) { | ||
return { | ||
currency: { name: "Unknown", id: "Unknown" }, | ||
derivations: [] | ||
}; | ||
} | ||
|
||
return { | ||
currency, | ||
derivations: getDerivationModesForCurrency(currency).map((derivationMode) => { | ||
const deriationScheme = getDerivationScheme({ currency, derivationMode }); | ||
return { | ||
name: derivationMode, | ||
path: runDerivationScheme(deriationScheme, currency, { account: accountIndex, address: addressIndex}), | ||
}; | ||
}) | ||
} | ||
})); | ||
}, [accountIndex, currencyId, addressIndex]); | ||
|
||
return ( | ||
<> | ||
<div> | ||
<label>Account index</label> | ||
<br/> | ||
<input | ||
type="text" | ||
onChange={onAccountIndexChange} | ||
value={accountIndex} | ||
placeholder="Enter the account index" | ||
/> | ||
</div> | ||
<div> | ||
<label>Address index</label> | ||
<br/> | ||
<input | ||
type="text" | ||
onChange={onAddressIndexChange} | ||
value={addressIndex} | ||
placeholder="Enter the address index" | ||
/> | ||
</div> | ||
<div> | ||
<label>Currency Id</label> | ||
<br/> | ||
<input | ||
type="text" | ||
onChange={onCurrencyChange} | ||
value={currencyId} | ||
placeholder="Enter the currency id" | ||
/> | ||
</div> | ||
<br/> | ||
<div> | ||
<button onClick={onSubmit}>Get derivation paths</button> | ||
</div> | ||
{ | ||
derivationsPerCurrency.map(({ currency, derivations }) => ( | ||
<div key={currency.id}> | ||
<h4>{currency.id}</h4> | ||
<ul> | ||
{ | ||
derivations.map(({ name, path }) => ( | ||
<li key={name}> | ||
<li>{name || "Default"}: {path}</li> | ||
</li> | ||
)) | ||
} | ||
</ul> | ||
</div> | ||
)) | ||
} | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
c7b0ae2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Bot] Daily non-reg on develop with 'Nitrogen' ✅ 162 txs ❌ 30 txs 💰 9 miss funds ($1,386.36) ⏲ 33min 16s
4 critical spec errors
Spec injective failed!
Spec VeChain VTHO failed!
Spec Polygon zkEVM Testnet failed!
Spec Solana failed!
❌ 30 mutation errors
Please increase the account target to at least 8 accounts
Please increase the account target to at least 6 accounts
Please increase the account target to at least 6 accounts
Please increase the account target to at least 6 accounts
Please increase the account target to at least 6 accounts
Please increase the account target to at least 6 accounts
Please increase the account target to at least 4 accounts
Please increase the account target to at least 4 accounts
Portfolio ($1,386.36) – Details of the 67 currencies
02026B93627Ed2F76551E7CeF0466468B12db8Fab806266107b69947D9c95CEd9E7c
0x246FFDB387F1F8c48072E1C13443540017bC71b7
osmo1qgrd8srhvald995uvpeyncvwg7afgkmr88spsw
desmos1rs97j43nfyvc689y5rjvnnhrq3tes6gh0y9454
dydx1rs97j43nfyvc689y5rjvnnhrq3tes6ghj9xpr6
umee1rs97j43nfyvc689y5rjvnnhrq3tes6ghf2468l
persistence1rs97j43nfyvc689y5rjvnnhrq3tes6gh4swkdf
quick1rs97j43nfyvc689y5rjvnnhrq3tes6ghscch6l
onomy1rs97j43nfyvc689y5rjvnnhrq3tes6ghpaunjg
sei1rs97j43nfyvc689y5rjvnnhrq3tes6ghksen9v
stars1rs97j43nfyvc689y5rjvnnhrq3tes6gh0qlcgu
core1rs97j43nfyvc689y5rjvnnhrq3tes6ghgjs7yk
cro14zpaxs3msrdnx5ch3m3y3yue0wwwevrf2hmwra
erd18n5sk95fq9dtgdsa9m9q5ddp66ch9cq5lpjflwn5j9z8x2e9h0qqrvk5qp
0.0.3663977
f2ed4c9253d3aca7d679bfa9f528d13e85c7f522b8857e094c850a157b750209
r9etPtq3oboweMPju5gdYufmvwhH2euz8z
SP3WE1A84RCG3GWKRXYMXNRVQJ8PG3VDRKE7CMPM4
GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC
tz1aDK1uFAmnUXZ7KJPEmcCEFeYHiVZ56zVF
0xc4B17901FECf86932c3bb296BB00E7c6816Fd416
TM4WJOS4MZ2TD775W7GSXZMBUF74YT6SKSBXCZY3N7OUIAPXE54MZ5FCD4
tb1p2lr96hmh552xm7snszhg4zkwyznmd05cajwjh2jdw6lyk77cyg9s48ly94
qzpwrsg3c3fye9qkhx98lh97g7wkq656sy80kzgzug
ASNwVtBWnWVH34Fv8BTLCR9UBAsp6SUKGs
XscDzwEtzZjSHzE3VGbjcm6T3WG7VPLaMF
dgb1q4xh2xpc8jk7q49rnuzzd5du4zrhl0g27y9ev9y
DTjV5D5meeZhep2LuJ5rvTnqDauGYjqcaD
RFxSMhF3rwNVC3fSQbgycd3hu6phewyRJi
ltc1q7mdal6g5878z4pgqact4tm24lw8p44gynqs53p
PCJwkHpZdYsmvnJn83aobNm3YX2zA5vAdg
D8xeBxVyjyKHrwvkUYhbecxgrR9mdoa9mv
3EiBRfRPuPpYUafDBTtpejRTFXzByCBhmr
EQ8RaPyeAZuCJT1ywXkrieUUJiB5bPTRPJ
t1SDpcaNZmbCH5TCCb5vNAh5bXs3isDtA5h
zncBAbYh5Q8CAkm9BzEixGMTmTJRAUwVF5Q
0x7584df0780C5eB83b26aE55abBc265014f8bf897
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x90bD48144e08b66490BcA9a756BDe9f004F17857
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x90bD48144e08b66490BcA9a756BDe9f004F17857
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0x60A4E7657D8df28594ac4A06CDe01E18E948a892
0573d7a9c745fa9fe224b080832aa93d740760b94f192c9c141c709945e9aaaf
Performance ⏲ 33min 16s
Time spent for each spec: (total across mutations)