Skip to content

Commit

Permalink
Merge pull request #279 from danielbellmas/add-fordefi-develop
Browse files Browse the repository at this point in the history
feat: add fordefi wallet
  • Loading branch information
fracek authored Jan 8, 2025
2 parents 441a220 + c895e93 commit 08c4670
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
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,
FordefiMock,
KeplrMock,
OKXMock,
UnknownWalletAMock,
Expand Down Expand Up @@ -35,13 +36,15 @@ describe("getAvailableWallets()", () => {
"starknet-braavos": BraavosMock,
starknet_okxwallet: OKXMock,
starknet_keplr: KeplrMock,
starknet_fordefi: FordefiMock,
})
const availableWallets = await sn.getAvailableWallets()
expect(availableWallets.length).toBe(4)
expect(availableWallets.length).toBe(5)
expect(availableWallets).toContainEqual(ArgentXMock)
expect(availableWallets).toContainEqual(BraavosMock)
expect(availableWallets).toContainEqual(OKXMock)
expect(availableWallets).toContainEqual(KeplrMock)
expect(availableWallets).toContainEqual(FordefiMock)
})
it("should return one injected wallet", async () => {
const sn = getWallet({
Expand Down Expand Up @@ -118,20 +121,23 @@ describe("getAuthorizedWallets()", () => {
"starknet-braavos": makeAuthorized(true)(BraavosMock),
starknet_okxwallet: makeAuthorized(true)(OKXMock),
starknet_keplr: makeAuthorized(true)(KeplrMock),
starknet_fordefi: makeAuthorized(true)(FordefiMock),
})
const preauthorizedWallets = await sn.getAuthorizedWallets()
expect(preauthorizedWallets.length).toBe(4)
expect(preauthorizedWallets.length).toBe(5)
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)
expect(preauthorizedWallets.map((w) => w.id)).contains(KeplrMock.id)
expect(preauthorizedWallets.map((w) => w.id)).contains(FordefiMock.id)
})
it("should return one authorized wallet", async () => {
const sn = getWallet({
"starknet-argent": makeAuthorized(true)(ArgentXMock),
"starknet-braavos": makeAuthorized(false)(BraavosMock),
starknet_okxwallet: makeAuthorized(false)(OKXMock),
starknet_keplr: makeAuthorized(false)(KeplrMock),
starknet_fordefi: makeAuthorized(false)(FordefiMock),
})
const authorizedWallets = await sn.getAuthorizedWallets()
expect(authorizedWallets.length).toBe(1)
Expand All @@ -143,10 +149,11 @@ describe("getDiscoveryWallets()", () => {
it("should return all discovery wallets", async () => {
const sn = getWallet({})
const discoveryWallets = await sn.getDiscoveryWallets()
expect(discoveryWallets.length).toBe(5)
expect(discoveryWallets.length).toBe(6)
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)
expect(discoveryWallets.map((w) => w.id)).contains(KeplrMock.id)
expect(discoveryWallets.map((w) => w.id)).contains(FordefiMock.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,
FordefiMock,
KeplrMock,
OKXMock,
UnknownWalletAMock,
Expand Down Expand Up @@ -52,6 +53,7 @@ describe("getLastConnectedWallet()", () => {
"starknet-braavos": makeAuthorized(false)(BraavosMock),
starknet_okxwallet: makeAuthorized(false)(OKXMock),
starknet_keplr: makeAuthorized(false)(KeplrMock),
starknet_fordefi: makeAuthorized(false)(FordefiMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand All @@ -67,6 +69,7 @@ describe("getLastConnectedWallet()", () => {
"starknet-braavos": makeAuthorized(true)(BraavosMock),
starknet_okxwallet: makeAuthorized(false)(OKXMock),
starknet_keplr: makeAuthorized(false)(KeplrMock),
starknet_fordefi: makeAuthorized(false)(FordefiMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand All @@ -82,6 +85,7 @@ describe("getLastConnectedWallet()", () => {
"starknet-braavos": makeAuthorized(true)(BraavosMock),
starknet_okxwallet: makeAuthorized(true)(OKXMock),
starknet_keplr: makeAuthorized(true)(KeplrMock),
starknet_fordefi: makeAuthorized(true)(FordefiMock),
},
mockStorageFunction({ "gsw-last": "braavos" }),
)
Expand All @@ -94,6 +98,7 @@ describe("getLastConnectedWallet()", () => {
"starknet-braavos": makeConnected(true)(BraavosMock),
starknet_okxwallet: makeConnected(true)(OKXMock),
starknet_keplr: makeAuthorized(true)(KeplrMock),
starknet_fordefi: makeAuthorized(true)(FordefiMock),
})
const lastConnectedWallet = await sn.getLastConnectedWallet()
expect(lastConnectedWallet).toBe(null)
Expand All @@ -120,6 +125,7 @@ describe("getLastConnectedWallet()", () => {
"starknet-braavos": makeAuthorized(true)(BraavosMock),
starknet_okxwallet: makeAuthorized(true)(OKXMock),
starknet_keplr: makeAuthorized(true)(KeplrMock),
starknet_fordefi: makeAuthorized(true)(FordefiMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand All @@ -139,6 +145,7 @@ describe("getLastConnectedWallet()", () => {
"starknet-braavos": makeAuthorized(true)(BraavosMock),
starknet_okxwallet: makeAuthorized(true)(OKXMock),
starknet_keplr: makeAuthorized(true)(KeplrMock),
starknet_fordefi: makeAuthorized(true)(FordefiMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/__test__/wallet.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ export const KeplrMock: StarknetWindowObject = {
off: () => {},
}

export const FordefiMock: StarknetWindowObject = {
...wallets.find((w) => w.id === "fordefi")!,
version: "0.0.0",
request: async (request) => {
switch (request.type) {
case "wallet_getPermissions":
return []
default:
return undefined as any
}
},
on: () => {},
off: () => {},
}

export function makeAuthorized(authorized: boolean) {
return (wallet: StarknetWindowObject) =>
({
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ const wallets: WalletProvider[] = [
edge: "https://microsoftedge.microsoft.com/addons/detail/keplr/ocodgmmffbkkeecmadcijjhkmeohinei",
},
},
{
id: "fordefi",
name: "Fordefi",
icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzEzNDk0XzY2MjU0KSI+CjxwYXRoIGQ9Ik0xMC44NzY5IDE1LjYzNzhIMS41VjE4LjM5OUMxLjUgMTkuODAxMyAyLjYzNDQ3IDIwLjkzOCA0LjAzMzkyIDIwLjkzOEg4LjI0OTkyTDEwLjg3NjkgMTUuNjM3OFoiIGZpbGw9IiM3OTk0RkYiLz4KPHBhdGggZD0iTTEuNSA5Ljc3NTUxSDE5LjA1MTZMMTcuMDEzOSAxMy44NzExSDEuNVY5Ljc3NTUxWiIgZmlsbD0iIzQ4NkRGRiIvPgo8cGF0aCBkPSJNNy42NTk5NiAzSDEuNTI0NDFWOC4wMDcwNEgyMi40NjEyVjNIMTYuMzI1NlY2LjczOTQ0SDE1LjA2MDZWM0g4LjkyNTAyVjYuNzM5NDRINy42NTk5NlYzWiIgZmlsbD0iIzVDRDFGQSIvPgo8L2c+CjxkZWZzPgo8Y2xpcFBhdGggaWQ9ImNsaXAwXzEzNDk0XzY2MjU0Ij4KPHJlY3Qgd2lkdGg9IjIxIiBoZWlnaHQ9IjE4IiBmaWxsPSJ3aGl0ZSIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMS41IDMpIi8+CjwvY2xpcFBhdGg+CjwvZGVmcz4KPC9zdmc+Cg==",
downloads: {
chrome:
"https://chrome.google.com/webstore/detail/fordefi/hcmehenccjdmfbojapcbcofkgdpbnlle",
},
},
]

export default wallets

0 comments on commit 08c4670

Please sign in to comment.