Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Deprecate BUSD
Browse files Browse the repository at this point in the history
  • Loading branch information
0xBuzzLightyear committed Dec 16, 2023
1 parent 4ad28ff commit 6bf4df2
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ Receive crypto including stablecoins with ease. Open new opportunities for your
<img src="./ui-dashboard/src/assets/icons/crypto/usdc.svg" height="64" alt="usdc">
<div>USDC</div>
</td>
<td align="center">
<img src="./ui-dashboard/src/assets/icons/crypto/busd.svg" height="64" alt="busd">
<div>BUSD</div>
</td>
</tr>
</table>

Expand Down
1 change: 1 addition & 0 deletions internal/money/money.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type CryptoCurrency struct {
TokenContractAddress string
TestTokenContractAddress string
Aliases []string
Deprecated bool
}

func (c CryptoCurrency) DisplayName() string {
Expand Down
2 changes: 1 addition & 1 deletion internal/server/http/merchantapi/merchant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestMerchantRoutes(t *testing.T) {
mt, _ := tc.Must.CreateMerchant(t, user.ID)

// And blockchain currencies
allCurrencies := tc.Services.Blockchain.ListSupportedCurrencies()
allCurrencies := tc.Services.Blockchain.ListSupportedCurrencies(false)

// ACT 1
// Get merchant
Expand Down
2 changes: 1 addition & 1 deletion internal/server/http/paymentapi/payment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
func TestHandlers(t *testing.T) {
tc := test.NewIntegrationTest(t)

allCurrencies := tc.Services.Blockchain.ListSupportedCurrencies()
allCurrencies := tc.Services.Blockchain.ListSupportedCurrencies(false)

t.Run("GetSupportedMethods", func(t *testing.T) {
t.Run("Returns list of supported methods", func(t *testing.T) {
Expand Down
26 changes: 24 additions & 2 deletions internal/service/blockchain/currencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

type Resolver interface {
ListSupportedCurrencies() []money.CryptoCurrency
ListSupportedCurrencies(withDeprecated bool) []money.CryptoCurrency
ListBlockchainCurrencies(blockchain money.Blockchain) []money.CryptoCurrency
GetCurrencyByTicker(ticker string) (money.CryptoCurrency, error)
GetNativeCoin(blockchain money.Blockchain) (money.CryptoCurrency, error)
Expand Down Expand Up @@ -138,12 +138,16 @@ func (r *CurrencyResolver) GetCurrencyByBlockchainAndContract(bc money.Blockchai
return money.CryptoCurrency{}, ErrCurrencyNotFound
}

func (r *CurrencyResolver) ListSupportedCurrencies() []money.CryptoCurrency {
func (r *CurrencyResolver) ListSupportedCurrencies(withDeprecated bool) []money.CryptoCurrency {
r.mu.RLock()
defer r.mu.RUnlock()

results := make([]money.CryptoCurrency, 0)
for i := range r.currencies {
if r.currencies[i].Deprecated && !withDeprecated {
continue
}

results = append(results, r.currencies[i])
}

Expand Down Expand Up @@ -181,6 +185,10 @@ func (r *CurrencyResolver) addCurrency(currency money.CryptoCurrency) {

r.ensureIndices(currency.Blockchain, currency.Ticker)

if currency.Deprecated {
return
}

// add currency to "index"
r.blockchainCurrencies[currency.Blockchain][currency.Ticker] = struct{}{}

Expand Down Expand Up @@ -281,6 +289,11 @@ func DefaultSetup(s *CurrencyResolver) error {
return err
}

deprecated, err := parseBool(c["deprecated"])
if err != nil {
return err
}

ticker := c["ticker"]

s.addCurrency(money.CryptoCurrency{
Expand All @@ -295,6 +308,7 @@ func DefaultSetup(s *CurrencyResolver) error {
TestTokenContractAddress: testTokenAddr,
Aliases: aliases,
Decimals: int64(decimals),
Deprecated: deprecated,
})

s.addMinimalWithdrawal(ticker, minimalWithdrawal)
Expand Down Expand Up @@ -372,6 +386,14 @@ func parseUSD(raw string) (money.Money, error) {
return money.FiatFromFloat64(money.USD, f)
}

func parseBool(raw string) (bool, error) {
if raw == "" {
return false, nil
}

return strconv.ParseBool(raw)
}

func parseAliases(raw string) []string {
if raw == "" {
return nil
Expand Down
3 changes: 2 additions & 1 deletion internal/service/blockchain/currencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"networkId": "56",
"testNetworkId": "97",
"minimal_withdrawal_amount_usd": "10",
"minimal_instant_internal_transfer_amount_usd": "30"
"minimal_instant_internal_transfer_amount_usd": "30",
"deprecated": "true"
}
]
4 changes: 2 additions & 2 deletions internal/service/merchant/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ type SupportedCurrency struct {
}

func (s *Service) ListSupportedCurrencies(_ context.Context, merchant *Merchant) ([]SupportedCurrency, error) {
all := s.blockchain.ListSupportedCurrencies()
all := s.blockchain.ListSupportedCurrencies(false)
enabledTickers := util.Set(merchant.Settings().PaymentMethods())

// if merchant didn't set this parameter yet, let's treat that as "all currencies enabled"
Expand Down Expand Up @@ -197,7 +197,7 @@ func (s *Service) UpdateSupportedMethods(ctx context.Context, merchant *Merchant
tickersSet := util.Set(tickers)
availableTickersSet := util.Set(
util.MapSlice(
s.blockchain.ListSupportedCurrencies(),
s.blockchain.ListSupportedCurrencies(false),
func(c money.CryptoCurrency) string { return c.Ticker },
),
)
Expand Down

0 comments on commit 6bf4df2

Please sign in to comment.