-
Notifications
You must be signed in to change notification settings - Fork 13
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
10 changed files
with
159 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@phantom/wallet-sdk": patch | ||
--- | ||
|
||
Initial implementation |
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,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!" |
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 |
---|---|---|
|
@@ -11,3 +11,5 @@ | |
|
||
#!.yarn/cache | ||
.pnp.* | ||
|
||
dist |
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,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" | ||
} | ||
} |
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 @@ | ||
@phantom/wallet-sdk |
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,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" | ||
} | ||
} |
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 @@ | ||
export const DEFAULT_EMBEDDED_ORIGIN = /^https:\/\/.*\.phantom\.app$/; |
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,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); | ||
}; | ||
} |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "ES2022", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"declaration": true, | ||
"outDir": "dist" | ||
}, | ||
"include": ["src"] | ||
} |
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