Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support okx wallet ext download #202

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/core/src/__test__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { mockStorageFunction } from "./storage.mock"
import {
ArgentXMock,
BraavosMock,
OKXMock,
UnknownWalletAMock,
UnknownWalletBMock,
makePreAuthorized,
Expand Down Expand Up @@ -31,11 +32,13 @@ describe("getAvailableWallets()", () => {
},
starknet: ArgentXMock,
"starknet-braavos": BraavosMock,
starknet_okxwallet: OKXMock,
})
const availableWallets = await sn.getAvailableWallets()
expect(availableWallets.length).toBe(2)
expect(availableWallets.length).toBe(3)
expect(availableWallets).toContainEqual(ArgentXMock)
expect(availableWallets).toContainEqual(BraavosMock)
expect(availableWallets).toContainEqual(OKXMock)
})
it("should return one injected wallet", async () => {
const sn = getWallet({
Expand Down Expand Up @@ -110,16 +113,19 @@ describe("getPreAuthorizedWallets()", () => {
const sn = getWallet({
"starknet-argent": makePreAuthorized(true)(ArgentXMock),
"starknet-braavos": makePreAuthorized(true)(BraavosMock),
starknet_okxwallet: makePreAuthorized(true)(OKXMock),
})
const preauthorizedWallets = await sn.getPreAuthorizedWallets()
expect(preauthorizedWallets.length).toBe(2)
expect(preauthorizedWallets.length).toBe(3)
expect(preauthorizedWallets.map((w) => w.id)).contains(ArgentXMock.id)
expect(preauthorizedWallets.map((w) => w.id)).contains(BraavosMock.id)
expect(preauthorizedWallets.map((w) => w.id)).contains(OKXMock.id)
})
it("should return one preauthorized wallet", async () => {
const sn = getWallet({
"starknet-argent": makePreAuthorized(true)(ArgentXMock),
"starknet-braavos": makePreAuthorized(false)(BraavosMock),
starknet_okxwallet: makePreAuthorized(false)(OKXMock),
})
const preauthorizedWallets = await sn.getPreAuthorizedWallets()
expect(preauthorizedWallets.length).toBe(1)
Expand All @@ -131,8 +137,9 @@ describe("getDiscoveryWallets()", () => {
it("should return all discovery wallets", async () => {
const sn = getWallet({})
const discoveryWallets = await sn.getDiscoveryWallets()
expect(discoveryWallets.length).toBe(2)
expect(discoveryWallets.length).toBe(3)
expect(discoveryWallets.map((w) => w.id)).contains(ArgentXMock.id)
expect(discoveryWallets.map((w) => w.id)).contains(BraavosMock.id)
expect(discoveryWallets.map((w) => w.id)).contains(OKXMock.id)
})
})
7 changes: 7 additions & 0 deletions packages/core/src/__test__/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { mockStorageFunction } from "./storage.mock"
import {
ArgentXMock,
BraavosMock,
OKXMock,
UnknownWalletAMock,
UnknownWalletBMock,
makeConnected,
Expand Down Expand Up @@ -48,6 +49,7 @@ describe("getLastConnectedWallet()", () => {
{
"starknet-argentX": makePreAuthorized(false)(ArgentXMock),
"starknet-braavos": makePreAuthorized(false)(BraavosMock),
starknet_okxwallet: makePreAuthorized(false)(OKXMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand All @@ -61,6 +63,7 @@ describe("getLastConnectedWallet()", () => {
{
"starknet-argentX": makePreAuthorized(false)(ArgentXMock),
"starknet-braavos": makePreAuthorized(true)(BraavosMock),
starknet_okxwallet: makePreAuthorized(false)(OKXMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand All @@ -74,6 +77,7 @@ describe("getLastConnectedWallet()", () => {
{
"starknet-argentX": makePreAuthorized(true)(ArgentXMock),
"starknet-braavos": makePreAuthorized(true)(BraavosMock),
starknet_okxwallet: makePreAuthorized(true)(OKXMock),
},
mockStorageFunction({ "gsw-last": "braavos" }),
)
Expand All @@ -84,6 +88,7 @@ describe("getLastConnectedWallet()", () => {
const sn = getWallet({
"starknet-argentX": makeConnected(true)(ArgentXMock),
"starknet-braavos": makeConnected(true)(BraavosMock),
starknet_okxwallet: makeConnected(true)(OKXMock),
})
const lastConnectedWallet = await sn.getLastConnectedWallet()
expect(lastConnectedWallet).toBe(null)
Expand All @@ -108,6 +113,7 @@ describe("getLastConnectedWallet()", () => {
{
"starknet-argentX": makePreAuthorized(true)(ArgentXMock),
"starknet-braavos": makePreAuthorized(true)(BraavosMock),
starknet_okxwallet: makePreAuthorized(true)(OKXMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand All @@ -125,6 +131,7 @@ describe("getLastConnectedWallet()", () => {
{
"starknet-argentX": makePreAuthorized(true)(ArgentXMock),
"starknet-braavos": makePreAuthorized(true)(BraavosMock),
starknet_okxwallet: makePreAuthorized(true)(OKXMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/__test__/wallet.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export const BraavosMock: WalletMock = {
isPreauthorized: async () => false,
}

export const OKXMock: WalletMock = {
...wallets.find((w) => w.id === "okxwallet")!,
isPreauthorized: async () => false,
}

export function makePreAuthorized(isPreauthorized: boolean) {
return (wallet: WalletMock) => ({
...wallet,
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type WalletProvider = {
| { chrome?: `https://chrome.google.com/webstore/detail/${string}` }
| { firefox?: `https://addons.mozilla.org/en-US/firefox/addon/${string}` }
| { edge?: `https://microsoftedge.microsoft.com/addons/detail/${string}` }
| { safari?: `https://apps.apple.com/us/app/${string}` }
}

const wallets: WalletProvider[] = [
Expand All @@ -31,6 +32,18 @@ const wallets: WalletProvider[] = [
edge: "https://microsoftedge.microsoft.com/addons/detail/braavos-wallet/hkkpjehhcnhgefhbdcgfkeegglpjchdc",
},
},
{
id: "okxwallet",
name: "OKX Wallet",
icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJDSURBVHgB7Zq9jtpAEMfHlhEgQLiioXEkoAGECwoKxMcTRHmC5E3IoyRPkPAEkI7unJYmTgEFTYwA8a3NTKScLnCHN6c9r1e3P2llWQy7M/s1Gv1twCP0ej37dDq9x+Zut1t3t9vZjDEHIiSRSPg4ZpDL5fxkMvn1cDh8m0wmfugfO53OoFQq/crn8wxfY9EymQyrVCqMfHvScZx1p9ls3pFxXBy/bKlUipGPrVbLuQqAfsCliq3zl0H84zwtjQrOw4Mt1W63P5LvBm2d+Xz+YzqdgkqUy+WgWCy+Mc/nc282m4FqLBYL+3g8fjDxenq72WxANZbLJeA13zDX67UDioL5ybXwafMYu64Ltn3bdDweQ5R97fd7GyhBQMipx4POeEDHIu2LfDdBIGGz+hJ9CQ1ABjoA2egAZPM6AgiCAEQhsi/C4jHyPA/6/f5NG3Ks2+3CYDC4aTccDrn6ojG54MnEvG00GoVmWLIRNZ7wTCwDHYBsdACy0QHIhiuRETxlICWpMMhGZHmqS8qH6JLyGegAZKMDkI0uKf8X4SWlaZo+Pp1bRrwlJU8ZKLIvUjKh0WiQ3sRUbNVq9c5Ebew7KEo2m/1p4jJ4qAmDaqDQBzj5XyiAT4VCQezJigAU+IDU+z8vJFnGWeC+bKQV/5VZ71FV6L7PA3gg3tXrdQ+DgLhC+75Wq3no69P3MC0NFQpx2lL04Ql9gHK1bRDjsSBIvScBnDTk1WrlGIZBorIDEYJj+rhdgnQ67VmWRe0zlplXl81vcyEt0rSoYDUAAAAASUVORK5CYII=",
downloads: {
chrome:
"https://chrome.google.com/webstore/detail/mcohilncbfahbmgdjkbpemcciiolgcge",
firefox: "https://addons.mozilla.org/en-US/firefox/addon/okexwallet",
edge: "https://microsoftedge.microsoft.com/addons/detail/%E6%AC%A7%E6%98%93-web3-%E9%92%B1%E5%8C%85/pbpjkcldjiffchgbbndmhojiacbgflha",
safari: "https://apps.apple.com/us/app/okx-wallet/id6463797825",
},
},
]

export default wallets
4 changes: 3 additions & 1 deletion packages/ui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import sn, {

export type { StarknetWindowObject, DisconnectOptions } from "get-starknet-core"

type StoreVersion = "chrome" | "firefox" | "edge"
type StoreVersion = "chrome" | "firefox" | "edge" | "safari"

const ssrSafeWindow = typeof window !== "undefined" ? window : null

Expand All @@ -28,6 +28,8 @@ function getStoreVersionFromBrowser(): StoreVersion | null {
case "opera": // opera is chromium based
case "vivaldi": // vivaldi is chromium based
return "chrome"
case "safari":
return "safari"
default:
return null
}
Expand Down
Loading