Added API for getting on ramp data
This commit is contained in:
parent
2ae1931e6c
commit
db962e0135
|
@ -180,6 +180,23 @@ func (api *API) GetFavourites(ctx context.Context) ([]*Favourite, error) {
|
|||
func (api *API) AddFavourite(ctx context.Context, favourite Favourite) error {
|
||||
log.Debug("call to create or update favourites")
|
||||
err := api.s.db.AddFavourite(favourite)
|
||||
log.Debug("result from database for create or update favouritesn", "err", err)
|
||||
log.Debug("result from database for create or update favourites", "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
func (api *API) GetCryptoOnRamps(ctx context.Context) ([]CryptoOnRamp, error) {
|
||||
if api.s.cryptoOnRampManager == nil {
|
||||
// TODO Add settings and then build options based on settings
|
||||
opts := &CryptoOnRampOptions{
|
||||
dataSourceType: DataSourceStatic,
|
||||
}
|
||||
api.s.cryptoOnRampManager = NewCryptoOnRampManager(opts)
|
||||
}
|
||||
|
||||
rs, err := api.s.cryptoOnRampManager.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rs, nil
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,42 @@
|
|||
package wallet
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCryptoOnRamps_Get(t *testing.T) {
|
||||
cs := []*CryptoOnRampManager{
|
||||
{options: &CryptoOnRampOptions{dataSourceType: DataSourceStatic}},
|
||||
{options: &CryptoOnRampOptions{
|
||||
dataSourceType: DataSourceHTTP,
|
||||
dataSource: cryptoOnRampsData,
|
||||
}},
|
||||
}
|
||||
|
||||
for _, corm := range cs {
|
||||
require.Equal(t, 0, len(corm.ramps))
|
||||
|
||||
rs, err := corm.Get()
|
||||
require.NoError(t, err)
|
||||
require.Greater(t, len(rs), 0)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCryptoOnRampManager_hasCacheExpired(t *testing.T) {
|
||||
corm := NewCryptoOnRampManager(&CryptoOnRampOptions{
|
||||
dataSourceType: DataSourceHTTP,
|
||||
dataSource: cryptoOnRampsData,
|
||||
})
|
||||
nt := time.Time{}.Add(30 * time.Minute)
|
||||
|
||||
require.False(t, corm.hasCacheExpired(nt))
|
||||
require.True(t, corm.hasCacheExpired(time.Now()))
|
||||
|
||||
_, err := corm.Get()
|
||||
require.NoError(t, err)
|
||||
require.False(t, corm.hasCacheExpired(time.Now()))
|
||||
require.True(t, corm.hasCacheExpired(time.Now().Add(2*time.Hour)))
|
||||
}
|
|
@ -29,12 +29,13 @@ func NewService(db *Database, accountsFeed *event.Feed) *Service {
|
|||
|
||||
// Service is a wallet service.
|
||||
type Service struct {
|
||||
feed *event.Feed
|
||||
db *Database
|
||||
reactor *Reactor
|
||||
signals *SignalsTransmitter
|
||||
client *ethclient.Client
|
||||
started bool
|
||||
feed *event.Feed
|
||||
db *Database
|
||||
reactor *Reactor
|
||||
signals *SignalsTransmitter
|
||||
client *ethclient.Client
|
||||
cryptoOnRampManager *CryptoOnRampManager
|
||||
started bool
|
||||
|
||||
group *Group
|
||||
accountsFeed *event.Feed
|
||||
|
|
Loading…
Reference in New Issue