- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #188 from palladians/feat/implement-web-connector-…
…events feat(web connector): add events emitting
Showing
43 changed files
with
657 additions
and
713 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version = 1 | ||
|
||
[[analyzers]] | ||
name = "javascript" | ||
|
||
[analyzers.meta] | ||
plugins = ["react"] | ||
environment = [ | ||
"browser", | ||
"vitest" | ||
] |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/public/rpc.js | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { OnMessageCallback } from "webext-bridge" | ||
|
||
export type Handler = OnMessageCallback<any, any> | ||
export * from "./web-provider" | ||
export * from "./wallet" | ||
|
||
export const opts = { | ||
projectId: "test", | ||
chains: ["Mainnet"], | ||
} |
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,48 @@ | ||
import { useVault } from "@palladxyz/vault" | ||
import type { NetworkName } from "@palladxyz/vault" | ||
import { MinaProvider } from "@palladxyz/web-provider" | ||
import { serializeError } from "serialize-error" | ||
import type { Handler } from "./" | ||
|
||
export const palladSidePanel: Handler = async ({ sender }) => { | ||
await chrome.sidePanel.open({ | ||
tabId: sender.tabId, | ||
}) | ||
} | ||
|
||
export const palladSwitchNetwork: Handler = async ({ data }) => { | ||
try { | ||
const provider = await MinaProvider.getInstance() | ||
await useVault.persist.rehydrate() | ||
const { switchNetwork, getChainId } = useVault.getState() | ||
const network = data.network as NetworkName | ||
await switchNetwork(network) | ||
await useVault.persist.rehydrate() | ||
const chainId = await getChainId() | ||
provider.emit("pallad_event", { | ||
data: { | ||
chainId: chainId, | ||
}, | ||
type: "chainChanged", | ||
}) | ||
} catch (error) { | ||
return { error: serializeError(error) } | ||
} | ||
} | ||
|
||
export const palladConnected: Handler = async () => { | ||
try { | ||
const provider = await MinaProvider.getInstance() | ||
await useVault.persist.rehydrate() | ||
const { getChainId } = useVault.getState() | ||
const chainId = await getChainId() | ||
provider.emit("pallad_event", { | ||
data: { | ||
chainId: chainId, | ||
}, | ||
type: "connect", | ||
}) | ||
} catch (error) { | ||
return { error: serializeError(error) } | ||
} | ||
} |
Oops, something went wrong.