Skip to content

Commit

Permalink
client: handle sellstring
Browse files Browse the repository at this point in the history
Improve sellstring(ord :Order) in orderutil.js and handles buy || Sell && Buying || Selling
string for core notifications.
  • Loading branch information
ukane-philemon committed Sep 8, 2022
1 parent eecebf5 commit ccd4de0
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 65 deletions.
9 changes: 6 additions & 3 deletions client/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5075,9 +5075,12 @@ func (c *Core) prepareTrackedTrade(dc *dexConnection, form *TradeForm, crypter e
rateString = wallets.trimmedConventionalRateString(corder.Rate)
}
ui := wallets.baseWallet.Info().UnitInfo
subject, details := c.formatDetails(TopicOrderPlaced,
sellString(corder.Sell), ui.ConventionalString(corder.Qty), ui.Conventional.Unit, rateString, tracker.token())
c.notify(newOrderNote(TopicOrderPlaced, subject, details, db.Poke, corder))
topic := TopicBuyOrderPlaced
if corder.Sell {
topic = TopicSellOrderPlaced
}
subject, details := c.formatDetails(topic, ui.ConventionalString(corder.Qty), ui.Conventional.Unit, rateString, tracker.token())
c.notify(newOrderNote(topic, subject, details, db.Poke, corder))
}

updated := assetMap{fromWallet.AssetID: struct{}{}}
Expand Down
133 changes: 96 additions & 37 deletions client/core/locale_ntfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var enUS = map[Topic]*translation{
// [asset name, error message]
TopicWalletCommsWarning: {
subject: "Wallet connection issue",
template: "Unable to communicate with %v wallet! Reason: %q",
template: "Unable to communicate with %v wallet! Reason: %v",
},
// [asset name]
TopicWalletPeersWarning: {
Expand Down Expand Up @@ -89,10 +89,15 @@ var enUS = map[Topic]*translation{
subject: "Market order placed",
template: "selling %s %s at market rate (%s)",
},
// [sell string, qty, ticker, rate string, token]
TopicOrderPlaced: {
// [qty, ticker, rate string, token]
TopicBuyOrderPlaced: {
subject: "Order placed",
template: "%sing %s %s, rate = %s (%s)",
template: "Buying %s %s, rate = %s (%s)",
},
// [qty, ticker, rate string, token]
TopicSellOrderPlaced: {
subject: "Order placed",
template: "Selling %s %s, rate = %s (%s)",
},
// [missing count, token, host]
TopicMissingMatches: {
Expand Down Expand Up @@ -134,15 +139,24 @@ var enUS = map[Topic]*translation{
subject: "Missed cancel",
template: "Cancel order did not match for order %s. This can happen if the cancel order is submitted in the same epoch as the trade or if the target order is fully executed before matching with the cancel order.",
},
// [capitalized sell string, base ticker, quote ticker, host, token]
TopicOrderCanceled: {
// [base ticker, quote ticker, host, token]
TopicBuyOrderCanceled: {
subject: "Order canceled",
template: "Buy order on %s-%s at %s has been canceled (%s)",
},
TopicSellOrderCanceled: {
subject: "Order canceled",
template: "%s order on %s-%s at %s has been canceled (%s)",
template: "Sell order on %s-%s at %s has been canceled (%s)",
},
// [base ticker, quote ticker, fill percent, token]
TopicBuyMatchesMade: {
subject: "Matches made",
template: "Buy order on %s-%s %.1f%% filled (%s)",
},
// [capitalized sell string, base ticker, quote ticker, fill percent, token]
TopicMatchesMade: {
// [base ticker, quote ticker, fill percent, token]
TopicSellMatchesMade: {
subject: "Matches made",
template: "%s order on %s-%s %.1f%% filled (%s)",
template: "Sell order on %s-%s %.1f%% filled (%s)",
},
// [qty, ticker, token]
TopicSwapSendError: {
Expand Down Expand Up @@ -392,10 +406,15 @@ var ptBR = map[Topic]*translation{
template: "vendendo %s %s a taxa de mercado (%s)",
subject: "Ordem de Mercado Colocada",
},
// [sell string, qty, ticker, rate string, token]
TopicOrderPlaced: {
// [qty, ticker, rate string, token], RETRANSLATE.
TopicBuyOrderPlaced: {
subject: "Ordem Colocada",
template: "%sing %s %s, valor = %s (%s)",
template: "Buying %s %s, valor = %s (%s)",
},
// [qty, ticker, rate string, token], RETRANSLATE.
TopicSellOrderPlaced: {
subject: "Ordem Colocada",
template: "Selling %s %s, valor = %s (%s)",
},
// [missing count, token, host]
TopicMissingMatches: {
Expand Down Expand Up @@ -437,14 +456,24 @@ var ptBR = map[Topic]*translation{
template: "Pedido de cancelamento não combinou para pedido %s. Isto pode acontecer se o pedido de cancelamento foi enviado no mesmo epoque do que a troca ou se o pedido foi completamente executado antes da ordem de cancelamento ser executada.",
subject: "Cancelamento Perdido",
},
// [capitalized sell string, base ticker, quote ticker, host, token]
TopicOrderCanceled: {
template: "%s pedido sobre %s-%s em %s foi cancelado (%s)",
// [base ticker, quote ticker, host, token], RETRANSLATE.
TopicSellOrderCanceled: {
template: "Sell pedido sobre %s-%s em %s foi cancelado (%s)",
subject: "Cancelamento de Pedido",
},
// [base ticker, quote ticker, host, token], RETRANSLATE.
TopicBuyOrderCanceled: {
template: "Buy pedido sobre %s-%s em %s foi cancelado (%s)",
subject: "Cancelamento de Pedido",
},
// [capitalized sell string, base ticker, quote ticker, fill percent, token]
TopicMatchesMade: {
template: "%s pedido sobre %s-%s %.1f%% preenchido (%s)",
// [base ticker, quote ticker, fill percent, token], RETRANSLATE.
TopicSellMatchesMade: {
template: "Sell pedido sobre %s-%s %.1f%% preenchido (%s)",
subject: "Combinações Feitas",
},
// [base ticker, quote ticker, fill percent, token], RETRANSLATE.
TopicBuyMatchesMade: {
template: "Buy pedido sobre %s-%s %.1f%% preenchido (%s)",
subject: "Combinações Feitas",
},
// [qty, ticker, token]
Expand Down Expand Up @@ -679,10 +708,15 @@ var zhCN = map[Topic]*translation{
subject: "下达市价单",
template: "以市场价格 (%[3]s) 出售 %[1]s %[2]s",
},
// [sell string, qty, ticker, rate string, token]
TopicOrderPlaced: {
// [qty, ticker, rate string, token], RETRANSLATE.
TopicBuyOrderPlaced: {
subject: "已下订单",
template: "%sing %s %s,值 = %s (%s)", // figure out the "ing" issue (TODO)
template: "Buying %s %s,值 = %s (%s)",
},
// [qty, ticker, rate string, token], RETRANSLATE.
TopicSellOrderPlaced: {
subject: "已下订单",
template: "Selling %s %s,值 = %s (%s)",
},
// [missing count, token, host]
TopicMissingMatches: {
Expand Down Expand Up @@ -724,15 +758,25 @@ var zhCN = map[Topic]*translation{
subject: "丢失取消",
template: "取消订单与订单 %s 不匹配。如果取消订单与交易所同时发送,或者订单在取消订单执行之前已完全执行,则可能发生这种情况。",
},
// [capitalized sell string, base ticker, quote ticker, host, token]
TopicOrderCanceled: {
// [base ticker, quote ticker, host, token], RETRANSLATE.
TopicBuyOrderCanceled: {
subject: "订单取消",
template: "Buy 的 %s-%s 的 %s 订单已被取消 (%s)", // alt. %s 上 %s-%s 上的 %s 请求已被取消 (%s)
},
// [base ticker, quote ticker, host, token], RETRANSLATE.
TopicSellOrderCanceled: {
subject: "订单取消",
template: "%s 的 %s-%s 的 %s 订单已被取消 (%s)", // alt. %s 上 %s-%s 上的 %s 请求已被取消 (%s)
template: "Sell 的 %s-%s 的 %s 订单已被取消 (%s)", // alt. %s 上 %s-%s 上的 %s 请求已被取消 (%s)
},
// [base ticker, quote ticker, fill percent, token], RETRANSLATE.
TopicBuyMatchesMade: {
subject: "匹配完成",
template: "Buy 订单 %s-%s %.1f%% 已完成 (%s)", // alt. %s 请求超过 %s-%s %.1f%% 已填充(%s)
},
// [capitalized sell string, base ticker, quote ticker, fill percent, token]
TopicMatchesMade: {
// [base ticker, quote ticker, fill percent, token], RETRANSLATE.
TopicSellMatchesMade: {
subject: "匹配完成",
template: "%s 订单 %s-%s %.1f%% 已完成 (%s)", // alt. %s 请求超过 %s-%s %.1f%% 已填充(%s)
template: "Sell 订单 %s-%s %.1f%% 已完成 (%s)", // alt. %s 请求超过 %s-%s %.1f%% 已填充(%s)
},
// [qty, ticker, token]
TopicSwapSendError: {
Expand Down Expand Up @@ -965,10 +1009,15 @@ var plPL = map[Topic]*translation{
subject: "Złożono zlecenie rynkowe",
template: "sprzedaż %s %s po kursie rynkowym (%s)",
},
// [sell string, qty, ticker, rate string, token]
TopicOrderPlaced: {
// [qty, ticker, rate string, token], RETRANSLATE.
TopicBuyOrderPlaced: {
subject: "Złożono zlecenie",
template: "%sing %s %s, kurs = %s (%s)",
template: "Buying %s %s, kurs = %s (%s)",
},
// [qty, ticker, rate string, token], RETRANSLATE.
TopicSellOrderPlaced: {
subject: "Złożono zlecenie",
template: "Selling %s %s, kurs = %s (%s)",
},
// [missing count, token, host]
TopicMissingMatches: {
Expand Down Expand Up @@ -1010,15 +1059,25 @@ var plPL = map[Topic]*translation{
subject: "Spóźniona anulacja",
template: "Zlecenie anulacji nie zostało spasowane dla zlecenia %s. Może to mieć miejsce, gdy zlecenie anulacji wysłane jest w tej samej epoce, co zlecenie handlu, lub gdy zlecenie handlu zostaje w pełni wykonane przed spasowaniem ze zleceniem anulacji.",
},
// [capitalized sell string, base ticker, quote ticker, host, token]
TopicOrderCanceled: {
// [base ticker, quote ticker, host, token], RETRANSLATE.
TopicBuyOrderCanceled: {
subject: "Zlecenie anulowane",
template: "Zlecenie buy dla %s-%s na %s zostało anulowane (%s)",
},
// [base ticker, quote ticker, host, token], RETRANSLATE.
TopicSellOrderCanceled: {
subject: "Zlecenie anulowane",
template: "Zlecenie %s dla %s-%s na %s zostało anulowane (%s)",
template: "Zlecenie sell dla %s-%s na %s zostało anulowane (%s)",
},
// [base ticker, quote ticker, fill percent, token], RETRANSLATE.
TopicSellMatchesMade: {
subject: "Dokonano spasowania",
template: "Zlecenie sell na %s-%s zrealizowane w %.1f%% (%s)",
},
// [capitalized sell string, base ticker, quote ticker, fill percent, token]
TopicMatchesMade: {
// [base ticker, quote ticker, fill percent, token], RETRANSLATE.
TopicBuyMatchesMade: {
subject: "Dokonano spasowania",
template: "Zlecenie %s na %s-%s zrealizowane w %.1f%% (%s)",
template: "Zlecenie buy na %s-%s zrealizowane w %.1f%% (%s)",
},
// [qty, ticker, token]
TopicSwapSendError: {
Expand Down
9 changes: 6 additions & 3 deletions client/core/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ type OrderNote struct {

const (
TopicOrderLoadFailure Topic = "OrderLoadFailure"
TopicOrderPlaced Topic = "OrderPlaced"
TopicBuyOrderPlaced Topic = "BuyOrderPlaced"
TopicSellOrderPlaced Topic = "SellOrderPlaced"
TopicYoloPlaced Topic = "YoloPlaced"
TopicMissingMatches Topic = "MissingMatches"
TopicWalletMissing Topic = "WalletMissing"
Expand All @@ -241,9 +242,11 @@ const (
TopicMissedCancel Topic = "MissedCancel"
TopicOrderBooked Topic = "OrderBooked"
TopicNoMatch Topic = "NoMatch"
TopicOrderCanceled Topic = "OrderCanceled"
TopicBuyOrderCanceled Topic = "BuyOrderCanceled"
TopicSellOrderCanceled Topic = "SellOrderCanceled"
TopicCancel Topic = "Cancel"
TopicMatchesMade Topic = "MatchesMade"
TopicBuyMatchesMade Topic = "BuyMatchesMade"
TopicSellMatchesMade Topic = "SellMatchesMade"
TopicSwapSendError Topic = "SwapSendError"
TopicInitError Topic = "InitError"
TopicReportRedeemError Topic = "ReportRedeemError"
Expand Down
6 changes: 4 additions & 2 deletions client/core/simnet_trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,8 @@ func testOrderStatusReconciliation(s *simulationTest) error {
s.client2.log.Infof("Waiting %v for order %s to be partially matched", maxMatchDuration, tracker.token())
matched := notes.find(ctx, maxMatchDuration, func(n Notification) bool {
orderNote, isOrderNote := n.(*OrderNote)
return isOrderNote && n.Topic() == TopicMatchesMade && orderNote.Order.ID.String() == orderID
isMatchedTopic := n.Topic() == TopicBuyMatchesMade || n.Topic() == TopicSellMatchesMade
return isOrderNote && isMatchedTopic && orderNote.Order.ID.String() == orderID
})
if !matched {
return fmt.Errorf("order %s not matched after %s", tracker.token(), maxMatchDuration)
Expand Down Expand Up @@ -1118,7 +1119,8 @@ func (s *simulationTest) monitorOrderMatchingAndTradeNeg(ctx context.Context, cl
client.log.Infof("Waiting up to %v for matches on order %s", maxMatchDuration, tracker.token())
matched := client.notes.find(ctx, maxMatchDuration, func(n Notification) bool {
orderNote, isOrderNote := n.(*OrderNote)
return isOrderNote && n.Topic() == TopicMatchesMade && orderNote.Order.ID.String() == orderID
isMatchedTopic := n.Topic() == TopicBuyMatchesMade || n.Topic() == TopicSellMatchesMade
return isOrderNote && isMatchedTopic && orderNote.Order.ID.String() == orderID
})
if ctx.Err() != nil { // context canceled
return nil
Expand Down
18 changes: 12 additions & 6 deletions client/core/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,13 @@ func (t *trackedTrade) negotiate(msgMatches []*msgjson.Match) error {
// Send notifications.
corder := t.coreOrderInternal()
if cancelMatch != nil {
subject, details := t.formatDetails(TopicOrderCanceled,
strings.Title(sellString(trade.Sell)), unbip(t.Base()), unbip(t.Quote()), t.dc.acct.host, t.token())
topic := TopicBuyOrderCanceled
if trade.Sell {
topic = TopicSellOrderCanceled
}
subject, details := t.formatDetails(topic, unbip(t.Base()), unbip(t.Quote()), t.dc.acct.host, t.token())

t.notify(newOrderNote(TopicOrderCanceled, subject, details, db.Poke, corder))
t.notify(newOrderNote(topic, subject, details, db.Poke, corder))
// Also send out a data notification with the cancel order information.
t.notify(newOrderNote(TopicCancel, "", "", db.Data, corder))
}
Expand All @@ -854,9 +857,12 @@ func (t *trackedTrade) negotiate(msgMatches []*msgjson.Match) error {
}

// A single order notification.
subject, details := t.formatDetails(TopicMatchesMade,
strings.Title(sellString(trade.Sell)), unbip(t.Base()), unbip(t.Quote()), fillPct, t.token())
t.notify(newOrderNote(TopicMatchesMade, subject, details, db.Poke, corder))
topic := TopicBuyMatchesMade
if trade.Sell {
topic = TopicSellMatchesMade
}
subject, details := t.formatDetails(topic, unbip(t.Base()), unbip(t.Quote()), fillPct, t.token())
t.notify(newOrderNote(topic, subject, details, db.Poke, corder))
}

err := t.db.UpdateOrder(t.metaOrder())
Expand Down
18 changes: 6 additions & 12 deletions client/webserver/site/src/js/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const ID_RECONFIG_SUCCESS = 'RECONFIG_SUCCESS'
export const ID_RESCAN_STARTED = 'RESCAN_STARTED'
export const ID_NEW_WALLET_SUCCESS = 'NEW_WALLET_SUCCESS'
export const ID_WALLET_UNLOCKED = 'WALLET_UNLOCKED'
export const ID_SELLING = 'ID_SELLING'
export const ID_BUYING = 'ID_BUYING'

export const enUS: Locale = {
[ID_NO_PASS_ERROR_MSG]: 'password cannot be empty',
Expand Down Expand Up @@ -111,7 +113,9 @@ export const enUS: Locale = {
[ID_RECONFIG_SUCCESS]: 'Wallet Reconfigured!',
[ID_RESCAN_STARTED]: 'Wallet Rescan Running',
[ID_NEW_WALLET_SUCCESS]: '{{ assetName }} Wallet Created!',
[ID_WALLET_UNLOCKED]: 'Wallet Unlocked'
[ID_WALLET_UNLOCKED]: 'Wallet Unlocked',
[ID_SELLING]: 'Selling',
[ID_BUYING]: 'Buying'
}

export const ptBR: Locale = {
Expand Down Expand Up @@ -198,20 +202,10 @@ export const zhCN: Locale = {
[ID_NEW_WALLET_PASS]: '设置新的钱包密码',
[ID_LOT]: '批处理',
[ID_LOTS]: '批', // alt. 很多
[ID_UNKNOWN]: 'unknown', // TODO
[ID_EPOCH]: '时间',
[ID_SETTLING]: 'settling', // TODO - "settling" shows in the Your Orders table when the order is doing an atomic swap with another trade
[ID_NO_MATCH]: 'no match', // TODO - "no match" shows in the Your Orders table when the order did not match with another trade and is done
[ID_CANCELED]: 'canceled', // TODO - "canceled" shows in the Your Orders table when the order has been canceled
[ID_REVOKED]: 'revoked', // TODO - "revoked" shows in the Your Orders table when the order has failed during swap
[ID_WAITING_FOR_CONFS]: 'Waiting for confirmations...', // TODO - shows when the registration fee transaction is waiting to be mined (needs confirmations)
[ID_NONE_SELECTED]: 'none selected', // TODO - looks unused, but this indicates nothing is selected in some list
[ID_REGISTRATION_FEE_SUCCESS]: 'Registration fee payment successful!', // TODO - When the registration fee transaction reaches the required number of confirmations, this is shown
[ID_API_ERROR]: '接口错误',
[ID_ADD]: '加',
[ID_CREATE]: '创建',
[ID_WALLET_READY]: 'Choose Wallet', // xxx translate
[ID_SETUP_WALLET]: 'Setup' // xxx translate
[ID_CREATE]: '创建'
}

export const plPL: Locale = {
Expand Down
2 changes: 1 addition & 1 deletion client/webserver/site/src/js/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ export default class MarketsPage extends BasePage {
Doc.hide(page.vUnlockPreorder, page.vPreorderErr)
Doc.show(page.vPreorder)

page.vBuySell.textContent = isSell ? 'Selling' : 'Buying'
page.vBuySell.textContent = isSell ? intl.prep(intl.ID_SELLING) : intl.prep(intl.ID_BUYING)
const buySellStr = isSell ? intl.prep(intl.ID_SELL) : intl.prep(intl.ID_BUY)
page.vSideSubmit.textContent = buySellStr
page.vOrderHost.textContent = order.host
Expand Down
7 changes: 6 additions & 1 deletion client/webserver/site/src/js/orderutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export const Taker = 1
*/
export const RateEncodingFactor = 1e8

export function sellString (ord: Order) { return ord.sell ? 'sell' : 'buy' }
export function sellString (ord: Order) {
const key = ord.sell ? intl.ID_SELL : intl.ID_BUY
const lang = document.documentElement.lang.toLowerCase()
return intl.prep(key).toLocaleLowerCase(lang)
}

export function typeString (ord: Order) { return ord.type === Limit ? (ord.tif === ImmediateTiF ? 'limit (i)' : 'limit') : 'market' }

/* isMarketBuy will return true if the order is a market buy order. */
Expand Down

0 comments on commit ccd4de0

Please sign in to comment.