forked from mozilla/price-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In the future we can fill in the rest of the vendor duck to support non-allowlisted sites.
- Loading branch information
Michael Kelly
committed
Oct 24, 2018
1 parent
2410ed5
commit c598dd6
Showing
6 changed files
with
82 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/** | ||
* Redux duck for vendors that sell products. | ||
* @module | ||
*/ | ||
|
||
import pt from 'prop-types'; | ||
|
||
// Types | ||
|
||
export const vendorShape = pt.shape({ | ||
name: pt.string.isRequired, | ||
hostnames: pt.arrayOf(pt.string).isRequired, | ||
faviconUrl: pt.string, | ||
}); | ||
|
||
// Eventually we will dynamically extract vendor data, but for now it's | ||
// hard-coded. | ||
const VENDORS = [ | ||
{ | ||
name: 'Amazon', | ||
hostnames: ['amazon.com', 'www.amazon.com', 'smile.amazon.com'], | ||
faviconUrl: 'https://www.amazon.com/favicon.ico', | ||
}, | ||
{ | ||
name: 'Best Buy', | ||
hostnames: ['bestbuy.com', 'www.bestbuy.com'], | ||
faviconUrl: 'https://www.bestbuy.com/favicon.ico', | ||
}, | ||
{ | ||
name: 'eBay', | ||
hostnames: ['ebay.com', 'www.ebay.com'], | ||
faviconUrl: 'https://www.ebay.com/favicon.ico', | ||
}, | ||
{ | ||
name: 'The Home Depot', | ||
hostnames: ['homedepot.com', 'www.homedepot.com'], | ||
faviconUrl: 'https://www.homedepot.com/favicon.ico', | ||
}, | ||
{ | ||
name: 'Walmart', | ||
hostnames: ['walmart.com', 'www.walmart.com'], | ||
faviconUrl: 'https://www.walmart.com/favicon.ico', | ||
}, | ||
{ | ||
name: 'mkelly Test', | ||
hostnames: ['mkelly.me', 'www.mkelly.me'], | ||
faviconUrl: '', | ||
}, | ||
]; | ||
|
||
// Selectors | ||
|
||
export function getVendor(state, url) { | ||
const hostname = new URL(url).hostname; | ||
return VENDORS.find(vendor => vendor.hostnames.includes(hostname)); | ||
} |