Skip to content

Instantly share code, notes, and snippets.

@molekilla
Created April 23, 2020 14:01
Show Gist options
  • Save molekilla/59cb5c011902354bbae0caf79bd7a510 to your computer and use it in GitHub Desktop.
Save molekilla/59cb5c011902354bbae0caf79bd7a510 to your computer and use it in GitHub Desktop.
onboard.js
//1 ) Instancia Onboard.js
this.onboard = Onboard({
dappId: (Vue as any).appconfig.BLOCKNATIVE_API_KEY,
networkId: this.defaultNetwork,
subscriptions: this.onboardSync,
walletSelect: undefined,
walletCheck: undefined
});
// Si no tiene wallet, muestra una pagina para que instale wallet
if (!(window as any).ethereum) {
this.$router.push({ path: "onboard" });
// Si no lo ha usado antes, debe seleccionar como acceder (walletconnect, otros)
} else if (localStorage.getItem("selectedWallet") === null) {
// display onboard.js
const hasSelected = await this.onboard.walletSelect();
if (!hasSelected) {
// Si no selecciono muestra un error o mantenlo en esa pagina
} else {
const self = this;
const init = await this.onboard.walletCheck();
// Si selecciono, carga tu web3 y otros
setTimeout(async () => {
const props = await (self as any).$loadOnchainDependencies({
networkId: self.onboard.getState().network,
account: self.onboard.getState().address
});
SolidoSingleton.setProps(props);
self.canInit = init;
self.$router.push({ path: "client" });
}, 800);
}
} else {
// Si previamente lo uso, carga su preferencia
const previouslySelectedWallet = window.localStorage.getItem(
"selectedWallet"
);
// call wallet select with that value if it exists
if (previouslySelectedWallet != null) {
await this.onboard.walletSelect(previouslySelectedWallet);
}
const props = await (this as any).$loadOnchainDependencies({
networkId: this.network,
account: this.address
});
await (window as any).ethereum.enable();
SolidoSingleton.setProps(props);
this.canInit = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment