1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
// Arching Kaos Donation Section
//
// Kaotisk Hund - 2024
//
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL v3.0
//
import { makeElement } from "../../arching-kaos-generator.js";
export async function freighterWalletConnect()
{
if ( await window.freighterApi.isConnected() )
{
let publicKey = "";
let error = "";
const accessObj = await window.freighterApi.requestAccess();
if (accessObj.error) {
return accessObj.error;
} else {
document.querySelector("#freighter-connect-button").innerText = accessObj.address;
document.querySelector("#freighter-connect-button").onclick = '';
// putKeyToField(accessObj.address);
return accessObj.address;
}
return publicKey;
}
else
{
console.log("fr fail");
}
}
function putKeyToField(k){
const address = k;
var base = document.querySelector("#freighter-connect-button");
base.innerText=address;
base.onclick='';
// stellar_connection_status = 1;
// checkAddressForConfigurationVariable(k);
}
export async function triggerDonation()
{
// try {
// ................................................... this element where the address should go when you connect the
var sourcePublicKey = document.querySelector("#freighter-connect-button").innerHTML; // extension with
// ^ the id of the element we query // the page.
const SERVER_URL = "https://horizon.stellar.org";
const server = new StellarSdk.Horizon.Server(SERVER_URL);
const account = await server.loadAccount(sourcePublicKey);
const fee = await server.fetchBaseFee();
const receiverPublicKey = "GAEVVR57OWKRXH2WLTEVTNT3NFSXN7MIZNJH2NFNPBJF4MYT4BNKJGXA"
const amount_to_send = document.querySelector("#donation-amount").value;
const kh_min = 20000000*amount_to_send;
const transaction = new StellarSdk.TransactionBuilder(account, { fee, networkPassphrase: StellarSdk.Networks.PUBLIC, })
/* The part that changes */
.addOperation(StellarSdk.Operation.pathPaymentStrictSend({
destination: receiverPublicKey,
sendAsset: new StellarSdk.Asset("XLM"),
sendAmount: String(amount_to_send),
destAsset: new StellarSdk.Asset("KAOTISKHUND","GDLJKMETTIXAVTZ2XXR2LHUITT7GZBNWEKQDN7V7SP4MURVY6266BIMO"),
destMin: String(kh_min),
path: [new StellarSdk.Asset("XLM"),new StellarSdk.Asset("KAOTISKHUND","GDLJKMETTIXAVTZ2XXR2LHUITT7GZBNWEKQDN7V7SP4MURVY6266BIMO")]
}))
/* End of part that changes */
.setTimeout(30)
// .addMemo(StellarSdk.Memo.text('Hello world!'))
.build();
const xdr = transaction.toXDR();
const userSignTransaction = async (
xdr,
network,
signWith
) => {
let signedTransaction = "";
let error = "";
try
{
signedTransaction = await window.freighterApi.signTransaction(
xdr,
{
address:signWith,
network
});
console.log(signTransaction);
}
catch (e)
{
error = e;
}
if (error)
{
return error;
}
return signedTransaction;
};
// const userSignedTransaction = await userSignTransaction(xdr, "PUBLIC", sourcePublicKey);
const userSignedTransaction = await window.freighterApi.signTransaction(xdr, {address: sourcePublicKey, network:"PUBLIC"});
console.log(userSignedTransaction);
const transactionToSubmit = StellarSdk.TransactionBuilder.fromXDR( userSignedTransaction.signedTxXdr, StellarSdk.Networks.PUBLIC );
try {
const response = await server.submitTransaction(transactionToSubmit);
// console.log(transaction.toEnvelope().toXDR('base64'));
console.log(JSON.stringify(response, null, 2));
console.log('\nSuccess! View the transaction at: ');
console.log(response._links.transaction.href);
makeElement(
{
element:"iframe",
onLoad:"var c=this;window.addEventListener('message',function({data,source}){if(c&&source===c.contentWindow&&data.widget===c.src)c.style.height=data.height+'px'},false);",
src:`https://stellar.expert/widget/public/tx/info/${response.id}`,
style:"border:none;overflow:hidden;max-width:100%; min-width:300px;max-height:100%;min-height:200px;width:100%"
},
document.querySelector("#donation-section").querySelector(".content")
);
} catch (e) {
console.log('An error has occured:');
console.log(e);
}
// } catch (e) {
// console.log(e);
// }
}
export function donationSection()
{
var whereAmI = {
element: "div",
className: "where-am-i",
innerHTML: [
{ element: "img", src:"./img/logo.png", onclick:"menusel({id:'#/welcome-section'})"},
{ element: "span", innerText:">"},
{ element: "h2", innerText:"Donation"}
]
};
var content = {
element: "div",
className: "content",
style: "display: flex; flex-direction: column; gap: 10px;",
innerHTML: [
{ element: "p", innerText:"If you like what you see and you want to contribute some memecoins you are free to do so using the XLM Freighter wallet."},
{ element: "p", innerText:"To donate, press the connect button below to connect your wallet."},
{
element:"button",
id:"freighter-connect-button",
onclick:"freighterWalletConnect()",
innerText: "Connect Freighter wallet"
},
{ element: "p", innerText:"You can enter the amount you want to donate in XLM on the input box below."},
{
element: "div",
style: "display: flex; gap: 5px;",
innerHTML: [
{ element: "input", type:"number", value:"1.0", placeholder:"1.0", step:"0.01", min:"0.01", max:"10", id:"donation-amount" },
{
element:"button",
id:"donate-button",
onclick:"triggerDonation()",
innerText: "Donate"
}
]
}
]
};
var donationSection = {
element: "div",
hidden: true,
id:"donation-section",
innerHTML: [
whereAmI,
content
]
};
makeElement(donationSection, document.querySelector('.main'));
}
// @license-end
|