feat: implement custom modals for no-webln error on mobile and web

Fixes #91
This commit is contained in:
MTG2000
2022-08-09 18:11:32 +03:00
parent 28eadcc1ff
commit f73e55377c
10 changed files with 236 additions and 130 deletions

View File

@@ -1,6 +1,7 @@
import { requestProvider, MissingProviderError, WebLNProvider } from 'webln';
import { store } from '../redux/store'
import { connectWallet as connectWalletStore } from '../redux/features/wallet.slice'
import { openModal } from 'src/redux/features/modals.slice';
class _Wallet_Service {
@@ -10,20 +11,19 @@ class _Wallet_Service {
async getWebln() {
if (!this.isConnected) await this.connectWallet();
return this.webln as WebLNProvider;
return this.webln;
}
init() {
const connectedPreviously = localStorage.getItem('wallet-connected')
if (connectedPreviously)
this.connectWallet();
// const connectedPreviously = localStorage.getItem('wallet-connected')
// if (connectedPreviously)
// this.connectWallet();
}
async connectWallet() {
try {
const webln = await requestProvider();
store.dispatch(connectWalletStore())
localStorage.setItem('wallet-connected', 'yes')
this.webln = webln;
this.isConnected = false;
}
@@ -35,11 +35,13 @@ class _Wallet_Service {
message = "Check out https://getalby.com to get a web enabled lightning wallet";
}
console.log(message);
localStorage.removeItem('wallet-connected')
// Show the error (though you should probably use something better than alert!)
alert(message);
store.dispatch(openModal({
Modal: "NoWeblnModal"
}))
}
}