-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: begin porting Namada Keychain integration
- Loading branch information
Showing
9 changed files
with
116 additions
and
73 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
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,60 @@ | ||
import { Signer, WindowWithNamada } from "@namada/types"; | ||
import { ChainRegistryEntry } from "types"; | ||
import { Namada, WalletConnector } from "./types"; | ||
|
||
export class NamadaWalletManager implements WalletConnector { | ||
install(): void { | ||
console.warn( | ||
"Namada is not available. Redirecting to the Namada download page..." | ||
); | ||
window.open("https://www.namada.net/extension", "_blank"); | ||
} | ||
|
||
private async _get(): Promise<Namada | undefined> { | ||
if ((window as WindowWithNamada).namada) { | ||
return (window as WindowWithNamada).namada; | ||
} | ||
|
||
if (document.readyState === "complete") { | ||
return (window as WindowWithNamada).namada; | ||
} | ||
|
||
return new Promise<Namada | undefined>((resolve) => { | ||
const documentStateChange = (event: Event): void => { | ||
if ( | ||
event.target && | ||
(event.target as Document).readyState === "complete" | ||
) { | ||
resolve((window as WindowWithNamada).namada); | ||
document.removeEventListener("readystatechange", documentStateChange); | ||
} | ||
}; | ||
|
||
document.addEventListener("readystatechange", documentStateChange); | ||
}); | ||
} | ||
|
||
async get(): Promise<Namada> { | ||
const namada = await this._get(); | ||
return namada!; | ||
} | ||
|
||
async connect(registry: ChainRegistryEntry): Promise<void> { | ||
const namada = await this.get(); | ||
await namada.connect(registry.chain.chain_id); | ||
} | ||
|
||
async getAddress(): Promise<string> { | ||
const namada = await this.get(); | ||
const defaultAccount = await namada.defaultAccount(); | ||
if (!defaultAccount) { | ||
throw new Error("No accounts found in keychain!"); | ||
} | ||
return defaultAccount.address; | ||
} | ||
|
||
async getSigner(): Promise<Signer> { | ||
const namada = await this.get(); | ||
return namada.getSigner(); | ||
} | ||
} |
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
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