mirror of
				https://github.com/taigrr/wtf
				synced 2025-01-18 04:03:14 -08:00 
			
		
		
		
	better variable names
This commit is contained in:
		
							parent
							
								
									0ffeab9c8d
								
							
						
					
					
						commit
						16c6dffeba
					
				| @ -1,18 +1,18 @@ | |||||||
| package bittrex | package bittrex | ||||||
| 
 | 
 | ||||||
| type summaryList struct { | type summaryList struct { | ||||||
| 	items []*fCurrency | 	items []*bCurrency | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // fCurrency From Currency | // Base Currency | ||||||
| type fCurrency struct { | type bCurrency struct { | ||||||
| 	name        string | 	name        string | ||||||
| 	displayName string | 	displayName string | ||||||
| 	to          []*tCurrency | 	markets     []*mCurrency | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // tCurrency To Currency | // Market Currency | ||||||
| type tCurrency struct { | type mCurrency struct { | ||||||
| 	name string | 	name string | ||||||
| 	summaryInfo | 	summaryInfo | ||||||
| } | } | ||||||
| @ -40,10 +40,10 @@ type summaryResponse struct { | |||||||
| 	} `json:"result"` | 	} `json:"result"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (list *summaryList) addSummaryItem(name, displayName string, toList []*tCurrency) { | func (list *summaryList) addSummaryItem(name, displayName string, marketList []*mCurrency) { | ||||||
| 	list.items = append(list.items, &fCurrency{ | 	list.items = append(list.items, &bCurrency{ | ||||||
| 		name:        name, | 		name:        name, | ||||||
| 		displayName: displayName, | 		displayName: displayName, | ||||||
| 		to:          toList, | 		markets:     marketList, | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
|  | |||||||
| @ -21,12 +21,12 @@ func (widget *Widget) display() { | |||||||
| func summaryText(list *summaryList, colors *TextColors) string { | func summaryText(list *summaryList, colors *TextColors) string { | ||||||
| 	str := "" | 	str := "" | ||||||
| 
 | 
 | ||||||
| 	for _, fromCurrency := range list.items { | 	for _, baseCurrency := range list.items { | ||||||
| 		str += fmt.Sprintf("[%s]%s[%s](%s):\n", colors.base.displayName, fromCurrency.displayName, colors.base.name, fromCurrency.name) | 		str += fmt.Sprintf("[%s]%s[%s](%s):\n", colors.base.displayName, baseCurrency.displayName, colors.base.name, baseCurrency.name) | ||||||
| 
 | 
 | ||||||
| 		resultTemplate := template.New("bittrex") | 		resultTemplate := template.New("bittrex") | ||||||
| 
 | 
 | ||||||
| 		for _, toCurrency := range fromCurrency.to { | 		for _, marketCurrency := range baseCurrency.markets { | ||||||
| 			writer := new(bytes.Buffer) | 			writer := new(bytes.Buffer) | ||||||
| 			strTemplate, _ := resultTemplate.Parse( | 			strTemplate, _ := resultTemplate.Parse( | ||||||
| 				"\t[{{.nameColor}}]{{.mName}}\n" + | 				"\t[{{.nameColor}}]{{.mName}}\n" + | ||||||
| @ -42,13 +42,13 @@ func summaryText(list *summaryList, colors *TextColors) string { | |||||||
| 				"nameColor":      colors.market.name, | 				"nameColor":      colors.market.name, | ||||||
| 				"fieldColor":     colors.market.field, | 				"fieldColor":     colors.market.field, | ||||||
| 				"valueColor":     colors.market.value, | 				"valueColor":     colors.market.value, | ||||||
| 				"mName":          toCurrency.name, | 				"mName":          marketCurrency.name, | ||||||
| 				"High":           toCurrency.High, | 				"High":           marketCurrency.High, | ||||||
| 				"Low":            toCurrency.Low, | 				"Low":            marketCurrency.Low, | ||||||
| 				"Last":           toCurrency.Last, | 				"Last":           marketCurrency.Last, | ||||||
| 				"Volume":         toCurrency.Volume, | 				"Volume":         marketCurrency.Volume, | ||||||
| 				"OpenSellOrders": toCurrency.OpenSellOrders, | 				"OpenSellOrders": marketCurrency.OpenSellOrders, | ||||||
| 				"OpenBuyOrders":  toCurrency.OpenBuyOrders, | 				"OpenBuyOrders":  marketCurrency.OpenBuyOrders, | ||||||
| 			}) | 			}) | ||||||
| 
 | 
 | ||||||
| 			str += writer.String() | 			str += writer.String() | ||||||
|  | |||||||
| @ -68,26 +68,26 @@ func (widget *Widget) config() { | |||||||
| 
 | 
 | ||||||
| func (widget *Widget) setSummaryList() { | func (widget *Widget) setSummaryList() { | ||||||
| 	sCurrencies, _ := Config.Map("wtf.mods.bittrex.summary") | 	sCurrencies, _ := Config.Map("wtf.mods.bittrex.summary") | ||||||
| 	for fromCurrencyName := range sCurrencies { | 	for baseCurrencyName := range sCurrencies { | ||||||
| 		displayName, _ := Config.String("wtf.mods.bittrex.summary." + fromCurrencyName + ".displayName") | 		displayName, _ := Config.String("wtf.mods.bittrex.summary." + baseCurrencyName + ".displayName") | ||||||
| 		toCurrencyList := makeSummaryToList(fromCurrencyName) | 		mCurrencyList := makeSummaryMarketList(baseCurrencyName) | ||||||
| 		widget.summaryList.addSummaryItem(fromCurrencyName, displayName, toCurrencyList) | 		widget.summaryList.addSummaryItem(baseCurrencyName, displayName, mCurrencyList) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func makeSummaryToList(currencyName string) []*tCurrency { | func makeSummaryMarketList(currencyName string) []*mCurrency { | ||||||
| 	tCurrencyList := []*tCurrency{} | 	mCurrencyList := []*mCurrency{} | ||||||
| 
 | 
 | ||||||
| 	configToList, _ := Config.List("wtf.mods.bittrex.summary." + currencyName + ".market") | 	configMarketList, _ := Config.List("wtf.mods.bittrex.summary." + currencyName + ".market") | ||||||
| 	for _, toCurrencyName := range configToList { | 	for _, mCurrencyName := range configMarketList { | ||||||
| 		tCurrencyList = append(tCurrencyList, makeToCurrency(toCurrencyName.(string))) | 		mCurrencyList = append(mCurrencyList, makeMarketCurrency(mCurrencyName.(string))) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	return tCurrencyList | 	return mCurrencyList | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func makeToCurrency(name string) *tCurrency { | func makeMarketCurrency(name string) *mCurrency { | ||||||
| 	return &tCurrency{ | 	return &mCurrency{ | ||||||
| 		name: name, | 		name: name, | ||||||
| 		summaryInfo: summaryInfo{ | 		summaryInfo: summaryInfo{ | ||||||
| 			High:           "-1", | 			High:           "-1", | ||||||
| @ -136,9 +136,9 @@ func (widget *Widget) updateSummary() { | |||||||
| 		Timeout: time.Duration(5 * time.Second), | 		Timeout: time.Duration(5 * time.Second), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	for _, fromCurrency := range widget.summaryList.items { | 	for _, baseCurrency := range widget.summaryList.items { | ||||||
| 		for _, toCurrency := range fromCurrency.to { | 		for _, mCurrency := range baseCurrency.markets { | ||||||
| 			request := makeRequest(fromCurrency.name, toCurrency.name) | 			request := makeRequest(baseCurrency.name, mCurrency.name) | ||||||
| 			response, err := client.Do(request) | 			response, err := client.Do(request) | ||||||
| 
 | 
 | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| @ -166,26 +166,26 @@ func (widget *Widget) updateSummary() { | |||||||
| 
 | 
 | ||||||
| 			if !jsonResponse.Success { | 			if !jsonResponse.Success { | ||||||
| 				ok = false | 				ok = false | ||||||
| 				errorText = fmt.Sprintf("%s-%s: %s", fromCurrency.name, toCurrency.name, jsonResponse.Message) | 				errorText = fmt.Sprintf("%s-%s: %s", baseCurrency.name, mCurrency.name, jsonResponse.Message) | ||||||
| 				break | 				break | ||||||
| 			} | 			} | ||||||
| 			ok = true | 			ok = true | ||||||
| 			errorText = "" | 			errorText = "" | ||||||
| 
 | 
 | ||||||
| 			toCurrency.Last = fmt.Sprintf("%f", jsonResponse.Result[0].Last) | 			mCurrency.Last = fmt.Sprintf("%f", jsonResponse.Result[0].Last) | ||||||
| 			toCurrency.High = fmt.Sprintf("%f", jsonResponse.Result[0].High) | 			mCurrency.High = fmt.Sprintf("%f", jsonResponse.Result[0].High) | ||||||
| 			toCurrency.Low = fmt.Sprintf("%f", jsonResponse.Result[0].Low) | 			mCurrency.Low = fmt.Sprintf("%f", jsonResponse.Result[0].Low) | ||||||
| 			toCurrency.Volume = fmt.Sprintf("%f", jsonResponse.Result[0].Volume) | 			mCurrency.Volume = fmt.Sprintf("%f", jsonResponse.Result[0].Volume) | ||||||
| 			toCurrency.OpenBuyOrders = fmt.Sprintf("%d", jsonResponse.Result[0].OpenBuyOrders) | 			mCurrency.OpenBuyOrders = fmt.Sprintf("%d", jsonResponse.Result[0].OpenBuyOrders) | ||||||
| 			toCurrency.OpenSellOrders = fmt.Sprintf("%d", jsonResponse.Result[0].OpenSellOrders) | 			mCurrency.OpenSellOrders = fmt.Sprintf("%d", jsonResponse.Result[0].OpenSellOrders) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	widget.display() | 	widget.display() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func makeRequest(fName, tName string) *http.Request { | func makeRequest(baseName, marketName string) *http.Request { | ||||||
| 	url := fmt.Sprintf("%s?market=%s-%s", baseURL, fName, tName) | 	url := fmt.Sprintf("%s?market=%s-%s", baseURL, baseName, marketName) | ||||||
| 	request, _ := http.NewRequest("GET", url, nil) | 	request, _ := http.NewRequest("GET", url, nil) | ||||||
| 
 | 
 | ||||||
| 	return request | 	return request | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user