Skip to content

Commit

Permalink
Initial SDK impl
Browse files Browse the repository at this point in the history
  • Loading branch information
pzuraq committed Oct 1, 2024
1 parent 30663ab commit 2506f1c
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-clocks-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@phantom/wallet-sdk": patch
---

Initial implementation
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Install Dependencies
run: yarn

- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
# This expects you to have a script called release which does a build for your packages and calls changeset publish
publish: yarn release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Send a Slack notification if a publish happens
if: steps.changesets.outputs.published == 'true'
# You can do something when a publish happens.
run: my-slack-bot send-notification --message "A new version of ${GITHUB_REPOSITORY} was published!"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@

#!.yarn/cache
.pnp.*

dist
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"name": "@phantom/sdk-monorepo",
"private": true,
"packageManager": "yarn@4.2.2",
"packages": [
"scripts": {
"build": "yarn workspaces foreach --all run build",
"release": "yarn build && yarn changeset version"
},
"workspaces": [
"packages/*"
],
"dependencies": {
"@changesets/cli": "^2.27.8"
"@changesets/cli": "^2.27.8",
"typescript": "^5.6.2"
}
}
1 change: 1 addition & 0 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@phantom/wallet-sdk
20 changes: 20 additions & 0 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@phantom/wallet-sdk",
"version": "0.0.0",
"type": "module",
"exports": {
".": {
"import": "./dist/index.js"
}
},
"packageManager": "yarn@4.2.2",
"scripts": {
"build": "tsc --build"
},
"packages": [
"packages/*"
],
"devDependencies": {
"typescript": "^5.6.2"
}
}
1 change: 1 addition & 0 deletions packages/sdk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_EMBEDDED_ORIGIN = /^https:\/\/.*\.phantom\.app$/;
41 changes: 41 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { DEFAULT_EMBEDDED_ORIGIN } from "./constants";

export interface PhantomWalletOptions {
embeddedOrigin?: string | RegExp;
}

const isValidOrigin = (origin: string, embeddedOrigin: string | RegExp) =>
typeof embeddedOrigin === "string"
? origin === embeddedOrigin
: embeddedOrigin.test(origin);

export function createPhantom(opts: PhantomWalletOptions = {}) {
const embeddedOrigin = opts.embeddedOrigin ?? DEFAULT_EMBEDDED_ORIGIN;

const iframe = document.createElement("iframe");

iframe.src = "/src/wallet/index.html";
iframe.setAttribute("frameborder", "0");
iframe.setAttribute("marginwidth", "0");
iframe.setAttribute("marginheight", "0");
iframe.style.position = "fixed";
iframe.style.bottom = "0";
iframe.style.right = "0";
iframe.style.width = "0";
iframe.style.height = "0";

window.addEventListener("message", (event) => {
if (!isValidOrigin(event.origin, embeddedOrigin)) {
return;
}

iframe.style.width = `${event.data.width}px`;
iframe.style.height = `${event.data.height}px`;
});

document.body.appendChild(iframe);

return () => {
document.body.removeChild(iframe);
};
}
13 changes: 13 additions & 0 deletions packages/sdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2016",
"module": "ES2022",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"declaration": true,
"outDir": "dist"
},
"include": ["src"]
}
29 changes: 29 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ __metadata:
resolution: "@phantom/sdk-monorepo@workspace:."
dependencies:
"@changesets/cli": "npm:^2.27.8"
typescript: "npm:^5.6.2"
languageName: unknown
linkType: soft

"@phantom/wallet-sdk@workspace:packages/sdk":
version: 0.0.0-use.local
resolution: "@phantom/wallet-sdk@workspace:packages/sdk"
dependencies:
typescript: "npm:^5.6.2"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -954,6 +963,26 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^5.6.2":
version: 5.6.2
resolution: "typescript@npm:5.6.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/3ed8297a8c7c56b7fec282532503d1ac795239d06e7c4966b42d4330c6cf433a170b53bcf93a130a7f14ccc5235de5560df4f1045eb7f3550b46ebed16d3c5e5
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A^5.6.2#optional!builtin<compat/typescript>":
version: 5.6.2
resolution: "typescript@patch:typescript@npm%3A5.6.2#optional!builtin<compat/typescript>::version=5.6.2&hash=b45daf"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/e6c1662e4852e22fe4bbdca471dca3e3edc74f6f1df043135c44a18a7902037023ccb0abdfb754595ca9028df8920f2f8492c00fc3cbb4309079aae8b7de71cd
languageName: node
linkType: hard

"universalify@npm:^0.1.0":
version: 0.1.2
resolution: "universalify@npm:0.1.2"
Expand Down

0 comments on commit 2506f1c

Please sign in to comment.