-
Notifications
You must be signed in to change notification settings - Fork 3
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
12 changed files
with
1,862 additions
and
990 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
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,42 @@ | ||
module.exports = { | ||
env: { | ||
es6: true, | ||
}, | ||
parser: "@babel/eslint-parser", | ||
extends: ["airbnb-base", "prettier"], | ||
plugins: ["prettier", "prefer-import"], | ||
rules: { | ||
// OFF | ||
"import/prefer-default-export": 0, | ||
"node/no-unsupported-features/es-syntax": 0, | ||
"node/no-unsupported-features/es-builtins": 0, | ||
camelcase: 0, | ||
"class-methods-use-this": 0, | ||
"linebreak-style": 0, | ||
"new-cap": 0, | ||
"no-param-reassign": 0, | ||
"no-underscore-dangle": 0, | ||
"no-use-before-define": 0, | ||
"prefer-destructuring": 0, | ||
"lines-between-class-members": 0, | ||
|
||
// WARN | ||
"prefer-import/prefer-import-over-require": [1], | ||
"no-console": ["warn", { allow: ["assert"] }], | ||
"no-debugger": 1, | ||
"no-unused-vars": 1, | ||
"arrow-body-style": 1, | ||
"valid-jsdoc": [ | ||
1, | ||
{ | ||
requireReturnDescription: false, | ||
}, | ||
], | ||
"prefer-const": 1, | ||
"object-shorthand": 1, | ||
"require-await": 1, | ||
|
||
// ERROR | ||
"no-unused-expressions": [2, { allowTaggedTemplates: true }], | ||
}, | ||
}; |
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,72 @@ | ||
import { | ||
Account, | ||
FeeBumpTransaction, | ||
Operation, | ||
Transaction, | ||
TransactionBuilder, | ||
xdr, | ||
Networks, | ||
Asset | ||
} from "stellar-base"; | ||
import { Client } from "./Client"; | ||
|
||
export class TxnBuilder{ | ||
account: Account | ||
client: Client | ||
constructor(account: Account){ | ||
this.account = account; | ||
} | ||
|
||
createAccountTxn(destination: string, amount: string, fee?:string): Transaction{ | ||
if(!fee){ | ||
console.log("no fee provided") | ||
fee = "1000" | ||
} | ||
|
||
const transactionBuilder = new TransactionBuilder(this.account, {fee, networkPassphrase: Networks.TESTNET }) | ||
console.log("transaction initialized"); | ||
console.log(transactionBuilder); | ||
transactionBuilder | ||
.addOperation(Operation.createAccount({ | ||
destination: destination, | ||
startingBalance: amount | ||
})) // <- funds and creates destinationA | ||
.setTimeout(30) | ||
console.log(transactionBuilder); | ||
const transaction = transactionBuilder.build(); | ||
console.log(transaction); | ||
console.log(transaction.toXDR()); | ||
return transaction; | ||
} | ||
|
||
buildPaymentTxn(destination: string, amount: string, fee?:string): Transaction{ | ||
if(!fee){ | ||
console.log("no fee provided") | ||
fee = "1000" | ||
} | ||
|
||
const transactionBuilder = new TransactionBuilder(this.account, {fee, networkPassphrase: Networks.TESTNET }) | ||
console.log("transaction initialized"); | ||
console.log(transactionBuilder); | ||
transactionBuilder | ||
/* | ||
.addOperation(Operation.createAccount({ | ||
destination: destinationA, | ||
startingBalance: "20" | ||
})) // <- funds and creates destinationA | ||
*/ | ||
.addOperation(Operation.payment({ | ||
destination: destination, | ||
amount: amount, | ||
asset: Asset.native() | ||
})) // <- sends 100 XLM to destinationB | ||
.setTimeout(30) | ||
console.log(transactionBuilder); | ||
const transaction = transactionBuilder.build(); | ||
console.log(transaction); | ||
console.log(transaction.toXDR()); | ||
return transaction; | ||
} | ||
|
||
|
||
} |
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,99 @@ | ||
|
||
|
||
/* | ||
Class for utility functions | ||
wallet is a global in the metamask context | ||
*/ | ||
import { panel, text, heading, divider, copyable, Panel } from '@metamask/snaps-ui'; | ||
export default class Utils { | ||
|
||
static throwError(code, msg){ | ||
if(code === undefined){ | ||
code = 0 | ||
} | ||
//metamask overrides Error codes | ||
//This function encodes an arc complient error code | ||
//into the error message, and is then seperated by the SDK | ||
console.log(JSON.stringify(msg)); | ||
throw new Error(`${code}\n${msg}`); | ||
} | ||
|
||
static async notify(message: string): Promise<boolean>{ | ||
try{ | ||
await snap.request({ | ||
method: 'snap_notify', | ||
params: { | ||
type: 'inApp', | ||
message: message, | ||
}, | ||
}); | ||
|
||
const result = await snap.request({ | ||
method: 'snap_notify', | ||
params: { | ||
type: 'native', | ||
message: message, | ||
}, | ||
}); | ||
return true; | ||
} | ||
catch(e){ | ||
console.log("error - ") | ||
console.log(e); | ||
await Utils.sendConfirmation("alert", "notifcation", message); | ||
return false; | ||
} | ||
|
||
|
||
} | ||
|
||
static async sendConfirmation(prompt: string, description: string, textAreaContent: string): Promise<boolean>{ | ||
if(!textAreaContent){ | ||
textAreaContent = "" | ||
} | ||
const confirm= await snap.request({ | ||
method: 'snap_dialog', | ||
params: { | ||
type: 'confirmation', | ||
content: panel([ | ||
heading(prompt), | ||
divider(), | ||
text(description), | ||
divider(), | ||
text(textAreaContent), | ||
]), | ||
}, | ||
}); | ||
|
||
return confirm; | ||
} | ||
|
||
static async sendAlert(title: string, info: string): Promise<boolean>{ | ||
const alert = await snap.request({ | ||
method: 'snap_dialog', | ||
params:{ | ||
type: 'alert', | ||
content: panel([ | ||
heading(title), | ||
divider(), | ||
text(info) | ||
]) | ||
} | ||
}) | ||
return true; | ||
} | ||
|
||
static async displayPanel(panel: Panel, type:"confirmation" | "alert" | "prompt" = "confirmation"): Promise<any>{ | ||
const disp = await snap.request({ | ||
method: 'snap_dialog', | ||
params:{ | ||
type: type, | ||
content: panel | ||
} | ||
}) | ||
return disp | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.