feat: granular balances
+ We were not using the total balances stuff I removed -that was an attempt by Akin at one point to work around the SDK cross account balance issue. + Decided to keep `balance` as is so we don't have to change it everywhere else...still makes sense I think.
This commit is contained in:
parent
52bca60b3e
commit
45e585c9cf
6 changed files with 86 additions and 87 deletions
77
dist/bundle.es.js
vendored
77
dist/bundle.es.js
vendored
|
@ -754,7 +754,7 @@ const Lbry = {
|
||||||
blob_list: (params = {}) => daemonCallWithResult('blob_list', params),
|
blob_list: (params = {}) => daemonCallWithResult('blob_list', params),
|
||||||
|
|
||||||
// Wallet utilities
|
// Wallet utilities
|
||||||
account_balance: () => daemonCallWithResult('account_balance'),
|
account_balance: (params = {}) => daemonCallWithResult('account_balance', params),
|
||||||
account_decrypt: () => daemonCallWithResult('account_decrypt', {}),
|
account_decrypt: () => daemonCallWithResult('account_decrypt', {}),
|
||||||
account_encrypt: (params = {}) => daemonCallWithResult('account_encrypt', params),
|
account_encrypt: (params = {}) => daemonCallWithResult('account_encrypt', params),
|
||||||
account_unlock: (params = {}) => daemonCallWithResult('account_unlock', params),
|
account_unlock: (params = {}) => daemonCallWithResult('account_unlock', params),
|
||||||
|
@ -1317,6 +1317,14 @@ const selectBalance = reselect.createSelector(selectState$1, state => state.bala
|
||||||
|
|
||||||
const selectTotalBalance = reselect.createSelector(selectState$1, state => state.totalBalance);
|
const selectTotalBalance = reselect.createSelector(selectState$1, state => state.totalBalance);
|
||||||
|
|
||||||
|
const selectReservedBalance = reselect.createSelector(selectState$1, state => state.reservedBalance);
|
||||||
|
|
||||||
|
const selectClaimsBalance = reselect.createSelector(selectState$1, state => state.claimsBalance);
|
||||||
|
|
||||||
|
const selectSupportsBalance = reselect.createSelector(selectState$1, state => state.supportsBalance);
|
||||||
|
|
||||||
|
const selectTipsBalance = reselect.createSelector(selectState$1, state => state.tipsBalance);
|
||||||
|
|
||||||
const selectTransactionsById = reselect.createSelector(selectState$1, state => state.transactions || {});
|
const selectTransactionsById = reselect.createSelector(selectState$1, state => state.transactions || {});
|
||||||
|
|
||||||
const selectSupportsByOutpoint = reselect.createSelector(selectState$1, state => state.supports || {});
|
const selectSupportsByOutpoint = reselect.createSelector(selectState$1, state => state.supports || {});
|
||||||
|
@ -1879,37 +1887,22 @@ function creditsToString(amount) {
|
||||||
function doUpdateBalance() {
|
function doUpdateBalance() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const {
|
const {
|
||||||
wallet: { balance: balanceInStore }
|
wallet: { total: totalInStore }
|
||||||
} = getState();
|
} = getState();
|
||||||
lbryProxy.account_balance().then(response => {
|
lbryProxy.account_balance({ reserved_subtotals: true }).then(response => {
|
||||||
const { available } = response;
|
const { available, reserved, reserved_subtotals, total } = response;
|
||||||
const balance = parseFloat(available);
|
const { claims, supports, tips } = reserved_subtotals;
|
||||||
if (balanceInStore !== balance) {
|
const totalFloat = parseFloat(total);
|
||||||
|
if (totalInStore !== totalFloat) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: UPDATE_BALANCE,
|
type: UPDATE_BALANCE,
|
||||||
data: {
|
data: {
|
||||||
balance
|
totalBalance: totalFloat,
|
||||||
}
|
balance: parseFloat(available),
|
||||||
});
|
reservedBalance: parseFloat(reserved),
|
||||||
}
|
claimsBalance: parseFloat(claims),
|
||||||
});
|
supportsBalance: parseFloat(supports),
|
||||||
};
|
tipsBalance: parseFloat(tips)
|
||||||
}
|
|
||||||
|
|
||||||
function doUpdateTotalBalance() {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
const {
|
|
||||||
wallet: { totalBalance: totalBalanceInStore }
|
|
||||||
} = getState();
|
|
||||||
lbryProxy.account_list().then(accountList => {
|
|
||||||
const { lbc_mainnet: accounts } = accountList;
|
|
||||||
const totalSatoshis = accounts.length === 1 ? accounts[0].satoshis : accounts.reduce((a, b) => a.satoshis + b.satoshis);
|
|
||||||
const totalBalance = (Number.isNaN(totalSatoshis) ? 0 : totalSatoshis) / Math.pow(10, 8);
|
|
||||||
if (totalBalanceInStore !== totalBalance) {
|
|
||||||
dispatch({
|
|
||||||
type: UPDATE_TOTAL_BALANCE,
|
|
||||||
data: {
|
|
||||||
totalBalance
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1924,13 +1917,6 @@ function doBalanceSubscribe() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function doTotalBalanceSubscribe() {
|
|
||||||
return dispatch => {
|
|
||||||
dispatch(doUpdateTotalBalance());
|
|
||||||
setInterval(() => dispatch(doUpdateTotalBalance()), 5000);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function doFetchTransactions() {
|
function doFetchTransactions() {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(doFetchSupports());
|
dispatch(doFetchSupports());
|
||||||
|
@ -4624,6 +4610,10 @@ const buildDraftTransaction = () => ({
|
||||||
const defaultState$a = {
|
const defaultState$a = {
|
||||||
balance: undefined,
|
balance: undefined,
|
||||||
totalBalance: undefined,
|
totalBalance: undefined,
|
||||||
|
reservedBalance: undefined,
|
||||||
|
claimsBalance: undefined,
|
||||||
|
supportsBalance: undefined,
|
||||||
|
tipsBalance: undefined,
|
||||||
latestBlock: undefined,
|
latestBlock: undefined,
|
||||||
transactions: {},
|
transactions: {},
|
||||||
fetchingTransactions: false,
|
fetchingTransactions: false,
|
||||||
|
@ -4720,11 +4710,12 @@ const walletReducer = handleActions({
|
||||||
},
|
},
|
||||||
|
|
||||||
[UPDATE_BALANCE]: (state, action) => _extends$e({}, state, {
|
[UPDATE_BALANCE]: (state, action) => _extends$e({}, state, {
|
||||||
balance: action.data.balance
|
totalBalance: action.data.totalBalance,
|
||||||
}),
|
balance: action.data.balance,
|
||||||
|
reservedBalance: action.data.reservedBalance,
|
||||||
[UPDATE_TOTAL_BALANCE]: (state, action) => _extends$e({}, state, {
|
claimsBalance: action.data.claimsBalance,
|
||||||
totalBalance: action.data.totalBalance
|
supportsBalance: action.data.supportsBalance,
|
||||||
|
tipsBalance: action.data.tipsBalance
|
||||||
}),
|
}),
|
||||||
|
|
||||||
[CHECK_ADDRESS_IS_MINE_STARTED]: state => _extends$e({}, state, {
|
[CHECK_ADDRESS_IS_MINE_STARTED]: state => _extends$e({}, state, {
|
||||||
|
@ -5034,14 +5025,12 @@ exports.doSetTransactionListFilter = doSetTransactionListFilter;
|
||||||
exports.doToast = doToast;
|
exports.doToast = doToast;
|
||||||
exports.doToggleBlockChannel = doToggleBlockChannel;
|
exports.doToggleBlockChannel = doToggleBlockChannel;
|
||||||
exports.doToggleTagFollow = doToggleTagFollow;
|
exports.doToggleTagFollow = doToggleTagFollow;
|
||||||
exports.doTotalBalanceSubscribe = doTotalBalanceSubscribe;
|
|
||||||
exports.doUpdateBalance = doUpdateBalance;
|
exports.doUpdateBalance = doUpdateBalance;
|
||||||
exports.doUpdateBlockHeight = doUpdateBlockHeight;
|
exports.doUpdateBlockHeight = doUpdateBlockHeight;
|
||||||
exports.doUpdateChannel = doUpdateChannel;
|
exports.doUpdateChannel = doUpdateChannel;
|
||||||
exports.doUpdatePublishForm = doUpdatePublishForm;
|
exports.doUpdatePublishForm = doUpdatePublishForm;
|
||||||
exports.doUpdateSearchOptions = doUpdateSearchOptions;
|
exports.doUpdateSearchOptions = doUpdateSearchOptions;
|
||||||
exports.doUpdateSearchQuery = doUpdateSearchQuery;
|
exports.doUpdateSearchQuery = doUpdateSearchQuery;
|
||||||
exports.doUpdateTotalBalance = doUpdateTotalBalance;
|
|
||||||
exports.doUploadThumbnail = doUploadThumbnail;
|
exports.doUploadThumbnail = doUploadThumbnail;
|
||||||
exports.doWalletDecrypt = doWalletDecrypt;
|
exports.doWalletDecrypt = doWalletDecrypt;
|
||||||
exports.doWalletEncrypt = doWalletEncrypt;
|
exports.doWalletEncrypt = doWalletEncrypt;
|
||||||
|
@ -5121,6 +5110,7 @@ exports.selectChannelImportPending = selectChannelImportPending;
|
||||||
exports.selectChannelIsBlocked = selectChannelIsBlocked;
|
exports.selectChannelIsBlocked = selectChannelIsBlocked;
|
||||||
exports.selectClaimSearchByQuery = selectClaimSearchByQuery;
|
exports.selectClaimSearchByQuery = selectClaimSearchByQuery;
|
||||||
exports.selectClaimSearchByQueryLastPageReached = selectClaimSearchByQueryLastPageReached;
|
exports.selectClaimSearchByQueryLastPageReached = selectClaimSearchByQueryLastPageReached;
|
||||||
|
exports.selectClaimsBalance = selectClaimsBalance;
|
||||||
exports.selectClaimsById = selectClaimsById;
|
exports.selectClaimsById = selectClaimsById;
|
||||||
exports.selectClaimsByUri = selectClaimsByUri;
|
exports.selectClaimsByUri = selectClaimsByUri;
|
||||||
exports.selectCreateChannelError = selectCreateChannelError;
|
exports.selectCreateChannelError = selectCreateChannelError;
|
||||||
|
@ -5170,6 +5160,7 @@ exports.selectPurchaseUriErrorMessage = selectPurchaseUriErrorMessage;
|
||||||
exports.selectPurchasedUris = selectPurchasedUris;
|
exports.selectPurchasedUris = selectPurchasedUris;
|
||||||
exports.selectReceiveAddress = selectReceiveAddress;
|
exports.selectReceiveAddress = selectReceiveAddress;
|
||||||
exports.selectRecentTransactions = selectRecentTransactions;
|
exports.selectRecentTransactions = selectRecentTransactions;
|
||||||
|
exports.selectReservedBalance = selectReservedBalance;
|
||||||
exports.selectResolvingUris = selectResolvingUris;
|
exports.selectResolvingUris = selectResolvingUris;
|
||||||
exports.selectSearchBarFocused = selectSearchBarFocused;
|
exports.selectSearchBarFocused = selectSearchBarFocused;
|
||||||
exports.selectSearchOptions = selectSearchOptions;
|
exports.selectSearchOptions = selectSearchOptions;
|
||||||
|
@ -5177,8 +5168,10 @@ exports.selectSearchState = selectState;
|
||||||
exports.selectSearchSuggestions = selectSearchSuggestions;
|
exports.selectSearchSuggestions = selectSearchSuggestions;
|
||||||
exports.selectSearchUrisByQuery = selectSearchUrisByQuery;
|
exports.selectSearchUrisByQuery = selectSearchUrisByQuery;
|
||||||
exports.selectSearchValue = selectSearchValue;
|
exports.selectSearchValue = selectSearchValue;
|
||||||
|
exports.selectSupportsBalance = selectSupportsBalance;
|
||||||
exports.selectSupportsByOutpoint = selectSupportsByOutpoint;
|
exports.selectSupportsByOutpoint = selectSupportsByOutpoint;
|
||||||
exports.selectTakeOverAmount = selectTakeOverAmount;
|
exports.selectTakeOverAmount = selectTakeOverAmount;
|
||||||
|
exports.selectTipsBalance = selectTipsBalance;
|
||||||
exports.selectToast = selectToast;
|
exports.selectToast = selectToast;
|
||||||
exports.selectTotalBalance = selectTotalBalance;
|
exports.selectTotalBalance = selectTotalBalance;
|
||||||
exports.selectTotalDownloadProgress = selectTotalDownloadProgress;
|
exports.selectTotalDownloadProgress = selectTotalDownloadProgress;
|
||||||
|
|
|
@ -91,8 +91,6 @@ export { savePosition } from 'redux/actions/content';
|
||||||
export {
|
export {
|
||||||
doUpdateBalance,
|
doUpdateBalance,
|
||||||
doBalanceSubscribe,
|
doBalanceSubscribe,
|
||||||
doUpdateTotalBalance,
|
|
||||||
doTotalBalanceSubscribe,
|
|
||||||
doFetchTransactions,
|
doFetchTransactions,
|
||||||
doGetNewAddress,
|
doGetNewAddress,
|
||||||
doCheckAddressIsMine,
|
doCheckAddressIsMine,
|
||||||
|
@ -258,6 +256,10 @@ export {
|
||||||
export {
|
export {
|
||||||
selectBalance,
|
selectBalance,
|
||||||
selectTotalBalance,
|
selectTotalBalance,
|
||||||
|
selectReservedBalance,
|
||||||
|
selectClaimsBalance,
|
||||||
|
selectSupportsBalance,
|
||||||
|
selectTipsBalance,
|
||||||
selectTransactionsById,
|
selectTransactionsById,
|
||||||
selectSupportsByOutpoint,
|
selectSupportsByOutpoint,
|
||||||
selectTotalSupports,
|
selectTotalSupports,
|
||||||
|
|
|
@ -93,7 +93,7 @@ const Lbry: LbryTypes = {
|
||||||
blob_list: (params = {}) => daemonCallWithResult('blob_list', params),
|
blob_list: (params = {}) => daemonCallWithResult('blob_list', params),
|
||||||
|
|
||||||
// Wallet utilities
|
// Wallet utilities
|
||||||
account_balance: () => daemonCallWithResult('account_balance'),
|
account_balance: (params = {}) => daemonCallWithResult('account_balance', params),
|
||||||
account_decrypt: () => daemonCallWithResult('account_decrypt', {}),
|
account_decrypt: () => daemonCallWithResult('account_decrypt', {}),
|
||||||
account_encrypt: (params = {}) => daemonCallWithResult('account_encrypt', params),
|
account_encrypt: (params = {}) => daemonCallWithResult('account_encrypt', params),
|
||||||
account_unlock: (params = {}) => daemonCallWithResult('account_unlock', params),
|
account_unlock: (params = {}) => daemonCallWithResult('account_unlock', params),
|
||||||
|
|
|
@ -8,40 +8,22 @@ import { selectMyClaimsRaw } from 'redux/selectors/claims';
|
||||||
export function doUpdateBalance() {
|
export function doUpdateBalance() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const {
|
const {
|
||||||
wallet: { balance: balanceInStore },
|
wallet: { total: totalInStore },
|
||||||
} = getState();
|
} = getState();
|
||||||
Lbry.account_balance().then(response => {
|
Lbry.account_balance({reserved_subtotals: true}).then((response: BalanceResponse) => {
|
||||||
const { available } = response;
|
const { available, reserved, reserved_subtotals, total } = response;
|
||||||
const balance = parseFloat(available);
|
const { claims, supports, tips } = reserved_subtotals;
|
||||||
if (balanceInStore !== balance) {
|
const totalFloat = parseFloat(total);
|
||||||
|
if (totalInStore !== totalFloat) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.UPDATE_BALANCE,
|
type: ACTIONS.UPDATE_BALANCE,
|
||||||
data: {
|
data: {
|
||||||
balance,
|
totalBalance: totalFloat,
|
||||||
},
|
balance: parseFloat(available),
|
||||||
});
|
reservedBalance: parseFloat(reserved),
|
||||||
}
|
claimsBalance: parseFloat(claims),
|
||||||
});
|
supportsBalance: parseFloat(supports),
|
||||||
};
|
tipsBalance: parseFloat(tips),
|
||||||
}
|
|
||||||
|
|
||||||
export function doUpdateTotalBalance() {
|
|
||||||
return (dispatch, getState) => {
|
|
||||||
const {
|
|
||||||
wallet: { totalBalance: totalBalanceInStore },
|
|
||||||
} = getState();
|
|
||||||
Lbry.account_list().then(accountList => {
|
|
||||||
const { lbc_mainnet: accounts } = accountList;
|
|
||||||
const totalSatoshis =
|
|
||||||
accounts.length === 1
|
|
||||||
? accounts[0].satoshis
|
|
||||||
: accounts.reduce((a, b) => a.satoshis + b.satoshis);
|
|
||||||
const totalBalance = (Number.isNaN(totalSatoshis) ? 0 : totalSatoshis) / 10 ** 8;
|
|
||||||
if (totalBalanceInStore !== totalBalance) {
|
|
||||||
dispatch({
|
|
||||||
type: ACTIONS.UPDATE_TOTAL_BALANCE,
|
|
||||||
data: {
|
|
||||||
totalBalance,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -56,13 +38,6 @@ export function doBalanceSubscribe() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doTotalBalanceSubscribe() {
|
|
||||||
return dispatch => {
|
|
||||||
dispatch(doUpdateTotalBalance());
|
|
||||||
setInterval(() => dispatch(doUpdateTotalBalance()), 5000);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function doFetchTransactions() {
|
export function doFetchTransactions() {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(doFetchSupports());
|
dispatch(doFetchSupports());
|
||||||
|
|
|
@ -16,6 +16,11 @@ type ActionResult = {
|
||||||
|
|
||||||
type WalletState = {
|
type WalletState = {
|
||||||
balance: any,
|
balance: any,
|
||||||
|
totalBalance: any,
|
||||||
|
reservedBalance: any,
|
||||||
|
claimsBalance: any,
|
||||||
|
supportsBalance: any,
|
||||||
|
tipsBalance: any,
|
||||||
latestBlock: ?number,
|
latestBlock: ?number,
|
||||||
transactions: { [string]: Transaction },
|
transactions: { [string]: Transaction },
|
||||||
supports: { [string]: Support },
|
supports: { [string]: Support },
|
||||||
|
@ -42,6 +47,10 @@ type WalletState = {
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
balance: undefined,
|
balance: undefined,
|
||||||
totalBalance: undefined,
|
totalBalance: undefined,
|
||||||
|
reservedBalance: undefined,
|
||||||
|
claimsBalance: undefined,
|
||||||
|
supportsBalance: undefined,
|
||||||
|
tipsBalance: undefined,
|
||||||
latestBlock: undefined,
|
latestBlock: undefined,
|
||||||
transactions: {},
|
transactions: {},
|
||||||
fetchingTransactions: false,
|
fetchingTransactions: false,
|
||||||
|
@ -145,13 +154,13 @@ export const walletReducer = handleActions(
|
||||||
},
|
},
|
||||||
|
|
||||||
[ACTIONS.UPDATE_BALANCE]: (state: WalletState, action) => ({
|
[ACTIONS.UPDATE_BALANCE]: (state: WalletState, action) => ({
|
||||||
...state,
|
|
||||||
balance: action.data.balance,
|
|
||||||
}),
|
|
||||||
|
|
||||||
[ACTIONS.UPDATE_TOTAL_BALANCE]: (state: WalletState, action) => ({
|
|
||||||
...state,
|
...state,
|
||||||
totalBalance: action.data.totalBalance,
|
totalBalance: action.data.totalBalance,
|
||||||
|
balance: action.data.balance,
|
||||||
|
reservedBalance: action.data.reservedBalance,
|
||||||
|
claimsBalance: action.data.claimsBalance,
|
||||||
|
supportsBalance: action.data.supportsBalance,
|
||||||
|
tipsBalance: action.data.tipsBalance,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
[ACTIONS.CHECK_ADDRESS_IS_MINE_STARTED]: (state: WalletState) => ({
|
[ACTIONS.CHECK_ADDRESS_IS_MINE_STARTED]: (state: WalletState) => ({
|
||||||
|
|
|
@ -80,6 +80,26 @@ export const selectTotalBalance = createSelector(
|
||||||
state => state.totalBalance
|
state => state.totalBalance
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const selectReservedBalance = createSelector(
|
||||||
|
selectState,
|
||||||
|
state => state.reservedBalance
|
||||||
|
);
|
||||||
|
|
||||||
|
export const selectClaimsBalance = createSelector(
|
||||||
|
selectState,
|
||||||
|
state => state.claimsBalance
|
||||||
|
);
|
||||||
|
|
||||||
|
export const selectSupportsBalance = createSelector(
|
||||||
|
selectState,
|
||||||
|
state => state.supportsBalance
|
||||||
|
);
|
||||||
|
|
||||||
|
export const selectTipsBalance = createSelector(
|
||||||
|
selectState,
|
||||||
|
state => state.tipsBalance
|
||||||
|
);
|
||||||
|
|
||||||
export const selectTransactionsById = createSelector(
|
export const selectTransactionsById = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.transactions || {}
|
state => state.transactions || {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue