Skip to content

Commit 30f7693

Browse files
authored
cc_wallet Ui fix - Merge pull request #199 from Chia-Network/ui_fix
Ui fix
2 parents f2e7263 + 4feeb0c commit 30f7693

File tree

7 files changed

+79
-32
lines changed

7 files changed

+79
-32
lines changed

electron-ui/trade_renderer.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function set_callbacks(socket) {
147147

148148
if (command == "start_server") {
149149
get_wallet_summaries()
150-
get_wallets();
150+
//get_wallets();
151151
get_height_info();
152152
get_sync_status();
153153
get_connection_info();
@@ -316,21 +316,21 @@ function handle_state_changed(data) {
316316
state = data["state"]
317317
console.log("State changed", state)
318318
if(global_syncing) {
319-
get_wallets()
319+
get_wallet_summaries()
320320
get_sync_status()
321321
get_height_info()
322322
return;
323323
}
324324

325325
if (state == "coin_removed") {
326326
} else if (state == "coin_added") {
327-
get_wallets()
327+
get_wallet_summaries()
328328
} else if (state == "pending_transaction") {
329-
get_wallets()
329+
get_wallet_summaries()
330330
} else if (state == "tx_sent") {
331-
get_wallets()
331+
get_wallet_summaries()
332332
} else if (state == "balance_changed") {
333-
get_wallets()
333+
get_wallet_summaries()
334334
} else if (state == "sync_changed") {
335335
get_sync_status()
336336
} else if (state == "new_block") {
@@ -697,6 +697,35 @@ function get_wallet_summaries_response(data){
697697
select_option = create_select_options(wallets_details)
698698
select_menu.innerHTML = select_option
699699
set_drop_down()
700+
var new_innerHTML = ""
701+
for (var i in data) {
702+
var wallet = data[i];
703+
var type = wallet["type"]
704+
var id = i
705+
var name = wallet["type"]
706+
707+
get_wallet_balance(id)
708+
//href, wallet_name, wallet_description, wallet_amount
709+
var href = ""
710+
if (type == "STANDARD_WALLET") {
711+
href = "./wallet-dark.html"
712+
name = "Chia Wallet"
713+
type = "Chia"
714+
} else if (type == "RATE_LIMITED") {
715+
href = "rl_wallet/rl_wallet.html"
716+
} else if (type == "COLOURED_COIN") {
717+
href = "cc_wallet/cc_wallet.html"
718+
name = "CC Wallet"
719+
type = wallet["name"]
720+
if (type.length > 18) {
721+
type = type.substring(0,18);
722+
type = type.concat("...")
723+
}
724+
}
725+
new_innerHTML += create_side_wallet(id, href, name, type, 0, false)
726+
}
727+
new_innerHTML += create_wallet_button()
728+
wallets_tab.innerHTML = new_innerHTML
700729
}
701730

702731

src/wallet/cc_wallet/cc_wallet.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ async def get_confirmed_balance(self) -> uint64:
200200

201201
async def get_unconfirmed_balance(self) -> uint64:
202202
confirmed = await self.get_confirmed_balance()
203-
unconfirmed_tx: List[TransactionRecord] = await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
203+
unconfirmed_tx: List[
204+
TransactionRecord
205+
] = await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
204206
self.wallet_info.id
205207
)
206208
addition_amount = 0
@@ -734,9 +736,7 @@ async def cc_spend(
734736
wallet_id=self.wallet_info.id,
735737
sent_to=[],
736738
)
737-
await self.wallet_state_manager.add_pending_transaction(
738-
tx_record
739-
)
739+
await self.wallet_state_manager.add_pending_transaction(tx_record)
740740

741741
return spend_bundle
742742

@@ -783,7 +783,9 @@ async def generate_new_coloured_coin(self, amount: uint64) -> Optional[SpendBund
783783
cc_puzzle = cc_wallet_puzzles.cc_make_puzzle(cc_inner, cc_core)
784784
cc_puzzle_hash = cc_puzzle.get_tree_hash()
785785

786-
tx_record: Optional[TransactionRecord] = await self.standard_wallet.generate_signed_transaction(
786+
tx_record: Optional[
787+
TransactionRecord
788+
] = await self.standard_wallet.generate_signed_transaction(
787789
amount, cc_puzzle_hash, uint64(0), origin_id, coins
788790
)
789791
self.log.warning(f"cc_puzzle_hash is {cc_puzzle_hash}")

src/wallet/trade_manager.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def create(
4545

4646
async def create_offer_for_ids(
4747
self, offer: Dict[int, int]
48-
) -> Tuple[bool, Optional[SpendBundle]]:
48+
) -> Tuple[bool, Optional[SpendBundle], Optional[str]]:
4949
"""
5050
Offer is dictionary of wallet ids and amount
5151
"""
@@ -57,7 +57,9 @@ async def create_offer_for_ids(
5757
wallet = self.wallet_state_manager.wallets[wallet_id]
5858
if isinstance(wallet, CCWallet):
5959
balance = await wallet.get_confirmed_balance()
60-
if balance == 0:
60+
if balance < abs(amount) and amount < 0:
61+
raise Exception(f"insufficient funds in wallet {wallet_id}")
62+
if balance == 0 and amount > 0:
6163
if spend_bundle is None:
6264
to_exclude: List[Coin] = []
6365
else:
@@ -67,7 +69,7 @@ async def create_offer_for_ids(
6769
] = await wallet.generate_zero_val_coin(False, to_exclude)
6870

6971
if zero_spend_bundle is None:
70-
raise ValueError(
72+
raise Exception(
7173
"Failed to generate offer. Zero value coin not created."
7274
)
7375
if spend_bundle is None:
@@ -100,22 +102,23 @@ async def create_offer_for_ids(
100102
amount, to_exclude
101103
)
102104
else:
103-
return False, None
105+
return False, None, "unssuported wallet type"
104106
if new_spend_bundle.removals() == [] or new_spend_bundle is None:
105-
return False, None
107+
raise Exception(f"Wallet {id} was unable to create offer.")
106108
if spend_bundle is None:
107109
spend_bundle = new_spend_bundle
108110
else:
109111
spend_bundle = SpendBundle.aggregate(
110112
[spend_bundle, new_spend_bundle]
111113
)
112114

113-
return True, spend_bundle
114-
except Exception:
115-
return False, None
115+
return True, spend_bundle, None
116+
except Exception as e:
117+
return False, None, str(e)
116118

117119
def write_offer_to_disk(self, file_path: Path, offer: SpendBundle):
118-
file_path.write_text(bytes(offer).hex())
120+
if offer is not None:
121+
file_path.write_text(bytes(offer).hex())
119122

120123
async def get_discrepancies_for_offer(
121124
self, file_path: Path
@@ -228,7 +231,8 @@ async def respond_to_offer(self, file_path: Path) -> Tuple[bool, Optional[str]]:
228231
colour
229232
)
230233
unspent = await self.wallet_state_manager.get_spendable_coins_for_wallet(
231-
wallets[colour].wallet_info.id)
234+
wallets[colour].wallet_info.id
235+
)
232236
if coinsol.coin in [record.coin for record in unspent]:
233237
return False, "can't respond to own offer"
234238
innerpuzzlereveal = solution.rest().rest().rest().first()
@@ -270,7 +274,9 @@ async def respond_to_offer(self, file_path: Path) -> Tuple[bool, Optional[str]]:
270274
coinsols.append(coinsol)
271275
else:
272276
# standard chia coin
273-
unspent = await self.wallet_state_manager.get_spendable_coins_for_wallet(1)
277+
unspent = await self.wallet_state_manager.get_spendable_coins_for_wallet(
278+
1
279+
)
274280
if coinsol.coin in [record.coin for record in unspent]:
275281
return False, "can't respond to own offer"
276282
if chia_discrepancy is None:

src/wallet/transaction_record.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ class TransactionRecord(Streamable):
3636
def name(self) -> bytes32:
3737
if self.spend_bundle:
3838
return self.spend_bundle.name()
39-
return std_hash(bytes(self.to_puzzle_hash) + bytes(self.created_at_time) + bytes(self.amount))
39+
return std_hash(
40+
bytes(self.to_puzzle_hash)
41+
+ bytes(self.created_at_time)
42+
+ bytes(self.amount)
43+
)

src/wallet/wallet_state_manager.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,9 @@ async def get_unconfirmed_balance(self, wallet_id) -> uint64:
403403
transactions.
404404
"""
405405
confirmed = await self.get_confirmed_balance_for_wallet(wallet_id)
406-
unconfirmed_tx: List[TransactionRecord] = await self.tx_store.get_unconfirmed_for_wallet(wallet_id)
406+
unconfirmed_tx: List[
407+
TransactionRecord
408+
] = await self.tx_store.get_unconfirmed_for_wallet(wallet_id)
407409
removal_amount = 0
408410

409411
for record in unconfirmed_tx:
@@ -453,9 +455,9 @@ async def coin_removed(self, coin: Coin, index: uint32):
453455

454456
await self.wallet_store.set_spent(coin.name(), index)
455457

456-
unconfirmed_record: List[TransactionRecord] = await self.tx_store.unconfirmed_with_removal_coin(
457-
coin.name()
458-
)
458+
unconfirmed_record: List[
459+
TransactionRecord
460+
] = await self.tx_store.unconfirmed_with_removal_coin(coin.name())
459461
for unconfirmed in unconfirmed_record:
460462
await self.tx_store.set_confirmed(unconfirmed.name(), index)
461463

src/wallet/websocket_server.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,15 @@ async def get_discrepancies_for_offer(self, websocket, request, response_api):
455455
async def create_offer_for_ids(self, websocket, request, response_api):
456456
offer = request["ids"]
457457
file_name = request["filename"]
458-
success, spend_bundle = await self.trade_manager.create_offer_for_ids(offer)
458+
success, spend_bundle, error = await self.trade_manager.create_offer_for_ids(
459+
offer
460+
)
459461
if success:
460462
self.trade_manager.write_offer_to_disk(Path(file_name), spend_bundle)
463+
response = {"success": success}
464+
else:
465+
response = {"success": success, "reason": error}
461466

462-
response = {"success": success}
463467
return await websocket.send(format_response(response_api, response))
464468

465469
async def respond_to_offer(self, websocket, request, response_api):

tests/cc_wallet/test_cc_wallet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ async def test_cc_trade(self, two_wallet_nodes):
320320

321321
offer_dict = {1: 10, 2: -30}
322322

323-
success, spend_bundle = await trade_manager_1.create_offer_for_ids(offer_dict)
323+
success, spend_bundle, error = await trade_manager_1.create_offer_for_ids(offer_dict)
324324

325325
assert success is True
326326
assert spend_bundle is not None
@@ -504,7 +504,7 @@ async def test_cc_trade_with_multiple_colours(self, two_wallet_nodes):
504504

505505
offer_dict = {1: -1000, 2: -30, 3: 50}
506506

507-
success, spend_bundle = await trade_manager_1.create_offer_for_ids(offer_dict)
507+
success, spend_bundle, error = await trade_manager_1.create_offer_for_ids(offer_dict)
508508

509509
assert success is True
510510
assert spend_bundle is not None
@@ -600,7 +600,7 @@ async def test_create_offer_with_zero_val(self, two_wallet_nodes):
600600

601601
offer_dict = {1: -10, 2: 30}
602602

603-
success, spend_bundle = await trade_manager_2.create_offer_for_ids(offer_dict)
603+
success, spend_bundle, error = await trade_manager_2.create_offer_for_ids(offer_dict)
604604

605605
assert success is True
606606
assert spend_bundle is not None

0 commit comments

Comments
 (0)