@@ -144,49 +144,117 @@ function updateFee(num, onNode, dedc) {
144144 num . value = numv ;
145145}
146146
147- function finalizeWithdraw ( amount , status ) {
148-
149- }
150-
151147function updateNetwork ( to ) {
148+ var nodes = [ document . getElementById ( "wnspd" ) , document . getElementById ( "wnlgn" ) , document . getElementById ( "wnbtc" ) , document . getElementById ( "wnbnb" ) ] ;
152149 var mn = document . getElementById ( "wtminimum" ) ;
153150 var mx = document . getElementById ( "wtmaximum" ) ;
154151 var fee = document . getElementById ( "withdrawfee" ) ;
155152 var amount = document . getElementById ( "withdrawamount" ) ;
156153 var spad = document . getElementById ( "speedad" ) ;
157- var ded = document . getElementById ( 'withdrawdeduct' )
154+ var bnad = document . getElementById ( "binancead" ) ;
155+ var ded = document . getElementById ( 'withdrawdeduct' ) ;
156+ for ( i of nodes ) i . style . display = "none" ;
157+ spad . style . display = "none" ;
158+ bnad . style . display = "none" ;
158159 if ( to === "spd" ) {
159160 mn . innerHTML = "10" ;
160161 mx . innerHTML = "10000" ;
161162 fee . innerHTML = "2" ;
162163 amount . min = 10 ;
163164 amount . max = 10000 ;
164165 spad . style . display = "block" ;
166+ nodes [ 0 ] . style . display = "flex" ;
165167 } else if ( to === "lgn" ) {
166168 mn . innerHTML = "2000" ;
167169 mx . innerHTML = "10000" ;
168170 fee . innerHTML = "100" ;
169171 amount . min = 2000 ;
170172 amount . max = 100000 ;
171- spad . style . display = "none " ;
173+ nodes [ 1 ] . style . display = "flex " ;
172174 } else if ( to === "btc" ) {
173175 mn . innerHTML = "20000" ;
174176 mx . innerHTML = "1000000" ;
175177 fee . innerHTML = "3000" ;
176178 amount . min = 20000 ;
177179 amount . max = 1000000 ;
178- spad . style . display = "none " ;
180+ nodes [ 2 ] . style . display = "flex " ;
179181 } else if ( to === "bnb" ) {
180182 mn . innerHTML = "100" ;
181183 mx . innerHTML = "100000000" ;
182184 fee . innerHTML = "0" ;
183185 amount . min = 100 ;
184186 amount . max = 100000000 ;
185- spad . style . display = "none" ;
187+ bnad . style . display = "block" ;
188+ nodes [ 3 ] . style . display = "flex" ;
186189 }
187190 updateFee ( amount , fee , ded ) ;
188191}
189192
193+ async function finalizeWithdraw ( amount , network , status ) {
194+ var address = document . getElementById ( "withdrawaddress" + network ) . value ;
195+ status . innerHTML = "Please wait..." ;
196+ if ( ! address || ! address . value ) {
197+ if ( ( network === "spd" ) || ( network === "btc" ) ) status . innerHTML = "Please enter a valid address." ;
198+ if ( network === "lgn" ) status . innerHTML = "Please enter a valid invoice." ;
199+ if ( ( network === "bnb" ) ( / ^ \d + $ / . test ( address ) ) ) status . innerHTML = "Please enter a valid Binance ID." ;
200+ return ;
201+ }
202+ if ( ( network === "spd" ) && ( ( address . includes ( "@speed.app" ) && ! / [ 0 - 9 A - Z a - z \. _ ] + / . test ( address . substring ( 0 , address . length - 10 ) ) ) || ! / [ 0 - 9 A - Z a - z \. _ ] + / . test ( address ) ) ) {
203+ status . innerHTML = "Please enter a valid Speed Wallet address." ;
204+ return ;
205+ }
206+ if ( ( network === "lgn" ) && ! address . startsWith ( "lnbc" ) ) {
207+ status . innerHTML = "Please enter a valid invoice." ;
208+ return ;
209+ }
210+ if ( ( network === "bnb" ) && ! / ^ \d + $ / . test ( address ) ) {
211+ status . innerHTML = "Please enter a valid Binance ID." ;
212+ return ;
213+ }
214+
215+ if ( ( network === "spd" && ( ( amount < 10 ) || ( amount > 10000 ) ) ) || ( network === "lgn" && ( ( amount < 2000 ) || ( amount > 10000 ) ) ) || ( network === "btc" && ( ( amount < 20000 ) || ( amount > 1000000 ) ) ) || ( network === "bnb" && ( ( amount < 100 ) || ( amount > 100000000 ) ) ) ) {
216+ status . innerHTML = "Please enter a valid amount." ;
217+ }
218+
219+ var bls = await getBalance ( ( await supabase . auth . getSession ( ) ) . data . session ?. user . id ) ;
220+ if ( ! bls ) {
221+ location . href = "login.html" ;
222+ return ;
223+ }
224+ bls = bls [ 2 ] ;
225+
226+ var fee = 0 ;
227+ if ( network === "spd" ) fee = amount . length ;
228+ if ( network === "lgn" ) fee = 100 ;
229+ if ( network === "btc" ) fee = 3000 ;
230+
231+ if ( bls < ( amount + fee ) ) {
232+ status . innerHTML = "Insufficient funds."
233+ return ;
234+ }
235+
236+ await fetch ( 'https://jwpvozanqtemykhdqhvk.supabase.co/functions/v1/withdrawRequest' , {
237+ method : 'POST' ,
238+ headers : {
239+ 'Content-Type' : 'application/json' ,
240+ 'authorization' : `Bearer ${ ( await supabase . auth . getSession ( ) ) . data . session ?. access_token } `
241+ } ,
242+ body : JSON . stringify ( { uid : ( await supabase . auth . getSession ( ) ) . data . session ?. user . id , network : network , amount : amount , address : address } )
243+ } )
244+ . then ( response => response . json ( ) )
245+ . then ( data => {
246+ if ( ! data . sc ) {
247+ status . innerHTML = "Error: " + data . response ;
248+ } else {
249+ status . innerHTML = data . response ;
250+ loadWallet ( ) ;
251+ }
252+ } )
253+ . catch ( ( error ) => {
254+ console . error ( 'Error invoking function:' , error ) ;
255+ } ) ;
256+ }
257+
190258function withdraw ( ) {
191259 popup ( "Withdraw Bitcoin Satoshi" ,
192260 `
@@ -204,6 +272,10 @@ function withdraw() {
204272 < speed wallet ad >
205273 </div>
206274
275+ <div id="binancead" style="display:none">
276+ < binance ad >
277+ </div>
278+
207279 <p>
208280 Minimum Withdrawal: <span id="wtminimum">10</span> Satoshis<br>
209281 Maximum Withdrawal: <span id="wtmaximum">10000</span> Satoshis<br>
@@ -219,22 +291,25 @@ function withdraw() {
219291 <label for="withdrawaddressspd">Speed Wallet Address:</label>
220292 <input id="withdrawaddressspd" type="text" placeholder="johndoe@speed.app">
221293 </div>
222- <div class="input" id="wnlgn">
294+ <div class="input" id="wnlgn" style="display:none" >
223295 <label for="withdrawaddresslgn">Lightning Invoice:</label>
296+ <div class="halve">
224297 <input id="withdrawaddresslgn" type="text" placeholder="lnbc1500n1pw9q5g0pp5g0g0g0g0g0g0g0g0g0g0g0g">
225- </div>
226- <div class="input" id="wnbtc">
298+ <button onclick="popup('Lightning Invoice','Do not make the invoice contain a set amount of money to withdraw!<br>Doing so may result in your transaction being rejected.')">?</button>
299+ </div></div>
300+ <div class="input" id="wnbtc" style="display:none">
227301 <label for="withdrawaddressbtc">Bitcoin Address:</label>
228302 <input id="withdrawaddressbtc" type="text" placeholder="1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa">
229303 </div>
230- <div class="input" id="wnbnb">
304+ <div class="input" id="wnbnb" style="display:none" >
231305 <label for="withdrawaddressbnb">Binance ID:</label>
232306 <input id="withdrawaddressbnb" type="text" placeholder="12345678">
233307 </div>
234308 <p>Total to be deducted from your wallet: <span id="withdrawdeduct" style="font-weight: bold">12</span> Satoshis</p>
235- <p style="color: #ccc; text-align: center;">Withdrawals are processed manually.<br>If you don't receive your Satoshis within 7 days, please contact the support.</p>
309+ <p style="color: #ccc; text-align: center;">Withdrawals are processed manually.<br>If you don't receive your Satoshis within 7 days, please contact the support.<br>
310+ If your withdrawal gets rejected, you will be fully refunded (fee included).</p>
236311 <p id="withdrawstatus" style="font-weight: bold;text-align:center"></p>
237- <button class="fullwidth" onclick="finalizeWithdraw()">Request Withdrawal</button>
312+ <button class="fullwidth" onclick="finalizeWithdraw(document.getElementById('withdrawamount').value, document.getElementById('withdrawnetwork').value, document.getElementById('withdrawstatus') )">Request Withdrawal</button>
238313 <p style="margin:0">
239314 `
240315 ) ;
0 commit comments