Skip to content

Commit

Permalink
Merge pull request #657 from Adamant-im/fix/fast-first-message
Browse files Browse the repository at this point in the history
Fix: fast first message
  • Loading branch information
bludnic authored Jan 11, 2025
2 parents 4312f57 + f7ab58e commit ecac1fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/components/Chat/Chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,11 @@ function validateMessage(message: string): string | false {
return validationErrors.emptyMessage
}
if (store.state.balance < Fees.NOT_ADM_TRANSFER) {
if (store.getters.isAccountNew()) {
const isNewAccount = store.getters.isAccountNew()
const balance = isNewAccount ? store.state.unconfirmedBalance : store.state.balance
if (balance < Fees.NOT_ADM_TRANSFER) {
if (isNewAccount) {
return validationErrors.notEnoughFundsNewAccount
} else {
return validationErrors.notEnoughFunds
Expand Down
22 changes: 19 additions & 3 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ import servicesPlugin from './modules/services/services-plugin'

export let interval

const UPDATE_BALANCE_INTERVAL = 10000
const UPDATE_BALANCE_INTERVAL = 5000
const UPDATE_BALANCE_INTERVAL_FOR_NEW_ACCOUNT = 1500

/**
* @type { import("vuex").StoreOptions } store
Expand All @@ -58,6 +59,7 @@ const store = {
IDBReady: false, // set `true` when state has been saved in IDB
address: '',
balance: 0,
unconfirmedBalance: 0,
balanceStatus: FetchStatus.Loading,
passphrase: '',
password: '',
Expand All @@ -80,6 +82,7 @@ const store = {
*/
return (
state.balance === 0 &&
state.unconfirmedBalance === 0 &&
state.chat.lastMessageHeight === 0 &&
Object.keys(state.adm.transactions).length === 0
)
Expand All @@ -92,6 +95,9 @@ const store = {
setBalance(state, balance) {
state.balance = balance
},
setUnconfirmedBalance(state, balance) {
state.unconfirmedBalance = balance
},
setBalanceStatus(state, status) {
state.balanceStatus = status
},
Expand Down Expand Up @@ -131,6 +137,7 @@ const store = {
return loginOrRegister(passphrase).then((account) => {
commit('setAddress', account.address)
commit('setBalance', account.balance)
commit('setUnconfirmedBalance', account.unconfirmedBalance)
commit('setPassphrase', passphrase)

// retrieve wallet data
Expand Down Expand Up @@ -204,6 +211,7 @@ const store = {
return getCurrentAccount()
.then((account) => {
commit('setBalance', account.balance)
commit('setUnconfirmedBalance', account.unconfirmedBalance)
commit('setBalanceStatus', FetchStatus.Success)
if (account.balance > Fees.KVS) {
flushCryptoAddresses()
Expand All @@ -217,12 +225,20 @@ const store = {

startInterval: {
root: true,
handler({ dispatch }) {
handler({ dispatch, getters }) {
function repeat() {
validateStoredCryptoAddresses()
dispatch('updateBalance')
.catch((err) => console.error(err))
.then(() => (interval = setTimeout(repeat, UPDATE_BALANCE_INTERVAL)))
.then(
() =>
(interval = setTimeout(
repeat,
getters.isAccountNew()
? UPDATE_BALANCE_INTERVAL_FOR_NEW_ACCOUNT
: UPDATE_BALANCE_INTERVAL
))
)
}
repeat()
}
Expand Down

0 comments on commit ecac1fe

Please sign in to comment.