mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-03-03 20:07:11 +01:00
FIX: Replace schema with empty string
This commit is contained in:
parent
c7f9466639
commit
e1fd3952e8
5 changed files with 162 additions and 6 deletions
149
class/acinqStrikeLightningWallet.js
Normal file
149
class/acinqStrikeLightningWallet.js
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
import { LegacyWallet } from './legacy-wallet';
|
||||||
|
import Frisbee from 'frisbee';
|
||||||
|
import { BitcoinUnit } from '../models/bitcoinUnits';
|
||||||
|
|
||||||
|
export class ACINQStrikeLightningWallet extends LegacyWallet {
|
||||||
|
static type = 'acinqStrikeLightningWallet';
|
||||||
|
static typeReadable = 'strike';
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.setBaseURI(); // no args to init with default value
|
||||||
|
this.init();
|
||||||
|
this.secret = '';
|
||||||
|
this.user_charges_raw = [];
|
||||||
|
this.preferredBalanceUnit = BitcoinUnit.SATS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* requires calling init() after setting
|
||||||
|
*
|
||||||
|
* @param URI
|
||||||
|
*/
|
||||||
|
setBaseURI(URI) {
|
||||||
|
if (URI) {
|
||||||
|
this.baseURI = URI;
|
||||||
|
} else {
|
||||||
|
this.baseURI = 'https://api.strike.acinq.co/api/v1';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getBaseURI() {
|
||||||
|
return this.baseURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
allowSend() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
timeToRefreshBalance() {
|
||||||
|
// only manual refresh for now
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
timeToRefreshTransaction() {
|
||||||
|
// only manual refresh for now
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(param) {
|
||||||
|
let obj = super.fromJson(param);
|
||||||
|
obj.init();
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this._api = new Frisbee({
|
||||||
|
baseURI: this.baseURI,
|
||||||
|
headers: {
|
||||||
|
'cache-control': 'no-cache',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setSecret(secret) {
|
||||||
|
this.secret = secret;
|
||||||
|
this._api.auth(this.secret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns list of LND invoices created by user
|
||||||
|
*
|
||||||
|
* @return {Promise.<Array>}
|
||||||
|
*/
|
||||||
|
async getCharge(chargeId) {
|
||||||
|
let response = await this._api.get('/charges/' + chargeId);
|
||||||
|
let json = response.body;
|
||||||
|
if (typeof json === 'undefined') {
|
||||||
|
throw new Error('API failure: ' + response.err + ' ' + JSON.stringify(response.originalResponse));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json && json.error) {
|
||||||
|
throw new Error('API error: ' + json.message + ' (code ' + json.code + ')');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.user_charges_raw = json.sort((a, b) => {
|
||||||
|
return a.created - b.created;
|
||||||
|
});
|
||||||
|
|
||||||
|
return this.user_charges_raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
async getUserCharges() {
|
||||||
|
let response = await this._api.get('/charges');
|
||||||
|
let json = response.body;
|
||||||
|
if (typeof json === 'undefined') {
|
||||||
|
throw new Error('API failure: ' + response.err + ' ' + JSON.stringify(response.originalResponse));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json && json.code && json.code === 401) {
|
||||||
|
throw new Error('API error: ' + json.message + ' (code ' + json.code + ')');
|
||||||
|
}
|
||||||
|
this.user_charges_raw = json.sort((a, b) => {
|
||||||
|
return a.created - b.created;
|
||||||
|
});
|
||||||
|
return this.user_charges_raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basically the same as this.getUserInvoices() but saves invoices list
|
||||||
|
* to internal variable
|
||||||
|
*
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
getTransactions() {
|
||||||
|
console.warn('heee');
|
||||||
|
|
||||||
|
return this.user_charges_raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
async authenticate() {
|
||||||
|
await this.getUserCharges();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async createCharge(amount, description = 'ACINQ strike Charge') {
|
||||||
|
let response = await this._api.post('/charges', {
|
||||||
|
body: { amount: Number(amount), description: String(description), currency: 'btc' },
|
||||||
|
auth: {
|
||||||
|
user: this.secret,
|
||||||
|
pass: '',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
let json = response.body;
|
||||||
|
if (typeof json === 'undefined') {
|
||||||
|
throw new Error('API failure: ' + response.err + ' ' + JSON.stringify(response.originalResponse));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json && json.code) {
|
||||||
|
throw new Error('API error: ' + json.message + ' (code ' + json.code + ')');
|
||||||
|
}
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
allowReceive() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,3 +10,4 @@ export * from './hd-legacy-p2pkh-wallet';
|
||||||
export * from './watch-only-wallet';
|
export * from './watch-only-wallet';
|
||||||
export * from './lightning-custodian-wallet';
|
export * from './lightning-custodian-wallet';
|
||||||
export * from './abstract-hd-wallet';
|
export * from './abstract-hd-wallet';
|
||||||
|
export * from './acinqStrikeLightningWallet';
|
||||||
|
|
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -3386,9 +3386,9 @@
|
||||||
"integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs="
|
"integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs="
|
||||||
},
|
},
|
||||||
"dayjs": {
|
"dayjs": {
|
||||||
"version": "1.8.0",
|
"version": "1.8.2",
|
||||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.0.tgz",
|
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.2.tgz",
|
||||||
"integrity": "sha512-2ofInmfMKLLR5R02q3WEUuDt86UK33VQQTaEeJudF+C04ZUaekCP3VpB0NJPiyPDCGJWq9XYhHX2AemdxA8+dg=="
|
"integrity": "sha512-iHNxe5kIbxmPgzJFjks9TFMokOu3TQcUUSagb/Ff7GZNi7ulYF0qaAZ61trZEFOONgrp4jvKVpBJ86qy4UsSoA=="
|
||||||
},
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
"buffer": "^5.2.1",
|
"buffer": "^5.2.1",
|
||||||
"buffer-reverse": "^1.0.1",
|
"buffer-reverse": "^1.0.1",
|
||||||
"crypto-js": "^3.1.9-1",
|
"crypto-js": "^3.1.9-1",
|
||||||
"dayjs": "^1.8.0",
|
"dayjs": "^1.8.2",
|
||||||
"electrum-client": "git+https://github.com/Overtorment/node-electrum-client.git",
|
"electrum-client": "git+https://github.com/Overtorment/node-electrum-client.git",
|
||||||
"electrum-host-parse": "^0.1.1",
|
"electrum-host-parse": "^0.1.1",
|
||||||
"eslint-config-prettier": "^4.0.0",
|
"eslint-config-prettier": "^4.0.0",
|
||||||
|
|
|
@ -556,9 +556,15 @@ export default class SendDetails extends Component {
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const { address, amount, memo } = this.decodeBitcoinUri(text);
|
const { address, amount, memo } = this.decodeBitcoinUri(text);
|
||||||
this.setState({ address, amount, memo, isLoading: false, bip70TransactionExpiration: null });
|
this.setState({
|
||||||
|
address: address.replace('bitcoin:', ''),
|
||||||
|
amount,
|
||||||
|
memo,
|
||||||
|
isLoading: false,
|
||||||
|
bip70TransactionExpiration: null,
|
||||||
|
});
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
this.setState({ address: text.trim(), isLoading: false, bip70TransactionExpiration: null });
|
this.setState({ address: text.trim().replace('bitcoin:', ''), isLoading: false, bip70TransactionExpiration: null });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue