-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: removed
isPreauthorized
, selectedAddress
, chainId
, `isCo…
…nnected`
- Loading branch information
Showing
12 changed files
with
212 additions
and
163 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
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 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,45 +1,72 @@ | ||
import type { StarknetWindowObject } from "../StarknetWindowObject" | ||
import { Permission, StarknetWindowObject } from "../StarknetWindowObject" | ||
import wallets from "../discovery" | ||
|
||
type WalletMock = Pick< | ||
StarknetWindowObject, | ||
"id" | "name" | "icon" | "isPreauthorized" | ||
> | ||
type WalletMock = Pick<StarknetWindowObject, "id" | "name" | "icon" | "request"> | ||
|
||
export const UnknownWalletAMock: WalletMock = { | ||
id: "wallet-a", | ||
name: "Wallet A", | ||
icon: "https://avatars.dicebear.com/api/initials/Wallet%20A.svg", | ||
isPreauthorized: async () => false, | ||
request: async () => false, | ||
} | ||
export const UnknownWalletBMock: WalletMock = { | ||
id: "wallet-b", | ||
name: "Wallet B", | ||
icon: "https://avatars.dicebear.com/api/initials/Wallet%20B.svg", | ||
isPreauthorized: async () => false, | ||
request: async () => false, | ||
} | ||
|
||
export const ArgentXMock: WalletMock = { | ||
...wallets.find((w) => w.id === "argentX")!, | ||
isPreauthorized: async () => false, | ||
request: async (request) => { | ||
switch (request.type) { | ||
case "wallet_getPermissions": | ||
return [] | ||
default: | ||
return undefined as any | ||
} | ||
}, | ||
} | ||
|
||
export const BraavosMock: WalletMock = { | ||
...wallets.find((w) => w.id === "braavos")!, | ||
isPreauthorized: async () => false, | ||
request: async (request) => { | ||
switch (request.type) { | ||
case "wallet_getPermissions": | ||
return [] | ||
default: | ||
return undefined as any | ||
} | ||
}, | ||
} | ||
|
||
export function makePreAuthorized(isPreauthorized: boolean) { | ||
return (wallet: WalletMock) => ({ | ||
...wallet, | ||
isPreauthorized: async () => isPreauthorized, | ||
}) | ||
export function makeAuthorized(authorized: boolean) { | ||
return (wallet: WalletMock) => | ||
({ | ||
...wallet, | ||
request: async (request) => { | ||
switch (request.type) { | ||
case "wallet_getPermissions": | ||
return authorized ? [Permission.Accounts] : [] | ||
default: | ||
return wallet.request(request) | ||
} | ||
}, | ||
} as WalletMock) | ||
} | ||
|
||
export function makeConnected(isConnected: boolean) { | ||
return (wallet: WalletMock) => ({ | ||
...makePreAuthorized(true)(wallet), | ||
request: async () => [], | ||
isConnected, | ||
}) | ||
return (wallet: WalletMock) => { | ||
return { | ||
...makeAuthorized(true)(wallet), | ||
request: async ({ type }) => { | ||
switch (type) { | ||
case "wallet_getPermissions": | ||
return isConnected ? [Permission.Accounts] : [] | ||
default: | ||
return [] | ||
} | ||
}, | ||
} as WalletMock | ||
} | ||
} |
Oops, something went wrong.