Skip to content

Commit

Permalink
Merge pull request #188 from palladians/feat/implement-web-connector-…
Browse files Browse the repository at this point in the history
…events

feat(web connector): add events emitting
mrcnk authored Aug 5, 2024
2 parents 1246e61 + 0bf5e98 commit 0ce65dc
Showing 43 changed files with 657 additions and 713 deletions.
11 changes: 11 additions & 0 deletions .deepsource.toml
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"
]
2 changes: 2 additions & 0 deletions apps/extension/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/public/rpc.js

# Logs
logs
*.log
2 changes: 1 addition & 1 deletion apps/extension/manifest.ts
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ export const manifest: chrome.runtime.ManifestV3 = {
],
web_accessible_resources: [
{
resources: ["pallad_rpc.js"],
resources: ["rpc.js"],
matches: ["https://*/*"],
},
],
11 changes: 7 additions & 4 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build": "tsc && pnpm build:rpc && vite build",
"build:rpc": "tsup",
"build:firefox": "web-ext build --source-dir=dist",
"build:safari": "xcrun safari-web-extension-converter dist --app-name Pallad --bundle-identifier co.pallad.app --swift --no-prompt --force --macos-only --no-open",
"preview": "vite preview",
@@ -18,9 +19,11 @@
"@palladxyz/features": "workspace:*",
"@palladxyz/key-management": "workspace:*",
"@palladxyz/web-provider": "workspace:*",
"@palladxyz/vault": "workspace:*",
"@plasmohq/messaging": "0.6.2",
"buffer": "6.0.3",
"debounce": "^2.1.0",
"p-debounce": "4.0.0",
"mitt": "3.0.1",
"next-themes": "0.3.0",
"react": "18.3.1",
"react-dom": "18.3.1",
@@ -58,8 +61,8 @@
"vite-plugin-svgr": "4.2.0",
"vite-plugin-top-level-await": "1.4.2",
"vite-plugin-wasm": "3.3.0",
"vite-plugin-web-extension": "^4.1.6",
"vite-plugin-web-extension": "4.1.6",
"web-ext": "8.2.0",
"write-json-file": "^6.0.0"
"write-json-file": "6.0.0"
}
}
107 changes: 0 additions & 107 deletions apps/extension/public/pallad_rpc.js

This file was deleted.

10 changes: 10 additions & 0 deletions apps/extension/src/background/handlers/index.ts
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"],
}
48 changes: 48 additions & 0 deletions apps/extension/src/background/handlers/wallet.ts
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) }
}
}
Loading

0 comments on commit 0ce65dc

Please sign in to comment.