WIP: maturing ETA for ldk onchain balance

This commit is contained in:
Overtorment 2021-11-02 11:57:36 +00:00
parent 237eae4274
commit 9b4f82244a
4 changed files with 19 additions and 3 deletions

View file

@ -110,6 +110,10 @@ export class LightningLdkWallet extends LightningCustodianWallet {
return RnLdk.getMaturingBalance();
}
async getMaturingHeight(): Promise<number> {
return RnLdk.getMaturingHeight();
}
/**
* Probes getNodeId() call. if its available - LDK has started
*

4
package-lock.json generated
View file

@ -20918,8 +20918,8 @@
}
},
"rn-ldk": {
"version": "git+https://github.com/BlueWallet/rn-ldk.git#0a68c7b7d0c95bfedda0a0ae2028a56dc6af3584",
"from": "git+https://github.com/BlueWallet/rn-ldk.git#v0.5.2"
"version": "git+https://github.com/BlueWallet/rn-ldk.git#v0.6.0",
"from": "git+https://github.com/BlueWallet/rn-ldk.git#v0.6.0"
},
"rn-nodeify": {
"version": "10.3.0",

View file

@ -189,7 +189,7 @@
"react-test-render": "1.1.2",
"readable-stream": "3.6.0",
"realm": "10.9.1",
"rn-ldk": "git+https://github.com/BlueWallet/rn-ldk.git#v0.5.2",
"rn-ldk": "git+https://github.com/BlueWallet/rn-ldk.git#v0.6.0",
"rn-nodeify": "10.3.0",
"scryptsy": "2.1.0",
"secure-random": "1.1.2",

View file

@ -41,6 +41,7 @@ const LdkInfo = () => {
const [pendingChannels, setPendingChannels] = useState<any[]>([]);
const [wBalance, setWalletBalance] = useState<{ confirmedBalance?: number }>({});
const [maturingBalance, setMaturingBalance] = useState(0);
const [maturingEta, setMaturingEta] = useState('');
const centerContent = channels.length === 0 && pendingChannels.length === 0 && inactiveChannels.length === 0;
const allChannelsAmount = useRef(0);
// Modals
@ -118,6 +119,16 @@ const LdkInfo = () => {
setWalletBalance(walletBalance);
setMaturingBalance(await wallet.getMaturingBalance());
const maturingHeight = await wallet.getMaturingHeight();
if (maturingHeight > 0) {
const result = await fetch('https://blockstream.info/api/blocks/tip/height');
const tip = await result.text();
const hrs = Math.ceil((maturingHeight - +tip) / 6); // convert blocks to hours
setMaturingEta(`${hrs} hours`);
} else {
setMaturingEta('');
}
} catch (e) {
console.log(e);
} finally {
@ -417,6 +428,7 @@ const LdkInfo = () => {
</>
) : null}
{maturingBalance ? <Text style={[stylesHook.detailsText]}>Balance awaiting confirmations: {maturingBalance} sat</Text> : null}
{maturingEta ? <Text style={[stylesHook.detailsText]}>ETA: {maturingEta}</Text> : null}
<Button text={loc.lnd.new_channel} onPress={navigateToOpenPrivateChannel} disabled={isLoading} />
<BlueSpacing20 />
</View>