-
Notifications
You must be signed in to change notification settings - Fork 8
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
5 changed files
with
11,492 additions
and
8,072 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
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
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,25 @@ | ||
|
||
const supportedFunctions = [ | ||
{name:'getAddress', params:{}, desc:'Get the current account address'}, | ||
{name:'getDataPacket', params:{}, desc:'Get the data packet for the current account'}, | ||
{name:'setCurrentAccount', params:{address:'string'}, desc:'Set the current account to the address provided'}, | ||
{name:'showAddress', params:{}, desc:'Show the current account address'}, | ||
{name:'createAccount', params:{name:'string'}, desc:'Create a new account with the name provided'}, | ||
{name:'listAccounts', params:{}, desc:'List all accounts'}, | ||
{name:'renameAccount', params:{address:'string', name:'string'}, desc:'Rename an account'}, | ||
{name:'importAccount', params:{}, desc:'Import an account'}, | ||
{name:'fund', params:{}, desc:'Fund the current account with testnet lumens'}, | ||
{name:'getFederationName', params:{}, desc:'Get the federation name for the current account'}, | ||
{name:'lookUpFedAccountByAddress', params:{address:'string'}, desc:'Get the federation address for the current account'}, | ||
{name:'lookUpFedAccountByName', params:{url:'string'}, desc:'Get the federation address for an account by its name*metastellar.io fed name'}, | ||
{name:'getBalance', params:{testnet:'boolean'}, desc:'Get the balance of the current account'}, | ||
{name:'getAssets', params:{}, desc:'Get the assets of the current account'}, | ||
{name:'signStr', params:{challenge:'string'}, desc:'Sign a string'}, | ||
{name:'dispPrivateKey', params:{}, desc:'Display the private key of the current account'}, | ||
{name: 'getAccountInfo', params:{}, desc:'Get the account info of the current account from horizon'}, | ||
{name: 'transfer', params:{to:'string', amount:'string', testnet:'boolean'}, desc:'Transfer lumens to another account, will create an account if it does not exist'}, | ||
{name: 'signTransaction', params:{transaction:'XDR as string', testnet:'boolean'}, desc:'Sign a transaction'}, | ||
{name: 'signAndSubmitTransaction', params:{transaction:'XDR as string', testnet:'boolean'}, desc:'Sign and submit a transaction'}, | ||
{name: 'createFederationAccount', params:{}, desc:'Opens the create federation account dialog'}, | ||
{name: 'openSendXLM', params:{}, desc:'Opens the send XLM dialog'}, | ||
] |
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,138 @@ | ||
<!doctype html> | ||
<html> | ||
</head> | ||
<title>Hello, Snaps!</title> | ||
<link rel="icon" type="image/svg" href="./images/icon.svg"/> | ||
<script src="./functions.js"></script> | ||
</head> | ||
|
||
<body> | ||
<h1>Hello, Snaps!</h1> | ||
<details> | ||
<summary>Instructions</summary> | ||
<ul> | ||
<li>First, click "Connect". Then, try out the other buttons!</li> | ||
<li>Please note that:</li> | ||
<ul> | ||
<li> | ||
The <code>snap.manifest.json</code> and <code>package.json</code> must be located in the server root directory... | ||
</li> | ||
<li> | ||
The Snap bundle must be hosted at the location specified by the <code>location</code> field of <code>snap.manifest.json</code>. | ||
</li> | ||
</ul> | ||
</ul> | ||
</details> | ||
<br/> | ||
|
||
<button class="connect">Connect</button> | ||
|
||
</body> | ||
|
||
<script> | ||
const snapId = `local:${window.location.href}`; | ||
|
||
|
||
|
||
async function callMetaStellar(method, params){ | ||
if (typeof window !== 'undefined' && typeof window.ethereum !== undefined) { | ||
//You Can Delete this section after offical launch | ||
const isFlask = ( | ||
await window.ethereum?.request({ method: "web3_clientVersion" }) | ||
)?.includes("flask"); | ||
if(!isFlask){ | ||
alert("install Metamask Flask") | ||
} | ||
// ------------------------------------------------ | ||
try{ | ||
if(method === 'connect'){ | ||
//This will also install stellar if the user has metamask | ||
return await window.ethereum.request({ | ||
method: 'wallet_requestSnaps', | ||
params: { | ||
['npm:stellar-snap']: {} | ||
}, | ||
}); | ||
} | ||
const rpcPacket = { | ||
method: 'wallet_invokeSnap', | ||
params:{ | ||
snapId:'npm:stellar-snap', | ||
request: {'method':method, params:params} | ||
} | ||
} | ||
return await window.ethereum.request(rpcPacket); | ||
} | ||
catch(e){ | ||
alert(e.message); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
const connectButton = document.querySelector('button.connect') | ||
|
||
|
||
connectButton.addEventListener('click', connect) | ||
|
||
|
||
// here we get permissions to interact with and install the snap | ||
async function connect () { | ||
await callMetaStellar('connect'); | ||
} | ||
|
||
function createTest(FunctionItem){ | ||
const test = document.createElement('div'); | ||
test.style = `display: flex; flex-direction: column; margin:50px;`; | ||
test.innerHTML = FunctionItem.name; | ||
let description = document.createElement('p'); | ||
description.innerHTML = FunctionItem.desc; | ||
test.appendChild(description); | ||
for(let i = 0; i < Object.keys(FunctionItem.params).length; i++){ | ||
let key = Object.keys(FunctionItem.params)[i]; | ||
let value = Object.values(FunctionItem.params)[i]; | ||
let input = document.createElement('input'); | ||
if(value === "string"){ | ||
const input = document.createElement('input'); | ||
input.id = FunctionItem.name+"-"+key; | ||
input.placeholder = key; | ||
} | ||
if(value === "boolean"){ | ||
const input = document.createElement('input'); | ||
input.id = FunctionItem.name+"-"+key; | ||
input.type = "checkbox"; | ||
input.checked = true; | ||
} | ||
test.appendChild(input); | ||
} | ||
buildRunFunction = (FunctionItem)=>{ | ||
return ()=>{ | ||
let params = {}; | ||
for(let i = 0; i < Object.keys(FunctionItem.params).length; i++){ | ||
let key = Object.keys(FunctionItem.params)[i]; | ||
let value = Object.values(FunctionItem.params)[i]; | ||
if(value === "string"){ | ||
params[key] = document.getElementById(FunctionItem.name+"-"+key).value; | ||
} | ||
if(value === "boolean"){ | ||
params[key] = document.getElementById(FunctionItem.name+"-"+key).checked; | ||
} | ||
} | ||
callMetaStellar(FunctionItem.name, params).then(console.log); | ||
} | ||
}; | ||
const button = document.createElement('button'); | ||
button.innerHTML = "Run"; | ||
button.addEventListener('click', buildRunFunction(FunctionItem)); | ||
test.appendChild(button); | ||
document.body.appendChild(test); | ||
} | ||
|
||
for(let i = 0; i<supportedFunctions.length; i++){ | ||
createTest(supportedFunctions[i]); | ||
} | ||
|
||
|
||
</script> | ||
</html> |
Oops, something went wrong.