Skip to content

Commit

Permalink
Merge pull request #272 from fracek/add-keplr
Browse files Browse the repository at this point in the history
feat: support keplr wallet
  • Loading branch information
fracek authored Oct 17, 2024
2 parents 9b27451 + 14d4ed1 commit 09d7710
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-spies-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@starknet-io/get-starknet-core": patch
---

Add keplr wallet
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
- ⚙️ Customizable and extensible
- 🌍 Open source and controlled by the community


## Installation

```
Expand All @@ -24,7 +23,8 @@ yarn add @starknet-io/get-starknet starknet@next
pnpm add @starknet-io/get-starknet starknet@next
```

Read more about the new Starkent Dapp<>Wallet API in the [post](https://community.starknet.io/t/new-starknet-wallet-dapp-api/114295)
Read more about the new Starkent Dapp<>Wallet API in the
[post](https://community.starknet.io/t/new-starknet-wallet-dapp-api/114295)

## Usage for dApp developers

Expand Down
26 changes: 20 additions & 6 deletions packages/core/src/__test__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { mockStorageFunction } from "./storage.mock"
import {
ArgentXMock,
BraavosMock,
KeplrMock,
OKXMock,
UnknownWalletAMock,
UnknownWalletBMock,
makeAuthorized,
Expand Down Expand Up @@ -31,11 +33,15 @@ describe("getAvailableWallets()", () => {
},
starknet: ArgentXMock,
"starknet-braavos": BraavosMock,
starknet_okxwallet: OKXMock,
starknet_keplr: KeplrMock,
})
const availableWallets = await sn.getAvailableWallets()
expect(availableWallets.length).toBe(2)
expect(availableWallets.length).toBe(4)
expect(availableWallets).toContainEqual(ArgentXMock)
expect(availableWallets).toContainEqual(BraavosMock)
expect(availableWallets).toContainEqual(OKXMock)
expect(availableWallets).toContainEqual(KeplrMock)
})
it("should return one injected wallet", async () => {
const sn = getWallet({
Expand Down Expand Up @@ -110,16 +116,22 @@ describe("getAuthorizedWallets()", () => {
const sn = getWallet({
"starknet-argent": makeAuthorized(true)(ArgentXMock),
"starknet-braavos": makeAuthorized(true)(BraavosMock),
starknet_okxwallet: makeAuthorized(true)(OKXMock),
starknet_keplr: makeAuthorized(true)(KeplrMock),
})
const authorizedWallets = await sn.getAuthorizedWallets()
expect(authorizedWallets.length).toBe(2)
expect(authorizedWallets.map((w) => w.id)).contains(ArgentXMock.id)
expect(authorizedWallets.map((w) => w.id)).contains(BraavosMock.id)
const preauthorizedWallets = await sn.getAuthorizedWallets()
expect(preauthorizedWallets.length).toBe(4)
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)
})
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),
})
const authorizedWallets = await sn.getAuthorizedWallets()
expect(authorizedWallets.length).toBe(1)
Expand All @@ -131,8 +143,10 @@ describe("getDiscoveryWallets()", () => {
it("should return all discovery wallets", async () => {
const sn = getWallet({})
const discoveryWallets = await sn.getDiscoveryWallets()
expect(discoveryWallets.length).toBe(3)
expect(discoveryWallets.length).toBe(5)
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)
})
})
14 changes: 14 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,8 @@ import { mockStorageFunction } from "./storage.mock"
import {
ArgentXMock,
BraavosMock,
KeplrMock,
OKXMock,
UnknownWalletAMock,
UnknownWalletBMock,
makeAuthorized,
Expand Down Expand Up @@ -48,6 +50,8 @@ describe("getLastConnectedWallet()", () => {
{
"starknet-argentX": makeAuthorized(false)(ArgentXMock),
"starknet-braavos": makeAuthorized(false)(BraavosMock),
starknet_okxwallet: makeAuthorized(false)(OKXMock),
starknet_keplr: makeAuthorized(false)(KeplrMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand All @@ -61,6 +65,8 @@ describe("getLastConnectedWallet()", () => {
{
"starknet-argentX": makeAuthorized(false)(ArgentXMock),
"starknet-braavos": makeAuthorized(true)(BraavosMock),
starknet_okxwallet: makeAuthorized(false)(OKXMock),
starknet_keplr: makeAuthorized(false)(KeplrMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand All @@ -74,6 +80,8 @@ describe("getLastConnectedWallet()", () => {
{
"starknet-argentX": makeAuthorized(true)(ArgentXMock),
"starknet-braavos": makeAuthorized(true)(BraavosMock),
starknet_okxwallet: makeAuthorized(true)(OKXMock),
starknet_keplr: makeAuthorized(true)(KeplrMock),
},
mockStorageFunction({ "gsw-last": "braavos" }),
)
Expand All @@ -84,6 +92,8 @@ describe("getLastConnectedWallet()", () => {
const sn = getWallet({
"starknet-argentX": makeConnected(true)(ArgentXMock),
"starknet-braavos": makeConnected(true)(BraavosMock),
starknet_okxwallet: makeConnected(true)(OKXMock),
starknet_keplr: makeAuthorized(true)(KeplrMock),
})
const lastConnectedWallet = await sn.getLastConnectedWallet()
expect(lastConnectedWallet).toBe(null)
Expand All @@ -108,6 +118,8 @@ describe("getLastConnectedWallet()", () => {
{
"starknet-argentX": makeAuthorized(true)(ArgentXMock),
"starknet-braavos": makeAuthorized(true)(BraavosMock),
starknet_okxwallet: makeAuthorized(true)(OKXMock),
starknet_keplr: makeAuthorized(true)(KeplrMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand All @@ -125,6 +137,8 @@ describe("getLastConnectedWallet()", () => {
{
"starknet-argentX": makeAuthorized(true)(ArgentXMock),
"starknet-braavos": makeAuthorized(true)(BraavosMock),
starknet_okxwallet: makeAuthorized(true)(OKXMock),
starknet_keplr: makeAuthorized(true)(KeplrMock),
},
mockStorageFunction({
"gsw-last": "braavos",
Expand Down
30 changes: 30 additions & 0 deletions packages/core/src/__test__/wallet.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,36 @@ export const BraavosMock: StarknetWindowObject = {
off: () => {},
}

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

export const KeplrMock: StarknetWindowObject = {
...wallets.find((w) => w.id === "keplr")!,
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
Loading

0 comments on commit 09d7710

Please sign in to comment.