Skip to content

Commit

Permalink
fix: update readme and info
Browse files Browse the repository at this point in the history
  • Loading branch information
wiseaidev committed Jun 17, 2024
1 parent de36445 commit 87352bd
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 4 deletions.
175 changes: 172 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center">

# 📖 WASI SOL
# 🦀 wasi-sol

[![made-with-rust](https://img.shields.io/badge/Made%20with-Rust-1f425f.svg?logo=rust&logoColor=white)](https://www.rust-lang.org/)
[![Netlify Status](https://api.netlify.com/api/v1/badges/d7858d73-f54a-4d4f-878f-466168d8ea07/deploy-status)](https://app.netlify.com/sites/wasi-sol/deploys)
Expand All @@ -11,8 +11,177 @@
[![docs](https://docs.rs/wasi-sol/badge.svg)](https://docs.rs/wasi-sol/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

![WASI SOL Demo](https://github.com/wiseaidev/wasi-sol/assets/62179149/a3ddea79-935e-4692-8d2f-b63a22b05a02)
![WASI SOL Demo](https://github.com/wiseaidev/wasi-sol/assets/62179149/ed3668ef-6f18-4d74-a10d-5e1ae551c695)

</div>

💳 Connect and manage your Solana wallet seamlessly in wasm-based web application.
A Solana Wallet adapter for WASM frameworks.

## 🔒 Wallets Support

> [!NOTE]
> By default, this crate triggers all `EIP-1193` compatible wallets, but you can only connect and perform all actions listed below if it is Phantom wallet.
| Wallet | Supported | Features |
|-----------|-------------|-------------------|
| Phantom || All |
| Metamask || Wallet Connect Only |
| Solflare |||

## 🌐 Wasm Frameworks Support

| Framework | Supported |
|-----------|-------------|
| Yew ||
| Dioxus ||
| Leptos ||

## ⚙️ Features

| Method | Supported | Tested |
|-----------------------|-----------|--------|
| `connect` |||
| `disconnect` |||
| `send_transaction` |||
| `sign_message` |||
| `sign_transaction` |||
| `sign_all_transactions` |||
| `sign_in` |||

❌: TODO

## 🚀 Examples

In addition to the [`examples`](examples) directory, you can use the following snippet of code to add `wasi-sol` wallet adapter using its built-in providers and hooks:

```rust
use yew::prelude::*;

use wasi_sol::{
core::traits::WalletAdapter,
core::wallet::BaseWalletAdapter,
provider::{
connection::{use_connection, ConnectionProvider},
wallet::{use_wallet, WalletProvider},
},
spawn_local
};

#[function_component]
pub fn App() -> Html {
let endpoint = "https://api.mainnet-beta.solana.com";
let wallets = vec![BaseWalletAdapter::new(
"Phantom",
"https://phantom.app",
"phantom_icon_url",
)];

html! {
<ConnectionProvider {endpoint}>
<WalletProvider {endpoint} {wallets}>
<LoginPage />
</WalletProvider>
</ConnectionProvider>
}
}

#[function_component]
pub fn LoginPage() -> Html {
let _connection_context = use_connection();
let wallet_context = use_wallet();
let connected = use_state(|| false);
let wallet_adapter = use_state(|| wallet_context);

let wallet_info = (*wallet_adapter).clone();

let connect_wallet = {
let connected = connected.clone();
let wallet_adapter = wallet_adapter.clone();

Callback::from(move |_| {
let connected = connected.clone();
let wallet_adapter = wallet_adapter.clone();

spawn_local(async move {
let mut wallet_info = (*wallet_adapter).clone();

match wallet_info.connect().await {
Ok(_) => {
wallet_adapter.set(wallet_info);
connected.set(true);
}
Err(err) => {
log::error!("Failed to connect wallet: {}", err);
}
}
});
})
};

let disconnect_wallet = {
let connected = connected.clone();
let wallet_adapter = wallet_adapter.clone();

Callback::from(move |_| {
let connected = connected.clone();
let wallet_adapter = wallet_adapter.clone();

spawn_local(async move {
let mut wallet_info = (*wallet_adapter).clone();

match wallet_info.disconnect().await {
Ok(_) => {
wallet_adapter.set(wallet_info);
connected.set(false);
}
Err(err) => {
log::error!("Failed to disconnect wallet: {}", err);
}
}
});
})
};

html! {
<div class="content">
<div class="wallet-info">
if *connected {
if let Some(ref key) = wallet_info.public_key() {
<p>{ format!("Connected Wallet: {}", wallet_info.name()) }</p>
<p>{ format!("Connected Public Key: {}", key) }</p>
} else {
<p>{ "Connected but no wallet info available" }</p>
}
}
</div>
<div class="buttons">
if !*connected {
<button class="connect-button" onclick={connect_wallet}>
<img src="images/phantom_logo.png" alt="Phantom Wallet" class="button-icon" />
{ "Connect Wallet" }
</button>
} else {
<button class="disconnect-button" onclick={disconnect_wallet}>
<img src="images/phantom_logo.png" alt="Disconnect Wallet" class="button-icon" />
{ "Disconnect Wallet" }
</button>
}
</div>
</div>
}
}

fn main() {
console_error_panic_hook::set_once();
wasm_logger::init(wasm_logger::Config::default());
yew::Renderer::<App>::new().render();
}
```

## 👥 Contributing

Contributions and feedback are welcome! If you'd like to contribute, report an issue, or suggest an enhancement, please engage with the project on [GitHub](https://github.com/gigadao/wasi-sol). Your contributions help improve this CLI and library for the community.

## 📝 License

This project is licensed under the [MIT License](LICENSE).
2 changes: 1 addition & 1 deletion examples/basic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn LoginPage() -> Html {
</div>
</div>
<footer class="footer">
<p>{ "2024 Wasi Sol." }</p>
<p>{ "2024 GigaDAO Foundation." }</p>
</footer>
</div>
}
Expand Down

0 comments on commit 87352bd

Please sign in to comment.