-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
308 additions
and
166 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 +1,31 @@ | ||
# Getting Started [Start with MinaJS Connect.] | ||
|
||
## Installation | ||
|
||
```sh | ||
$ npm install @mina-js/connect | ||
``` | ||
|
||
### Nightly builds | ||
|
||
```sh | ||
$ npm install https://pkg.pr.new/palladians/mina-js/@mina-js/connect@main | ||
``` | ||
|
||
:::warning | ||
For now there are only [nightly builds](/getting-started#nightly-builds) available. The stable version will be released soon™️. | ||
::: | ||
|
||
## Find Mina wallets | ||
|
||
To discover injected wallet providers, we've developed a Provider Discovery reactive store utility. [Check out the usage](/connect/provider-discovery). | ||
|
||
## Window Polyfill | ||
|
||
For your convenient TypeScript development, we've created a window polyfill. This will make sure you have an autocompletion for MinaJS compliant providers. | ||
|
||
```ts | ||
import '@mina-js/connect/window' | ||
|
||
const account = await window.mina.request({ method: 'mina_accounts' }) | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Provider Discovery [Discover injected wallet providers with ease.] | ||
|
||
For your convenience, MinaJS Connect provides a simple way to discover all Mina's injected wallet providers. This is done by an API similar to [Wevm's MIPD](https://github.com/wevm/mipd). | ||
|
||
## Vanilla TypeScript | ||
|
||
```ts twoslash | ||
import { createStore, type MinaProviderDetail } from '@mina-js/connect' | ||
|
||
const store = createStore() | ||
|
||
// Reactively, you can use MinaProviderDetail to type the array, but it fails in docs ffs. | ||
const providersReactively = [] | ||
const unsubscribe = store.subscribe((provider) => providersReactively.push(provider)) | ||
|
||
// Imperatively | ||
const providersImperatively = store.getProviders() | ||
``` | ||
|
||
## React | ||
|
||
```tsx twoslash | ||
import { useSyncExternalStore } from 'react' | ||
import { createStore } from '@mina-js/connect' | ||
|
||
const store = createStore() | ||
|
||
function Example() { | ||
const providers = useSyncExternalStore(store.subscribe, store.getProviders) | ||
} | ||
``` | ||
|
||
## Svelte | ||
|
||
```svelte twoslash | ||
<script lang="ts"> | ||
import { readable } from 'svelte/store' | ||
import { createStore } from '@mina-js/connect' | ||
const store = createStore() | ||
const providers = readable(store.getProviders(), store.subscribe) | ||
</script> | ||
``` | ||
|
||
## Vue | ||
|
||
```vue twoslash | ||
<script setup lang="ts"> | ||
import { reactive } from 'vue' | ||
import { createStore } from '@mina-js/connect' | ||
const store = createStore() | ||
const state = reactive({ providers: store.getProviders() }) | ||
store.subscribe(providers => (state.providers = providers)) | ||
</script> | ||
``` |
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Bun Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should initialize the store 1`] = ` | ||
{ | ||
"_listeners": [Function: _listeners], | ||
"clear": [Function: clear], | ||
"destroy": [Function: destroy], | ||
"findProvider": [Function: findProvider], | ||
"getProviders": [Function: getProviders], | ||
"reset": [Function: reset], | ||
"subscribe": [Function: subscribe], | ||
} | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { | ||
MinaAnnounceProviderEvent, | ||
MinaProviderClient, | ||
MinaRequestProviderEvent, | ||
} from "@mina-js/providers"; | ||
|
||
declare global { | ||
interface WindowEventMap { | ||
"mina:announceProvider": MinaAnnounceProviderEvent; | ||
"mina:requestProvider": MinaRequestProviderEvent; | ||
} | ||
interface Window { | ||
mina?: MinaProviderClient | undefined; | ||
} | ||
} |
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,18 +1,3 @@ | ||
import type { | ||
MinaAnnounceProviderEvent, | ||
MinaProviderClient, | ||
MinaRequestProviderEvent, | ||
} from "@mina-js/providers"; | ||
|
||
declare global { | ||
interface WindowEventMap { | ||
"mina:announceProvider": MinaAnnounceProviderEvent; | ||
"mina:requestProvider": MinaRequestProviderEvent; | ||
} | ||
interface Window { | ||
mina?: MinaProviderClient | undefined; | ||
} | ||
} | ||
|
||
export * from "./store"; | ||
export * from "./events"; | ||
export type { MinaProviderDetail } from "@mina-js/providers"; |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { expect, it, mock } from "bun:test"; | ||
import { mockedProvider } from "./__mocks__/provider"; | ||
import { announceProvider } from "./events"; | ||
import { createStore } from "./store"; | ||
|
||
it("should initialize the store", () => { | ||
const store = createStore(); | ||
expect(store).toMatchSnapshot(); | ||
}); | ||
|
||
it("should update providers", () => { | ||
const store = createStore(); | ||
const listener = mock(); | ||
store.subscribe(listener); | ||
announceProvider(mockedProvider); | ||
const provider = store.getProviders()[0]; | ||
expect(listener).toHaveBeenCalled(); | ||
expect(provider).toEqual(mockedProvider); | ||
}); | ||
|
||
it("should unsubscribe from store", () => { | ||
const store = createStore(); | ||
const listener = mock(); | ||
const unsub = store.subscribe(listener); | ||
unsub(); | ||
announceProvider(mockedProvider); | ||
expect(listener).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("should clear providers list", () => { | ||
const store = createStore(); | ||
const listener = mock(); | ||
store.subscribe(listener); | ||
announceProvider(mockedProvider); | ||
store.clear(); | ||
const providers = store.getProviders(); | ||
expect(providers.length).toEqual(0); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { MinaProviderDetail } from "@mina-js/providers"; | ||
import { match } from "ts-pattern"; | ||
|
||
export const unito = (provider: MinaProviderDetail) => { | ||
return match(provider) | ||
.with({ info: { slug: "auro" } }, (provider) => { | ||
return { | ||
...provider, | ||
provider: { | ||
...provider.provider, | ||
request: null, | ||
}, | ||
}; | ||
}) | ||
.otherwise((provider) => provider); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./global-polyfill"; |
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,3 +1,7 @@ | ||
import { defineConfig } from "tsup"; | ||
import sharedConfig from "../shared/tsup.config"; | ||
|
||
export default sharedConfig; | ||
export default defineConfig({ | ||
...sharedConfig, | ||
entry: ["./src/index.ts", "./src/window.ts"], | ||
}); |
Oops, something went wrong.