Skip to content

Commit

Permalink
Merge pull request #1530 from synonymdev/update-exchange-rates
Browse files Browse the repository at this point in the history
fix(wallet): Re-Adds updateExchangeRates to setupOnChainWallet
  • Loading branch information
coreyphillips authored Feb 1, 2024
2 parents 1162155 + 1367c92 commit 8de8504
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@synonymdev/web-relay": "1.0.7",
"backpack-client": "github:synonymdev/bitkit-backup-client#f08fdb28529d8a3f8bfecc789443c43b966a7581",
"bech32": "2.0.0",
"beignet": "0.0.19",
"beignet": "0.0.20",
"bip21": "2.0.3",
"bip32": "4.0.0",
"bip39": "3.0.4",
Expand Down
6 changes: 1 addition & 5 deletions src/store/actions/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ import {
EAvailableNetworks,
EFeeId,
getDefaultWalletData,
getExchangeRates,
getStorageKeyValues,
IBoostedTransaction,
IExchangeRates,
IOnchainFees,
IOutput,
ISendTransaction,
Expand All @@ -53,6 +51,7 @@ import {
import { ETransactionSpeed } from '../types/settings';
import { updateOnchainFeeEstimates } from '../utils/fees';
import { getMaxSendAmount } from '../../utils/wallet/transactions';
import { getExchangeRates, IExchangeRates } from '../../utils/exchange-rate';

export const updateWallet = (
payload: Partial<IWalletStore>,
Expand Down Expand Up @@ -815,9 +814,6 @@ export const setWalletData = async <K extends keyof IWalletData>(
selectedNetwork: getNetworkFromBeignet(network),
});
break;
case 'exchangeRates':
updateExchangeRates(data as IExchangeRates);
break;
case 'feeEstimates':
updateOnchainFeeEstimates({
selectedNetwork: getNetworkFromBeignet(network),
Expand Down
73 changes: 41 additions & 32 deletions src/utils/lightning/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import lm, {
TPaymentReq,
TTransactionData,
TTransactionPosition,
TGetFees,
} from '@synonymdev/react-native-ldk';

import {
Expand Down Expand Up @@ -89,6 +90,8 @@ import {
__BACKUPS_SERVER_PUBKEY__,
__TRUSTED_ZERO_CONF_PEERS__,
} from '../../constants/env';
import { TBroadcastTransaction } from '@synonymdev/react-native-ldk/dist/utils/types';
import { TGetAddressHistory } from 'beignet';

let LDKIsStayingSynced = false;

Expand Down Expand Up @@ -161,6 +164,37 @@ const LDK_ACCOUNT_SUFFIX_V2 = 'ldkaccountv2';
export const setLdkStoragePath = (): Promise<Result<string>> =>
lm.setBaseStoragePath(`${RNFS.DocumentDirectoryPath}/ldk/`);

const broadcastTransaction: TBroadcastTransaction = async (
rawTx: string,
): Promise<Result<string>> => {
const electrum = getOnChainWalletElectrum();
return await electrum.broadcastTransaction({
rawTx,
subscribeToOutputAddress: false,
});
};

const getScriptPubKeyHistory = async (
scriptPubKey: string,
): Promise<TGetAddressHistory[]> => {
const electrum = getOnChainWalletElectrum();
return await electrum.getScriptPubKeyHistory(scriptPubKey);
};

const getFees: TGetFees = async () => {
const fees = getFeesStore().onchain;
return {
//https://github.com/lightningdevkit/rust-lightning/blob/main/CHANGELOG.md#api-updates
onChainSweep: fees.fast,
maxAllowedNonAnchorChannelRemoteFee: Math.max(25, fees.fast * 10),
minAllowedAnchorChannelRemoteFee: fees.minimum,
minAllowedNonAnchorChannelRemoteFee: Math.max(fees.minimum - 1, 0),
anchorChannelFee: fees.slow,
nonAnchorChannelFee: fees.normal,
channelCloseMinimum: fees.minimum,
};
};

/**
* Used to spin-up LDK services.
* In order, this method:
Expand All @@ -170,8 +204,8 @@ export const setLdkStoragePath = (): Promise<Result<string>> =>
* 5. Syncs LDK.
*/
export const setupLdk = async ({
selectedWallet,
selectedNetwork,
selectedWallet = getSelectedWallet(),
selectedNetwork = getSelectedNetwork(),
shouldRefreshLdk = true,
staleBackupRecoveryMode = false,
shouldPreemptivelyStopLdk = true,
Expand All @@ -185,12 +219,6 @@ export const setupLdk = async ({
try {
pendingRefreshPromises = [];
isRefreshing = false;
if (!selectedWallet) {
selectedWallet = getSelectedWallet();
}
if (!selectedNetwork) {
selectedNetwork = getSelectedNetwork();
}

if (shouldPreemptivelyStopLdk) {
// start from a clean slate
Expand Down Expand Up @@ -249,35 +277,16 @@ export const setupLdk = async ({
return err(storageRes.error);
}
const rapidGossipSyncUrl = getStore().settings.rapidGossipSyncUrl;
const electrum = getOnChainWalletElectrum();
const lmStart = await lm.start({
account: account.value,
getFees: async () => {
const fees = getFeesStore().onchain;
return {
//https://github.com/lightningdevkit/rust-lightning/blob/main/CHANGELOG.md#api-updates
onChainSweep: fees.fast,
maxAllowedNonAnchorChannelRemoteFee: Math.max(25, fees.fast * 10),
minAllowedAnchorChannelRemoteFee: fees.minimum,
minAllowedNonAnchorChannelRemoteFee: Math.max(fees.minimum - 1, 0),
anchorChannelFee: fees.slow,
nonAnchorChannelFee: fees.normal,
channelCloseMinimum: fees.minimum,
};
},
getFees,
network,
getBestBlock,
getAddress,
broadcastTransaction: (rawTx) =>
electrum.broadcastTransaction({
rawTx,
subscribeToOutputAddress: false,
}),
getTransactionData: (txId) => getTransactionData(txId),
getScriptPubKeyHistory: electrum.getScriptPubKeyHistory,
getTransactionPosition: (params) => {
return getTransactionPosition(params);
},
broadcastTransaction,
getTransactionData,
getScriptPubKeyHistory,
getTransactionPosition,
forceCloseOnStartup: {
forceClose: staleBackupRecoveryMode,
broadcastLatestTx: false,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
generateNewReceiveAddress,
getWalletData,
setWalletData,
updateExchangeRates,
updateWallet,
} from '../../store/actions/wallet';
import { TCoinSelectPreference } from '../../store/types/settings';
Expand Down Expand Up @@ -1569,6 +1570,7 @@ export const setupOnChainWallet = async ({
setData: setWalletData,
};
}
updateExchangeRates();
const createWalletResponse = await Wallet.create({
name,
mnemonic,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5563,10 +5563,10 @@ bech32@^1.1.2, bech32@^1.1.4:
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9"
integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ==

[email protected].19:
version "0.0.19"
resolved "https://registry.yarnpkg.com/beignet/-/beignet-0.0.19.tgz#9d5242ecb9f6853bc3c3b62e2a79c7c45cc546e2"
integrity sha512-A8fCZ3XiCmtWaU3nneXRZ9pJ2XBqVVfHQDyf7F6AXhKFcX9e6VVFBglQDsNEDAgFBUK9wBQmusktpeDYFT+Xpg==
[email protected].20:
version "0.0.20"
resolved "https://registry.yarnpkg.com/beignet/-/beignet-0.0.20.tgz#2f11389dacac1957eb36bf26b7bb7319d69ff241"
integrity sha512-m816N3mJ/wfIcHpX+bpFMsyrvn6yviXQqekMvmqcB1QNKNJ0MFp4Nt9b3+rRB4HvwmayJqyHDvhI+TAyZ+UUJA==
dependencies:
"@bitcoinerlab/secp256k1" "1.0.5"
bech32 "2.0.0"
Expand Down

0 comments on commit 8de8504

Please sign in to comment.