-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dcellar-web-ui): fix refresh page will logout issue (#166)
* fix(dcellar-web-ui): auto logout if wallet is locked * test(dcellar-web-ui): add wallet log * feat(dcellar-web-ui): add wallet log * test(dcellar-web-ui): add log * test(dcellar-web-ui): add log * test(dcellar-web-ui): add log * test: add log * test: add log * fix(dcellar-web-ui): fix refresh page will logout if using trust wallet * test: add log * test: test wallet * test: add log * test: add log * test: remove MetaMaskConnector * fix: customize MetaMaskConnector & TrustWalletConnector * test: add TrustWalletConnector connect method * refactor: fix wallet issue * fix(dcellar-web-ui): fix wallet issue * fix: remove wallet log * test: test * test: add log * fix: fix wallet issues * fix: remove logs * fix(dcellar-web-ui): remove unused dependencies
- Loading branch information
Showing
11 changed files
with
117 additions
and
31 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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
apps/dcellar-web-ui/src/context/WalletConnectContext/components/WalletConnectProvider.tsx
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
16 changes: 0 additions & 16 deletions
16
apps/dcellar-web-ui/src/context/WalletConnectContext/config/connectors.ts
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
apps/dcellar-web-ui/src/context/WalletConnectContext/connectors/MetaMaskConnector.ts
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,3 @@ | ||
import { MetaMaskConnector as WagmiMetaMaskConnector } from 'wagmi/connectors/metaMask'; | ||
|
||
export class MetaMaskConnector extends WagmiMetaMaskConnector {} |
72 changes: 72 additions & 0 deletions
72
apps/dcellar-web-ui/src/context/WalletConnectContext/connectors/TrustWalletConnector.ts
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,72 @@ | ||
import { Chain } from 'wagmi' | ||
import { MetaMaskConnector as WagmiMetaMaskConnector } from 'wagmi/connectors/metaMask'; | ||
import { | ||
getClient, | ||
} from '@wagmi/core' | ||
|
||
export type TrustWalletConnectorOptions = { | ||
shimDisconnect?: boolean | ||
} | ||
|
||
export class TrustWalletConnector extends WagmiMetaMaskConnector { | ||
readonly id: any = 'trustWallet'; | ||
|
||
constructor({ | ||
chains, | ||
options: _options, | ||
}: { | ||
chains?: Chain[] | ||
options?: TrustWalletConnectorOptions | ||
} = {}) { | ||
|
||
const options = { | ||
name: 'Trust Wallet', | ||
shimDisconnect: true, | ||
UNSTABLE_shimOnConnectSelectAccount: true, | ||
getProvider: getTrustWalletProvider, | ||
..._options, | ||
} | ||
|
||
super({ | ||
chains, | ||
options, | ||
}) | ||
} | ||
|
||
async disconnect() { | ||
super.disconnect() | ||
|
||
const provider: any = await this.getProvider() | ||
if (!provider?.off) return | ||
|
||
provider.off('accountsChanged', this.onAccountsChanged) | ||
provider.off('chainChanged', this.onChainChanged) | ||
provider.off('disconnect', this.onDisconnect) | ||
|
||
if (this.options.shimDisconnect) { | ||
getClient().storage?.removeItem(this.shimDisconnectKey) | ||
} | ||
} | ||
} | ||
|
||
export function getTrustWalletProvider() { | ||
const isTrustWallet = (ethereum: any) => { | ||
return !!ethereum.isTrust | ||
} | ||
|
||
const injectedProviderExist = typeof window !== 'undefined' && typeof window.ethereum !== 'undefined' | ||
|
||
if (!injectedProviderExist) { | ||
return | ||
} | ||
|
||
if (isTrustWallet(window.ethereum)) { | ||
return window.ethereum | ||
} | ||
|
||
if (window.ethereum?.providers) { | ||
return window.ethereum.providers.find(isTrustWallet) | ||
} | ||
|
||
return window.trustWallet | ||
} |
8 changes: 8 additions & 0 deletions
8
apps/dcellar-web-ui/src/context/WalletConnectContext/connectors/index.tsx
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,8 @@ | ||
import { chains } from '@/context/WalletConnectContext/chains'; | ||
import { MetaMaskConnector } from '@/context/WalletConnectContext/connectors/MetaMaskConnector'; | ||
import { TrustWalletConnector } from '@/context/WalletConnectContext/connectors/TrustWalletConnector'; | ||
|
||
const trustWalletConnector = new TrustWalletConnector({ chains }) | ||
const metaMaskConnector = new MetaMaskConnector({ chains }) | ||
|
||
export const connectors = [trustWalletConnector, metaMaskConnector]; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.