Skip to content

Commit 9668b41

Browse files
committed
-added reason for failure messages to create offer
-trade manager now shows colour names for side wallets
1 parent 8bbd0d3 commit 9668b41

File tree

3 files changed

+47
-15
lines changed

3 files changed

+47
-15
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/trade_manager.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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,9 +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(
71-
"Failed to generate offer. Zero value coin not created."
72-
)
72+
raise Exception("Failed to generate offer. Zero value coin not created.")
7373
if spend_bundle is None:
7474
spend_bundle = zero_spend_bundle
7575
else:
@@ -102,7 +102,7 @@ async def create_offer_for_ids(
102102
else:
103103
return False, None
104104
if new_spend_bundle.removals() == [] or new_spend_bundle is None:
105-
return False, None
105+
raise Exception(f"Wallet {id} was unable to create offer.")
106106
if spend_bundle is None:
107107
spend_bundle = new_spend_bundle
108108
else:
@@ -111,11 +111,12 @@ async def create_offer_for_ids(
111111
)
112112

113113
return True, spend_bundle
114-
except Exception:
115-
return False, None
114+
except Exception as e:
115+
return False, str(e)
116116

117117
def write_offer_to_disk(self, file_path: Path, offer: SpendBundle):
118-
file_path.write_text(bytes(offer).hex())
118+
if offer is not None:
119+
file_path.write_text(bytes(offer).hex())
119120

120121
async def get_discrepancies_for_offer(
121122
self, file_path: Path

src/wallet/websocket_server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,10 @@ async def create_offer_for_ids(self, websocket, request, response_api):
458458
success, spend_bundle = await self.trade_manager.create_offer_for_ids(offer)
459459
if success:
460460
self.trade_manager.write_offer_to_disk(Path(file_name), spend_bundle)
461+
response = {"success": success}
462+
else:
463+
response = {"success": success, "reason": spend_bundle}
461464

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

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

0 commit comments

Comments
 (0)