Skip to content

Commit

Permalink
svelte demo rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfears committed Sep 15, 2023
1 parent 59fd318 commit 8b3625b
Show file tree
Hide file tree
Showing 30 changed files with 2,095 additions and 210 deletions.
1 change: 1 addition & 0 deletions images/icon - Copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "template-typescript-snap",
"version": "1.0.0",
"name":"stellar-snap",
"version": "0.0.5",
"private": true,
"description": "The 'Hello, world!' of MetaMask Snaps, now written in TypeScript.",
"description": "A non custodial Stellar Wallet built for metamask",
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/template-typescript-snap.git"
"url": "https://github.com/paulfears/StellarSnap.git"
},
"license": "MIT",
"main": "src/index.ts",
Expand All @@ -15,7 +15,7 @@
"snap.manifest.json"
],
"scripts": {
"build": "mm-snap build",
"build": "cd site && yarn && yarn build . --outDir ../site_dist",
"build:clean": "yarn clean && yarn build",
"build:website": "node ./scripts/build-website.js",
"clean": "rimraf 'dist/*'",
Expand Down Expand Up @@ -60,6 +60,11 @@
"dependencies": {
"@metamask/snaps-types": "^1.0.2",
"@metamask/snaps-ui": "^1.0.2",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"buffer": "^6.0.3",
"crc": "^4.3.2",
"nacl": "^0.1.3",
"stellar-base": "10.0.0-soroban.7",
"tweetnacl": "^1.0.3"
}
}
14 changes: 12 additions & 2 deletions site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.min.js"></script>

<title>Metamask Snap</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
<div style="width:100%; height:100vh;" id="pageBackground">
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</div>
<script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.rings.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/soroban-client/0.11.2/soroban-client.js"></script>
<script src="https://cdn.jsdelivr.net/npm/stellar-sdk@10.4.1/dist/stellar-sdk.min.js"></script>
<script>

</script>
</body>
</html>
2 changes: 2 additions & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
"postcss": "^8.4.29",
"svelte": "^4.0.5",
"svelte-check": "^3.4.6",
"svelte-loading-spinners": "^0.3.4",
"tslib": "^2.6.0",
"typescript": "^5.0.2",
"vite": "^4.4.5"
},
"dependencies": {
"flowbite-svelte": "^0.44.15",
"svelte-ace": "^1.0.21",
"tailwindcss": "^3.3.3"
}
}
222 changes: 216 additions & 6 deletions site/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,229 @@


<script lang="ts">
import ConnectButton from './lib/connectButton.svelte';
import FunctionButton from './lib/functionButton.svelte';
import FunctionContainer from './lib/functionContainer.svelte';
import {ButtonGroup} from 'flowbite-svelte';
import {connected} from './store';
import {snapId} from './constants';
import { Navbar, NavBrand, NavLi, NavUl, NavHamburger, TabItem, Tabs, Toggle} from 'flowbite-svelte';
import CodeBucket from './lib/CodeBucket.svelte';
import SorobanPage from './lib/SorobanPage.svelte';
import { Chasing } from 'svelte-loading-spinners';
import {fade} from 'svelte/transition'
let funding = false;
let testnet = true;
function genreateCode(method, params){
return `
window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: '${snapId}',
request: {
method: '${method}',
params: ${JSON.stringify(params)}
},
},
})
.then((result)=>alert(JSON.stringify(result)))
`
}
async function fundWallet(){
funding = true;
try{
console.log("in here");
const result = await window.ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId: snapId,
request: {
method: "fund",
},
},
});
console.log(result)
}
catch(e){
}
funding = false;
}
</script>

<style>
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
width:auto;
padding: 10px;
gap: 10px;
}
#id{
width:100%;
height:100%;
}
</style>

<ConnectButton>Connect</ConnectButton>
<Navbar rounded>
<NavBrand href="/">
<div style="display:flex; flex-direction:column; justify-content:left;">
<img style="height:40px;" src="https://assets-global.website-files.com/5deac75ecad2173c2ccccbc7/5dec8960504967fd31147f62_Stellar_lockup_black_RGB.svg" alt="" class="stellar-logo">
<h2 style="font-size:x-large;">on Metamask</h2>
</div>
</NavBrand>
<NavHamburger/>
<NavUl>
<NavLi><ConnectButton callback={fundWallet}/></NavLi>
</NavUl>
</Navbar>

{#if funding}
<div class="flex">
<Chasing color="#6366f1"></Chasing>
<p style="color:white background-color:black;">Funding Your testnet and Futurenet Accounts. Please Wait.</p>
</div>
{/if}
<br>
<br>
<div>
{#if $connected}
<FunctionButton method="hello" params={{}}>Hello</FunctionButton>
{/if}
{#if $connected}
<div transition:fade={{ delay: 0, duration: 300 }}>
<Toggle bind:checked={testnet}>Testnet</Toggle>
<br/>
<Tabs defaultClass="flex">
<TabItem open>
<span slot="title">Query Stellar</span>
<div class="grid-container">
<FunctionContainer code={genreateCode("getAddress", {testnet})} params={{"testnet":testnet}} method="getAddress">
<p slot="title">Get Address of Wallet</p>
</FunctionContainer>
<FunctionContainer code={genreateCode("getBalance", {testnet})} params={{"testnet":testnet}} method="getBalance">
<p slot="title">Get Balance of Wallet</p>
</FunctionContainer>
<FunctionContainer code={genreateCode("getAccountInfo", {testnet})} params={{"testnet":testnet}} method="getAccountInfo">
<p slot="title">Get Account Info</p>
</FunctionContainer>



</div>

</TabItem>
<TabItem >
<span slot="title">Signing Functions</span>
<div class="flex">
<div class="grow">
<FunctionContainer
code={genreateCode("transfer", {to:"GDPZOWVRHQV2SQ3N47CILKNU4NZQOXYDVXGKKJI32TVWIF7V7364G2QM", "amount":"1", testnet})}

params={{"to":"string:GDPZOWVRHQV2SQ3N47CILKNU4NZQOXYDVXGKKJI32TVWIF7V7364G2QM", "amount":"number:0", testnet}}
method="transfer">
<p slot="title">TRANSFER XLM</p>
</FunctionContainer>
</div>
<div class="grow">
<FunctionContainer method="signTransaction"
code={`
async function signTransaction(){
const server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
const sourcePublicKey = await ethereum.request({
method: 'wallet_invokeSnap',
params: {snapId:'${snapId}', request:{
method: 'getAddress',
}}
})
const account = await server.loadAccount(sourcePublicKey);
const fee = await server.fetchBaseFee();
console.log("base fee is");
console.log(fee);
const receiverPublicKey = 'GAIRISXKPLOWZBMFRPU5XRGUUX3VMA3ZEWKBM5MSNRU3CHV6P4PYZ74D';
console.log("metamask public key: ");
console.log(sourcePublicKey);
console.log("account is");
console.log(account);
console.log("building Transaction");
const transaction = new StellarSdk.TransactionBuilder(account, { fee, networkPassphrase: "Test SDF Network ; September 2015" });
// Add a payment operation to the transaction
console.log("transaction builder initilazed");
await transaction.addOperation(StellarSdk.Operation.payment({
destination: receiverPublicKey,
// The term native asset refers to lumens
asset: StellarSdk.Asset.native(),
// Specify 350.1234567 lumens. Lumens are divisible to seven digits past
// the decimal. They are represented in JS Stellar SDK in string format
// to avoid errors from the use of the JavaScript Number data structure.
amount: '350.1234567',
}));
console.log("operations added")
// Make this transaction valid for the next 30 seconds only
await transaction.setTimeout(30);
console.log("timeout set");
// Uncomment to add a memo (https://www.stellar.org/developers/learn/concepts/transactions.html)
// .addMemo(StellarSdk.Memo.text('Hello world!'))
const endTransaction = await transaction.build();
const xdrTransaction = endTransaction.toXDR();
console.log(xdrTransaction);
const response = await ethereum.request({
method: 'wallet_invokeSnap',
params:{snapId:'${snapId}', request:{
method: 'signTransaction',
params:{
transaction: xdrTransaction,
testnet: ${testnet}
}
}}
});
return response
}
(async () => alert(await signTransaction()))();
`}
codeView={true}
lockView={true}
params={{testnet}}>
<p slot="title">Sign Transaction</p>
<br/>
</FunctionContainer>
</div>
</div>
</TabItem>
<TabItem >
<span slot="title">Soroban</span>
<SorobanPage/>
</TabItem>
<TabItem >
<span slot="title">Project Info</span>
This project Utilizes Metamask snaps, This is code that runs inside of metamask secure execution enviroment, but is seemless from a user experence.
</TabItem>
</Tabs>
</div>
{:else}

<section transition:fade={{ delay: 0, duration: 300 }} class="bg-no-repeat bg-[url('https://chaindebrief.com/wp-content/uploads/2021/08/Metamask-logo.png')] bg-blend-multiply">
<div class="py-8 px-10 mx-auto max-w-screen-xl text-left lg:py-16">
<h1 class="mb-4 px-10 text-4xl font-extrabold tracking-tight leading-none text-gray-900 md:text-5xl lg:text-6xl dark:text-white">Unlock The Power of Stellar with Metamask</h1>
<p style="text-align:left; padding-right:40%;" class="mb-8 text-lg font-normal text-gray-500 lg:text-xl sm:px-10 lg:px-10 dark:text-gray-400">
Unlock Stellar to 30 Million Metamask Users
</p>
<div class="flex flex-col space-y-4 sm:flex-row sm:justify-center sm:space-y-0 sm:space-x-4">
<ConnectButton/>
<a href="https://www.youtube.com/watch?v=-VenhahQ5zo" target="_blank" class="inline-flex justify-center items-center py-3 px-5 text-base font-medium text-center text-gray-900 rounded-lg border border-gray-300 hover:bg-gray-100 focus:ring-4 focus:ring-gray-100 dark:text-white dark:border-gray-700 dark:hover:bg-gray-700 dark:focus:ring-gray-800">
Learn more
</a>
</div>
</div>
</section>


{/if}



59 changes: 1 addition & 58 deletions site/src/app.css
Original file line number Diff line number Diff line change
@@ -1,47 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

.card {
padding: 2em;
}

#app {
max-width: 1280px;
Expand All @@ -50,24 +10,7 @@ h1 {
text-align: center;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}


@media (prefers-color-scheme: light) {
:root {
Expand Down
Loading

0 comments on commit 8b3625b

Please sign in to comment.