Skip to content

Commit

Permalink
changed wallet heading
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfears committed Oct 22, 2024
1 parent 8479951 commit 5effd4f
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 48 deletions.
12 changes: 8 additions & 4 deletions site/src/routes/wallet/WalletHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@
<div>
<div style="display:flex; flex-direction:row; justify-content:space-between;">
<div style="display:flex; flex-gap:3;">

<img style="padding:5px;" on:click={()=>quickCopy($dataPacket.currentAddress)} alt={"addressIcon"} width="35" height="35" src={iconSRC}/>
<div style="padding:10px;">
<img style="padding:5px;" on:click={()=>quickCopy($dataPacket.currentAddress)} alt={"addressIcon"} width="35" height="35" src={iconSRC}/>
</div>
<Tooltip>icon provided by lobstr.co</Tooltip>
<P size="2xl">{$dataPacket.name}{#if $dataPacket.fedName} - {$dataPacket.fedName}{/if}</P>
<div style="display:flex; flex-direction:column;">
<P size="2xl" style="margin:0px;">{$dataPacket.name}</P>
{#if $dataPacket.fedName} <P size="sm">{$dataPacket.fedName}</P>{/if}
</div>
</div>
<Button on:click={flipNetwork} color="light" class="relative" size="sm">
<Button on:click={flipNetwork} color="light" class="relative" size="sm" style="height:40px;">
{$isTestnet?"testnet":"mainnet"}
<span class="sr-only">Network Indicator</span>
{#if $isTestnet}
Expand Down
2 changes: 1 addition & 1 deletion snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/paulfears/StellarSnap.git"
},
"source": {
"shasum": "0wNq/TjE7rJ15fw59lDMVQasa3RM2Azl/FN39mbsGSU=",
"shasum": "WCKcDYLPysLb4iYtokYDgCj3XxYfGbYLKJHDKLy+XWQ=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
8 changes: 4 additions & 4 deletions snap/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface auth{
export class Auth{
keypair:Keypair;

constructor(keypair){
constructor(keypair:Keypair){

this.keypair = keypair;
}
Expand All @@ -33,7 +33,7 @@ export class Auth{
console.log(prepaired);
return prepaired;
}
async signData(data: string):string{
async signData(data: string):Promise<string>{
let displayPanel = panel([
heading('Sign Text?'),
divider(),
Expand Down Expand Up @@ -67,7 +67,7 @@ export class Auth{
}
}

async signOnGet(url, testKey){
async signOnGet(url:string, testKey:string){
const auth = await this.getAuthObject(testKey);
const outAuth = JSON.stringify({auth:auth})
const response = await fetch(url,
Expand All @@ -82,7 +82,7 @@ export class Auth{
return await response.json();
}

async signOnPost(url, jsonData, testKey){
async signOnPost(url:string, jsonData:any, testKey:string){
const auth = await this.getAuthObject(testKey);
console.log("sign on post");
jsonData.auth = auth;
Expand Down
26 changes: 14 additions & 12 deletions snap/Client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FeeBumpTransaction, Transaction } from "stellar-base";
import { SorobanRpc } from "./soroban_rpc";
import { Wallet } from "./Wallet";
import { Url } from "url";

const testNetURL = "https://horizon-testnet.stellar.org"
const mainNetURL = "https://horizon.stellar.org"
Expand Down Expand Up @@ -34,18 +35,21 @@ export async function fund(wallet:Wallet){


export class Client{
endPoint:string
testNet: boolean
testNetURL: string
mainNetURL: string
endPoint = mainNetURL
MainnetPassphrase = 'Public Global Stellar Network ; September 2015'
TestnetPassphrase = 'Test SDF Network ; September 2015'
FuturenetPassphrase = 'Test SDF Future Network ; October 2022'
currentPassphrase: string;
network: 'mainnet' | 'testnet' | 'futurenet'
network: 'mainnet' | 'testnet' | 'futurenet' = 'mainnet';

constructor(network?:'mainnet'|'testnet'|'futurenet'){
this.setNetwork(network);
this.currentPassphrase = this.MainnetPassphrase;
if(network){
this.setNetwork(network);
}
else{
this.setNetwork('mainnet');
}
}

setNetworkPassphrase(networkPasspharse: string):void{
Expand All @@ -67,14 +71,14 @@ export class Client{
}
}

async get(path){
async get(path:string){
console.log("here")
console.log(this.endPoint)
const response = await fetch(this.endPoint+'/'+path)
const json = await response.json()
return json
}
async post(path){
async post(path:string){
console.log("here")
const response = await fetch(this.endPoint+'/'+path, {
method: "POST",
Expand All @@ -86,9 +90,7 @@ export class Client{
return json
}

async postData(path, data){

}


async getAccount(address: string){
console.log("getAccount");
Expand Down Expand Up @@ -153,7 +155,7 @@ export class Client{
if(this.network === 'mainnet'){
sorobanRPC = soroban_main_rpc;
}
const result = await fetch(sorobanRPC, {
const result = await fetch(sorobanRPC as string, {
method: 'POST',
headers: {
'Accept': 'application/json',
Expand Down
4 changes: 2 additions & 2 deletions snap/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export default class Utils {
params:{
type: type,
content: panel([
text(`request origin: ${InteractionHandler.requestOrigin}`),
disppanel,
divider(),
disppanel
text(`request origin: ${InteractionHandler.requestOrigin}`), //this is a global variable for the request origin
])
}
})
Expand Down
4 changes: 2 additions & 2 deletions snap/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class Wallet{
return Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)))
}

static async createNewAccount(name, currentState?:State, setState?:boolean):Promise<Wallet>{
static async createNewAccount(name:string, currentState?:State, setState?:boolean):Promise<Wallet>{
if(currentState === undefined){
currentState = await StateManager.getState();
}
Expand Down Expand Up @@ -88,7 +88,7 @@ export class Wallet{
return new Wallet(tempAccount, currentState);
}

static async renameWallet(address, name, currentState?:State):Promise<boolean>{
static async renameWallet(address:string, name:string, currentState?:State):Promise<boolean>{
if(!currentState){
currentState = await StateManager.getState();
}
Expand Down
10 changes: 5 additions & 5 deletions snap/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,20 @@ export async function getAssets(wallet:Wallet, client:Client):Promise<Array<Asse
export async function getDataPacket(wallet:Wallet, client:Client):Promise<DataPacket>{
const currentAddress = wallet.currentState.currentAccount;
const accounts = await Wallet.listAccounts(wallet.currentState);
const name = wallet.currentState.accounts[currentAddress].name;
const name = wallet.currentState.accounts[String(currentAddress)]?.name ?? "Unknown";
const startingNetwork = client.network;
client.setNetwork('mainnet');
const mainnetAssets = await getAssets(wallet, client);
client.setNetwork('testnet');
const testnetAssets = await getAssets(wallet, client);
const mainnetXLMBalance = mainnetAssets[mainnetAssets.length-1].balance; //xlm is always the last asset
const testnetXLMBalance = testnetAssets[testnetAssets.length-1].balance;
const fedName = (await lookupAddress(currentAddress)).stellar_address;
const mainnetXLMBalance = mainnetAssets[mainnetAssets.length-1]?.balance ?? "0"; //xlm is always the last asset
const testnetXLMBalance = testnetAssets[testnetAssets.length-1]?.balance ?? "0";
const fedName = (await lookupAddress(currentAddress as string)).stellar_address;
client.setNetwork(startingNetwork);
return {
name,
accounts,
currentAddress,
currentAddress: currentAddress as string,
mainnetAssets,
testnetAssets,
mainnetXLMBalance,
Expand Down
4 changes: 2 additions & 2 deletions snap/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function createFederationAccount(account:Keypair, username:string):
*/
}

export async function lookupFedAccount(name):Promise<fedResponse>{
export async function lookupFedAccount(name:string):Promise<fedResponse>{
try{
const res = await fetch(`https://stellarid.io/federation/?q=${name}&type=name`, {
method: "GET",
Expand Down Expand Up @@ -117,6 +117,6 @@ export async function lookupAddress(address:string):Promise<fedResponse>{
catch(e){
console.log("there was an error");
console.log(e);
return {"stellar_address":null, account_id:null, "error":e};
return {"stellar_address":null, account_id:null, "error":String(e)};
}
}
9 changes: 1 addition & 8 deletions snap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import { fund, Client } from './Client';
import { TxnBuilder } from './TxnBuilder';
import { WalletFuncs } from './WalletFuncs';
import { Screens } from './screens';
import {createFederationAccount, lookupAddress, lookupFedAccount} from './federation'
import {lookupAddress, lookupFedAccount} from './federation'
import { NotificationEngine } from './notificationEngine';

import { OnCronjobHandler } from '@metamask/snaps-types';
import { parseRawSimulation } from './sorobanTxn';
import Utils from './Utils';
import { StateManager } from './stateManager';
import {getAssets, getDataPacket} from './assets';
Expand Down Expand Up @@ -187,11 +185,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ origin, request }) =>
return await operations.signAndSubmitTransaction(params.transaction);
}

case 'callContract':
//params.params
//params.address
return "null"

case 'createFederationAccount':
return await Screens.setUpFedAccount(wallet);

Expand Down
10 changes: 3 additions & 7 deletions snap/screens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Screens{
return await Utils.displayPanel(disp, 'prompt');
}

static async SameNameWarning(name){
static async SameNameWarning(name:string){
const disp = panel([
heading(`${name} is already taken`),
divider(),
Expand Down Expand Up @@ -115,7 +115,7 @@ export class Screens{
result = await createFederationAccount(wallet.keyPair, name as string);
if(result.error){
if(result.error === "username is already in use"){
await Screens.SameNameWarning(name);
await Screens.SameNameWarning(name as string);
continue;
}
if(result.error === "address already has an account"){
Expand Down Expand Up @@ -165,7 +165,7 @@ export class Screens{
}
}

static async confirmAccountChange(origin, accountName, accountAddress):Promise<boolean>{
static async confirmAccountChange(origin:string, accountName:string, accountAddress:string):Promise<boolean>{
const disp = panel([
heading('Switch Account?'),
divider(),
Expand All @@ -178,10 +178,6 @@ export class Screens{
return (await Utils.displayPanel(disp, 'confirmation')) as boolean;
}

static async homeScreen(wallet){

}

static async clearStateConfirmation():Promise<boolean>{
const disp = panel([
heading("Would you like to clear all state?"),
Expand Down
1 change: 1 addition & 0 deletions snap/screens/qr.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'qrcode-svg';
60 changes: 59 additions & 1 deletion snap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,66 @@ export interface AssetBalance{
asset_issuer: string, //address
}

export type walletAsset = AssetBalance | NativeBalance
export type json_Asset = {
issuer: string
code: string
}

export interface NativeBalance{
balance:string,
liquidity_pool_id?:string,
limit: string,
buying_liabilites: string,
selling_liabilites: string,
sponser?: string,
last_modified_ledger: number,
is_authorized: boolean,
is_authorized_to_maintain_liabilites: boolean,
is_clawback_enabled: boolean,
asset_type: "native",
asset_issuer: "native"
asset_code: "XLM"
}

export interface AssetBalance{
balance:string, //number
liquidity_pool_id?:string, //number
limit: string, //number
buying_liabilites: string, //number
selling_liabilites: string, //number
sponser?: string, //address
last_modified_ledger: number,
is_authorized: boolean,
is_authorized_to_maintain_liabilites: boolean,
is_clawback_enabled: boolean,
asset_type: "credit_alphanum4"|"credit_alphanum12"
asset_code: string,
asset_issuer: string, //address
}

export type walletAsset = AssetBalance | NativeBalance

const emptyNativeBalance:NativeBalance = {
balance:"0",
limit: "Infinity",
buying_liabilites: "0",
selling_liabilites: "0",
last_modified_ledger: Date.now(),
is_authorized: true,
is_authorized_to_maintain_liabilites: true,
is_clawback_enabled: false,
asset_type: "native",
asset_issuer: "native",
asset_code: "XLM"
}

export interface DataPacket{
name:string,
currentAddress:string,
mainnetAssets?: walletAsset[],
testnetAssets?: walletAsset[],
accounts: Array<{name:String, address:String}>
mainnetXLMBalance: string,
testnetXLMBalance: string,
fedName: string | null
}

0 comments on commit 5effd4f

Please sign in to comment.