-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7b71c6
commit 183aae3
Showing
13 changed files
with
2,712 additions
and
320 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,93 @@ | ||
import { createAppKit } from "@reown/appkit"; | ||
import { EthersAdapter } from "@reown/appkit-adapter-ethers"; | ||
import { BrowserProvider } from "ethers"; | ||
import log from "loglevel"; | ||
import { createEffect, createMemo } from "solid-js"; | ||
|
||
import { config } from "../config"; | ||
import { RBTC } from "../consts/Assets"; | ||
import { useWeb3Signer } from "../context/Web3"; | ||
import WalletConnectProvider from "../utils/WalletConnectProvider"; | ||
|
||
// 1. Get projectId | ||
const projectId = "ba2fd40da144b7017436e42851ec62ae"; | ||
|
||
// 3. Create a metadata object - optional | ||
const metadata = { | ||
name: "Boltz Testnet", | ||
description: "AppKit Example", | ||
url: "https://webapp-mainnet-git-wallet-connect-boltz.vercel.app/", // origin must match your domain & subdomain | ||
icons: [ | ||
"https://raw.githubusercontent.com/BoltzExchange/logo/refs/heads/master/boltz-logo_circle_1024x1024.png", | ||
], | ||
}; | ||
|
||
export const WalletConnect = () => { | ||
const { openWalletConnectModal, setOpenWalletConnectModal } = | ||
useWeb3Signer(); | ||
|
||
const appKit = createMemo(() => { | ||
const configRsk = config.assets[RBTC]; | ||
|
||
return createAppKit({ | ||
adapters: [new EthersAdapter()], | ||
networks: [ | ||
{ | ||
id: configRsk.network.chainId, | ||
name: configRsk.network.chainName, | ||
nativeCurrency: { | ||
name: RBTC, | ||
symbol: RBTC, | ||
decimals: 18, | ||
}, | ||
rpcUrls: { | ||
default: { | ||
http: configRsk.network.rpcUrls, | ||
}, | ||
}, | ||
blockExplorers: { | ||
default: { | ||
name: "Explorer", | ||
url: configRsk.blockExplorerUrl.normal, | ||
}, | ||
}, | ||
}, | ||
], | ||
metadata, | ||
projectId, | ||
themeMode: "dark", | ||
debug: true, | ||
enableEIP6963: false, | ||
enableInjected: false, | ||
features: { | ||
email: false, | ||
socials: false, | ||
analytics: true, | ||
}, | ||
}); | ||
}); | ||
|
||
appKit().subscribeEvents(async (ev) => { | ||
Check warning on line 70 in src/components/WalletConnect.tsx GitHub Actions / ci
|
||
log.debug(`WalletConnect event: ${ev.data.event}`); | ||
|
||
if (ev.data.event !== "MODAL_CLOSE") { | ||
setOpenWalletConnectModal(false); | ||
return; | ||
} | ||
|
||
const address = appKit().getAddress(); | ||
const provider = new BrowserProvider( | ||
await appKit().getUniversalProvider(), | ||
); | ||
|
||
WalletConnectProvider.resolveClosePromise(provider, address); | ||
}); | ||
|
||
createEffect(() => { | ||
if (openWalletConnectModal()) { | ||
appKit().open().then(); | ||
} | ||
}); | ||
|
||
return <></>; | ||
}; |
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
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,66 @@ | ||
import type { BrowserProvider } from "ethers"; | ||
import { Setter } from "solid-js"; | ||
|
||
import { EIP1193Provider } from "../consts/Types"; | ||
|
||
class WalletConnectProvider implements EIP1193Provider { | ||
private static provider: BrowserProvider; | ||
private static openModal: Setter<boolean>; | ||
private static closePromiseResolver: { | ||
resolve: (addresses: string[]) => void; | ||
reject: (reason?: any) => void; | ||
}; | ||
|
||
constructor() {} | ||
|
||
public static setOpenModal = (openModal: Setter<boolean>) => { | ||
WalletConnectProvider.openModal = openModal; | ||
}; | ||
|
||
public static resolveClosePromise = ( | ||
provider: BrowserProvider, | ||
address: string, | ||
) => { | ||
if (WalletConnectProvider.closePromiseResolver === undefined) { | ||
return; | ||
} | ||
if (address === undefined) { | ||
WalletConnectProvider.closePromiseResolver.reject( | ||
"No wallet connected", | ||
); | ||
} else { | ||
WalletConnectProvider.provider = provider; | ||
WalletConnectProvider.closePromiseResolver.resolve([address]); | ||
} | ||
|
||
WalletConnectProvider.closePromiseResolver = undefined; | ||
}; | ||
|
||
public request = async (request: { | ||
method: string; | ||
params?: Array<unknown>; | ||
}) => { | ||
switch (request.method) { | ||
case "eth_requestAccounts": { | ||
WalletConnectProvider.openModal(true); | ||
return new Promise<string[]>((resolve, reject) => { | ||
WalletConnectProvider.closePromiseResolver = { | ||
resolve, | ||
reject, | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
return (await WalletConnectProvider.provider.send( | ||
request.method, | ||
request.params, | ||
)) as never; | ||
}; | ||
|
||
public on = () => {}; | ||
|
||
public removeAllListeners = () => {}; | ||
} | ||
|
||
export default WalletConnectProvider; |