-
Notifications
You must be signed in to change notification settings - Fork 403
enable 'no-unsafe-call' lint #1905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
73527de
avoid calling .toString() on type 'any'
dynst cc87031
type-narrowing on a json array before calling .map
dynst 19fe365
ledger-amino: add type annotation to Transport hack
dynst 9c4f80c
ledger-amino: return type in demo
dynst 00b373b
ledger-amino: coerce error to string in demo
dynst 9fdd328
ledger-amino: assign strings to forms
dynst cf41d5b
ledger-amino: add type safety to web forms
dynst 6578d28
enable '@typescript-eslint/no-unsafe-call' lint
dynst 888d15e
ledger-amino: add return type
dynst 3998cb5
ledger-amino: remove 'window: any' from web demo code
dynst 9d17324
stargate: don't construct an Array<any>
dynst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -8,8 +8,11 @@ import TransportWebUSB from "@ledgerhq/hw-transport-webusb"; | |
|
|
||
| import { LedgerSigner } from "../ledgersigner"; | ||
|
|
||
| declare const window: any; | ||
| declare const document: any; | ||
| const getElement = (id: string): HTMLInputElement => { | ||
| const e = document.getElementById(id); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this compile? How does TS know
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nevermind, in ledger-amino we have DOM types due to |
||
| assert(e instanceof HTMLInputElement, "got the wrong element!"); | ||
| return e; | ||
| }; | ||
|
|
||
| const accountNumbers = [0, 1, 2, 10]; | ||
| const paths = accountNumbers.map(makeCosmoshubPath); | ||
|
|
@@ -45,7 +48,7 @@ function createSignDoc(accountNumber: number, address: string): string { | |
| return JSON.stringify(signDoc, null, 2); | ||
| } | ||
|
|
||
| window.updateMessage = (accountNumberInput: unknown) => { | ||
| const updateMessage = (accountNumberInput: unknown): void => { | ||
| assert(typeof accountNumberInput === "string"); | ||
| const accountNumber = Uint53.fromString(accountNumberInput).toNumber(); | ||
| const account = accounts[accountNumber]; | ||
|
|
@@ -54,23 +57,23 @@ window.updateMessage = (accountNumberInput: unknown) => { | |
| } | ||
|
|
||
| const address = accounts[accountNumber].address; | ||
| const addressInput = document.getElementById("address"); | ||
| const addressInput = getElement("address"); | ||
| addressInput.value = address; | ||
| const signDocTextArea = document.getElementById("sign-doc"); | ||
| const signDocTextArea = getElement("sign-doc"); | ||
| signDocTextArea.textContent = createSignDoc(accountNumber, address); | ||
| }; | ||
|
|
||
| window.setPath = (accountNumberInput: unknown) => { | ||
| const setPath = (accountNumberInput: unknown): void => { | ||
| assert(typeof accountNumberInput === "string"); | ||
| const accountNumber = Uint53.fromString(accountNumberInput).toNumber(); | ||
|
|
||
| const path = pathToString(paths[accountNumber]); | ||
| const pathInput = document.getElementById("path"); | ||
| const pathInput = getElement("path"); | ||
| pathInput.value = path; | ||
| }; | ||
|
|
||
| // This must be called by the user an cannot be done on load (see "TransportWebUSBGestureRequired"). | ||
| window.createSigner = async function createSigner(): Promise<LedgerSigner> { | ||
| const createSigner = async function createSigner(): Promise<LedgerSigner> { | ||
| const interactiveTimeout = 120_000; | ||
| const ledgerTransport = await TransportWebUSB.create(interactiveTimeout, interactiveTimeout); | ||
| return new LedgerSigner(ledgerTransport, { | ||
|
|
@@ -79,16 +82,16 @@ window.createSigner = async function createSigner(): Promise<LedgerSigner> { | |
| }); | ||
| }; | ||
|
|
||
| window.getAccounts = async function getAccounts(signer: LedgerSigner | undefined): Promise<void> { | ||
| const getAccounts = async function getAccounts(signer: LedgerSigner | undefined): Promise<void> { | ||
| if (signer === undefined) { | ||
| console.error("Please wait for transport to connect"); | ||
| return; | ||
| } | ||
| const accountNumberInput1 = document.getElementById("account-number1"); | ||
| const accountNumberInput2 = document.getElementById("account-number2"); | ||
| const addressInput = document.getElementById("address"); | ||
| const accountsDiv = document.getElementById("accounts"); | ||
| const signDocTextArea = document.getElementById("sign-doc"); | ||
| const accountNumberInput1 = getElement("account-number1"); | ||
| const accountNumberInput2 = getElement("account-number2"); | ||
| const addressInput = getElement("address"); | ||
| const accountsDiv = getElement("accounts"); | ||
| const signDocTextArea = getElement("sign-doc"); | ||
| accountsDiv.textContent = "Loading..."; | ||
|
|
||
| try { | ||
|
|
@@ -101,46 +104,48 @@ window.getAccounts = async function getAccounts(signer: LedgerSigner | undefined | |
| const accountNumber = 0; | ||
|
|
||
| // Show address block | ||
| accountNumberInput1.max = accounts.length - 1; | ||
| accountNumberInput1.value = accountNumber; | ||
| window.setPath(accountNumber.toString()); | ||
| accountNumberInput1.max = String(accounts.length - 1); | ||
| accountNumberInput1.value = String(accountNumber); | ||
| setPath(accountNumber.toString()); | ||
|
|
||
| // Sign block | ||
| accountNumberInput2.max = accounts.length - 1; | ||
| accountNumberInput2.value = accountNumber; | ||
| accountNumberInput2.max = String(accounts.length - 1); | ||
| accountNumberInput2.value = String(accountNumber); | ||
| const address = accounts[0].address; | ||
| addressInput.value = address; | ||
| signDocTextArea.textContent = createSignDoc(accountNumber, address); | ||
| } catch (error) { | ||
| console.error(error); | ||
| accountsDiv.textContent = error; | ||
| accountsDiv.textContent = String(error); | ||
| } | ||
| }; | ||
|
|
||
| window.showAddress = async function showAddress(signer: LedgerSigner | undefined): Promise<void> { | ||
| const showAddress = async function showAddress(signer: LedgerSigner | undefined): Promise<void> { | ||
| if (signer === undefined) { | ||
| console.error("Please wait for transport to connect"); | ||
| return; | ||
| } | ||
| const path = stringToPath(document.getElementById("path").value); | ||
| const path = stringToPath(getElement("path").value); | ||
| await signer.showAddress(path); | ||
| }; | ||
|
|
||
| window.sign = async function sign(signer: LedgerSigner | undefined): Promise<void> { | ||
| const sign = async function sign(signer: LedgerSigner | undefined): Promise<void> { | ||
| if (signer === undefined) { | ||
| console.error("Please wait for transport to connect"); | ||
| return; | ||
| } | ||
| const signatureDiv = document.getElementById("signature"); | ||
| const signatureDiv = getElement("signature"); | ||
| signatureDiv.textContent = "Loading..."; | ||
|
|
||
| try { | ||
| const address = document.getElementById("address").value; | ||
| const signDocJson = document.getElementById("sign-doc").textContent; | ||
| const address = getElement("address").value; | ||
| const signDocJson = getElement("sign-doc").textContent; | ||
| const signDoc: StdSignDoc = JSON.parse(signDocJson); | ||
| const signature = await signer.signAmino(address, signDoc); | ||
| signatureDiv.textContent = JSON.stringify(signature, null, "\t"); | ||
| } catch (error) { | ||
| signatureDiv.textContent = error; | ||
| signatureDiv.textContent = String(error); | ||
| } | ||
| }; | ||
|
|
||
| Object.assign(window, { updateMessage, setPath, createSigner, getAccounts, showAddress, sign }); | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Here we can also use the solution from the other
getAccountimplementation:It avoids the
anytype and uses unknown instead. Any preference?