| 116 | } |
| 117 | |
| 118 | void Account::update(const graphene::chain::account_balance_object& balance) |
| 119 | { |
| 120 | auto balanceItr = std::find_if(m_balances.begin(), m_balances.end(), |
| 121 | [&balance](Balance* b) { return b->type()->id() == balance.asset_type.instance.value; }); |
| 122 | |
| 123 | if (balanceItr != m_balances.end()) { |
| 124 | ilog("Updating ${a}'s balance: ${b}", ("a", name().toStdString())("b", balance)); |
| 125 | (*balanceItr)->update(balance); |
| 126 | Q_EMIT balancesChanged(); |
| 127 | } else { |
| 128 | ilog("Adding to ${a}'s new balance: ${b}", ("a", name().toStdString())("b", balance)); |
| 129 | Balance* newBalance = new Balance; |
| 130 | newBalance->setParent(this); |
| 131 | auto model = qobject_cast<ChainDataModel*>(parent()); |
| 132 | newBalance->setProperty("type", QVariant::fromValue(model->getAsset(balance.asset_type.instance.value))); |
| 133 | newBalance->setProperty("amount", QVariant::fromValue(balance.balance.value)); |
| 134 | m_balances.append(newBalance); |
| 135 | Q_EMIT balancesChanged(); |
| 136 | } |
| 137 | } |