From e3422cfa97b6d1075be4f5d08c37802c11a26be6 Mon Sep 17 00:00:00 2001 From: Gareth Kirwan Date: Mon, 12 Aug 2024 07:36:24 +0700 Subject: [PATCH] Currencies: StorePairs auto-update pairs Store Pairs simply does-the-right-thing now. --- currency/manager.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/currency/manager.go b/currency/manager.go index af210a6e1ad..921262acf18 100644 --- a/currency/manager.go +++ b/currency/manager.go @@ -190,8 +190,9 @@ func (p *PairsManager) GetFormat(a asset.Item, request bool) (PairFormat, error) return *pFmt, nil } -// StorePairs stores a list of pairs based on the asset type and whether they're enabled or not -// All enabled pairs must be stored as available already +// StorePairs stores a list of pairs based on the asset type and whether enabled or just available +// All enabled pairs are automatically added to available pairs +// All pairs removed from available are automatically removed from enabled as well func (p *PairsManager) StorePairs(a asset.Item, pairs Pairs, enabled bool) error { if !a.IsValid() { return fmt.Errorf("%s %w", a, asset.ErrNotSupported) @@ -215,17 +216,16 @@ func (p *PairsManager) StorePairs(a asset.Item, pairs Pairs, enabled bool) error } if enabled { - // All new enabled pairs must be in Available already - if err := pairStore.Available.ContainsAll(pairs, true); err != nil { - return fmt.Errorf("%w: %w for asset %s", ErrPairNotAvailable, err, a) - } pairStore.Enabled = slices.Clone(pairs) + pairStore.Available.Add(pairs...) } else { - if err := pairs.ContainsAll(pairStore.Enabled, true); err != nil { - return fmt.Errorf("%w: %w for asset %s", ErrPairNotAvailable, err, a) - } pairStore.Available = slices.Clone(pairs) p.reindex() + diff, err := pairStore.Enabled.FindDifferences(pairs) + if err != nil { + return err + } + pairStore.Enabled.Remove(diff.Remove...) } return nil