Skip to content

Commit

Permalink
Merge pull request #21 from phantom/napas/auth-924-update-sdk-to-allo…
Browse files Browse the repository at this point in the history
…w-configuration-of-wallet-positioning

featL Add positioning config
  • Loading branch information
tian000 authored Dec 6, 2024
2 parents ca1c3eb + 4a5002c commit 639f28c
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 42 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-humans-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@phantom/wallet-sdk": patch
---

Add parameters for wallet positioning on all 4 corners
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.pnp.*

dist
/.idea/
58 changes: 37 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Phantom Embedded Wallet SDK

Phantom Embedded enables you to seamlessly onboard users to your application, without requiring them to have previously installed a wallet. With Phantom Embedded, users can create a self custodial wallet with just their Google account and a 4-digit pin. Once created, this wallet will automatically sync with [Phantom](https://phantom.app)'s mobile and extension apps without the user needing to know their seed phrase or manage any private keys.
Phantom Embedded enables you to seamlessly onboard users to your application, without requiring them to have previously
installed a wallet. With Phantom Embedded, users can create a self custodial wallet with just their Google account and a
4-digit pin. Once created, this wallet will automatically sync with [Phantom](https://phantom.app)'s mobile and
extension apps without the user needing to know their seed phrase or manage any private keys.

In addition to powering wallet creation, Phantom Embedded also comes with a built-in UI for users to view and manage their holdings. This UI serves as a trusted interface for users to sign messages and transactions on your app.
In addition to powering wallet creation, Phantom Embedded also comes with a built-in UI for users to view and manage
their holdings. This UI serves as a trusted interface for users to sign messages and transactions on your app.

## Features

Expand All @@ -24,44 +28,52 @@ yarn | npm | pnpm add @phantom/wallet-sdk
2. Load the Phantom Embedded wallet in your web application

```tsx
import { createPhantom } from "@phantom/wallet-sdk"
import {createPhantom} from "@phantom/wallet-sdk"

const opts: CreatePhantomConfig = {
zIndex: 10_000,
hideLauncherBeforeOnboarded: true,
zIndex: 10_000,
hideLauncherBeforeOnboarded: true,
}

const App = () => {
useEffect(() => {
createPhantom(opts);
}, []);
...
useEffect(() => {
createPhantom(opts);
}, []);
...
}
```

3. [Integrate Phantom](https://docs.phantom.app/solana/integrating-phantom) as you would normally. Whenever a user interacts with Phantom (e.g. `window.phantom.solana.connect()`), the Phantom Embedded wallet will automatically initialize if the user does not have Phantom already installed.
3. [Integrate Phantom](https://docs.phantom.app/solana/integrating-phantom) as you would normally. Whenever a user
interacts with Phantom (e.g. `window.phantom.solana.connect()`), the Phantom Embedded wallet will automatically
initialize if the user does not have Phantom already installed.

## Configuration

The following optional parameters can be passed as `createPhantom({options...})` to customize the Phantom Embedded wallet experience.
The following optional parameters can be passed as `createPhantom({options...})` to customize the Phantom Embedded
wallet experience.

| Parameter | Type | Description |
| ----------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| `hideLauncherBeforeOnboarded` | boolean | If `true`, the Phantom Embedded UI will be hidden until the user engages with Phantom. Defaults to `false`. |
| Parameter | Type | Description |
| ----------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `hideLauncherBeforeOnboarded` | boolean | If `true`, the Phantom Embedded UI will be hidden until the user engages with Phantom. Defaults to `false`. |
| `colorScheme` | string | The background color of the Phantom Embedded iframe, which should be configured to match your site's theme. Can be `"light"`, `"dark"`, or `"normal"`. Defaults to `"normal"`. |
| `zIndex` | number | The z-index of the Phantom Embedded UI. Defaults to `10_000`. |
| `paddingBottom` | number | The number of pixels between the Phantom Embedded UI and the right edge of the web. Defaults to `0`. |
| `paddingRight` | number | The number of pixels between the Phantom Embedded UI and the bottom edge of the web. Defaults to `0`. |
| `zIndex` | number | The z-index of the Phantom Embedded UI. Defaults to `10_000`. |
| `paddingBottom` | number | The number of pixels between the Phantom Embedded UI and the right edge of the web. Defaults to `0`. |
| `paddingRight` | number | The number of pixels between the Phantom Embedded UI and the bottom edge of the web. Defaults to `0`. |
| `paddingTop` | number | The number of pixels between the Phantom Embedded UI and the top edge of the web. Defaults to `0`. |
| `paddingLeft` | number | The number of pixels between the Phantom Embedded UI and the left edge of the web. Defaults to `0`. |
| `position` | enum | The corner of the app where the Phantom wallet will be displayed. Can be `"bottom-right"`, `"bottom-left"`, `"top-right"`, `"top-left"`. Defaults to "bottom-left". |

## See It In Action

Try out Phantom Embedded via our demo app: https://sandbox.phantom.dev/sol-embedded-sandbox

> Note: Phantom Embedded will not initialize if it detects that the user already has the Phantom extension installed, or if the user is accessing the page from within the Phantom mobile app.
> Note: Phantom Embedded will not initialize if it detects that the user already has the Phantom extension installed, or
> if the user is accessing the page from within the Phantom mobile app.
## Give Feedback

Phantom Embedded is in active development and will be prioritizing features requested by early adopters. If you are interested in working with us, please email us at `[email protected]` or message `@brianfriel` on Telegram.
Phantom Embedded is in active development and will be prioritizing features requested by early adopters. If you are
interested in working with us, please email us at `[email protected]` or message `@brianfriel` on Telegram.

## Frequently Asked Questions

Expand Down Expand Up @@ -102,6 +114,10 @@ Phantom Embedded is in active development and will be prioritizing features requ

## Disclaimers

We are providing early access to beta software for testing purposes only. Embedded wallet should be used in a non-production environment only. Phantom will not be liable for any losses or damages suffered by you or your end users if you push the early access version of embedded wallets to a production environment.
We are providing early access to beta software for testing purposes only. Embedded wallet should be used in a
non-production environment only. Phantom will not be liable for any losses or damages suffered by you or your end users
if you push the early access version of embedded wallets to a production environment.

All suggestions, enhancement requests, recommendations or other feedback provided by you relating to the embedded wallet will be the sole and exclusive property of Phantom and by using the early access version of embedded wallets and providing feedback to Phantom you agree to assign any rights in that feedback to Phantom.
All suggestions, enhancement requests, recommendations or other feedback provided by you relating to the embedded wallet
will be the sole and exclusive property of Phantom and by using the early access version of embedded wallets and
providing feedback to Phantom you agree to assign any rights in that feedback to Phantom.
58 changes: 37 additions & 21 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Phantom Embedded Wallet SDK

Phantom Embedded enables you to seamlessly onboard users to your application, without requiring them to have previously installed a wallet. With Phantom Embedded, users can create a self custodial wallet with just their Google account and a 4-digit pin. Once created, this wallet will automatically sync with [Phantom](https://phantom.app)'s mobile and extension apps without the user needing to know their seed phrase or manage any private keys.
Phantom Embedded enables you to seamlessly onboard users to your application, without requiring them to have previously
installed a wallet. With Phantom Embedded, users can create a self custodial wallet with just their Google account and a
4-digit pin. Once created, this wallet will automatically sync with [Phantom](https://phantom.app)'s mobile and
extension apps without the user needing to know their seed phrase or manage any private keys.

In addition to powering wallet creation, Phantom Embedded also comes with a built-in UI for users to view and manage their holdings. This UI serves as a trusted interface for users to sign messages and transactions on your app.
In addition to powering wallet creation, Phantom Embedded also comes with a built-in UI for users to view and manage
their holdings. This UI serves as a trusted interface for users to sign messages and transactions on your app.

## Features

Expand All @@ -24,44 +28,52 @@ yarn | npm | pnpm add @phantom/wallet-sdk
2. Load the Phantom Embedded wallet in your web application

```tsx
import { createPhantom } from "@phantom/wallet-sdk"
import {createPhantom} from "@phantom/wallet-sdk"

const opts: CreatePhantomConfig = {
zIndex: 10_000,
hideLauncherBeforeOnboarded: true,
zIndex: 10_000,
hideLauncherBeforeOnboarded: true,
}

const App = () => {
useEffect(() => {
createPhantom(opts);
}, []);
...
useEffect(() => {
createPhantom(opts);
}, []);
...
}
```

3. [Integrate Phantom](https://docs.phantom.app/solana/integrating-phantom) as you would normally. Whenever a user interacts with Phantom (e.g. `window.phantom.solana.connect()`), the Phantom Embedded wallet will automatically initialize if the user does not have Phantom already installed.
3. [Integrate Phantom](https://docs.phantom.app/solana/integrating-phantom) as you would normally. Whenever a user
interacts with Phantom (e.g. `window.phantom.solana.connect()`), the Phantom Embedded wallet will automatically
initialize if the user does not have Phantom already installed.

## Configuration

The following optional parameters can be passed as `createPhantom({options...})` to customize the Phantom Embedded wallet experience.
The following optional parameters can be passed as `createPhantom({options...})` to customize the Phantom Embedded
wallet experience.

| Parameter | Type | Description |
| ----------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------- |
| `hideLauncherBeforeOnboarded` | boolean | If `true`, the Phantom Embedded UI will be hidden until the user engages with Phantom. Defaults to `false`. |
| Parameter | Type | Description |
| ----------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `hideLauncherBeforeOnboarded` | boolean | If `true`, the Phantom Embedded UI will be hidden until the user engages with Phantom. Defaults to `false`. |
| `colorScheme` | string | The background color of the Phantom Embedded iframe, which should be configured to match your site's theme. Can be `"light"`, `"dark"`, or `"normal"`. Defaults to `"normal"`. |
| `zIndex` | number | The z-index of the Phantom Embedded UI. Defaults to `10_000`. |
| `paddingBottom` | number | The number of pixels between the Phantom Embedded UI and the right edge of the web. Defaults to `0`. |
| `paddingRight` | number | The number of pixels between the Phantom Embedded UI and the bottom edge of the web. Defaults to `0`. |
| `zIndex` | number | The z-index of the Phantom Embedded UI. Defaults to `10_000`. |
| `paddingBottom` | number | The number of pixels between the Phantom Embedded UI and the right edge of the web. Defaults to `0`. |
| `paddingRight` | number | The number of pixels between the Phantom Embedded UI and the bottom edge of the web. Defaults to `0`. |
| `paddingTop` | number | The number of pixels between the Phantom Embedded UI and the top edge of the web. Defaults to `0`. |
| `paddingLeft` | number | The number of pixels between the Phantom Embedded UI and the left edge of the web. Defaults to `0`. |
| `position` | enum | The corner of the app where the Phantom wallet will be displayed. Can be `"bottom-right"`, `"bottom-left"`, `"top-right"`, `"top-left"`. Defaults to "bottom-left". |

## See It In Action

Try out Phantom Embedded via our demo app: https://sandbox.phantom.dev/sol-embedded-sandbox

> Note: Phantom Embedded will not initialize if it detects that the user already has the Phantom extension installed, or if the user is accessing the page from within the Phantom mobile app.
> Note: Phantom Embedded will not initialize if it detects that the user already has the Phantom extension installed, or
> if the user is accessing the page from within the Phantom mobile app.
## Give Feedback

Phantom Embedded is in active development and will be prioritizing features requested by early adopters. If you are interested in working with us, please email us at `[email protected]` or message `@brianfriel` on Telegram.
Phantom Embedded is in active development and will be prioritizing features requested by early adopters. If you are
interested in working with us, please email us at `[email protected]` or message `@brianfriel` on Telegram.

## Frequently Asked Questions

Expand Down Expand Up @@ -102,6 +114,10 @@ Phantom Embedded is in active development and will be prioritizing features requ

## Disclaimers

We are providing early access to beta software for testing purposes only. Embedded wallet should be used in a non-production environment only. Phantom will not be liable for any losses or damages suffered by you or your end users if you push the early access version of embedded wallets to a production environment.
We are providing early access to beta software for testing purposes only. Embedded wallet should be used in a
non-production environment only. Phantom will not be liable for any losses or damages suffered by you or your end users
if you push the early access version of embedded wallets to a production environment.

All suggestions, enhancement requests, recommendations or other feedback provided by you relating to the embedded wallet will be the sole and exclusive property of Phantom and by using the early access version of embedded wallets and providing feedback to Phantom you agree to assign any rights in that feedback to Phantom.
All suggestions, enhancement requests, recommendations or other feedback provided by you relating to the embedded wallet
will be the sole and exclusive property of Phantom and by using the early access version of embedded wallets and
providing feedback to Phantom you agree to assign any rights in that feedback to Phantom.
17 changes: 17 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { SDK_URL } from "./constants.js";

export enum Position {
bottomRight = "bottom-right",
bottomLeft = "bottom-left",
topRight = "top-right",
topLeft = "top-left",
}

export type CreatePhantomConfig = Partial<{
zIndex: number;
hideLauncherBeforeOnboarded: boolean;
colorScheme: string;
paddingBottom: number;
paddingRight: number;
paddingTop: number;
paddingLeft: number;
position: Position;
}>;

export function createPhantom(config: CreatePhantomConfig = {}) {
Expand All @@ -30,6 +40,13 @@ export function createPhantom(config: CreatePhantomConfig = {}) {
if (config.paddingRight)
sdkURL.searchParams.append("paddingRight", config.paddingRight.toString());

if (config.paddingTop)
sdkURL.searchParams.append("paddingTop", config.paddingTop.toString());
if (config.paddingLeft)
sdkURL.searchParams.append("paddingLeft", config.paddingLeft.toString());
if (config.position)
sdkURL.searchParams.append("position", config.position.toString());

scriptTag.setAttribute("type", "module");
scriptTag.setAttribute("src", sdkURL.toString());
container.insertBefore(scriptTag, container.children[0]);
Expand Down

0 comments on commit 639f28c

Please sign in to comment.