Skip to content

Commit

Permalink
Fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dkmyta committed Jul 29, 2024
1 parent 70433e2 commit df958f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 2 additions & 3 deletions projects/packages/waf/src/class-waf-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public static function should_use_global_stats_cache() {
* Get the global stats from the API endpoint
*/
public static function fetch_global_stats_from_api() {
// todo: merge and deploy add/wpcom-endpoint-for-wpscan-statistics first!
$url = esc_url_raw( 'https://public-api.wordpress.com/wpcom/v2/jetpack-protect-global-stats' );
$response = wp_remote_get( $url );

Expand Down Expand Up @@ -151,8 +150,8 @@ public static function get_global_stats( $refresh_from_wpcom = false ) {
$global_stats = self::get_global_stats_from_options();
}

// Ensure that $global_stats is not null and is of the correct type
if ( $global_stats === null || ( ! is_array( $global_stats ) && ! ( $global_stats instanceof \WP_Error ) ) ) {
// Ensure that $global_stats is the correct type
if ( ! is_array( $global_stats ) && ! ( $global_stats instanceof \WP_Error ) ) {
return new \WP_Error( 'unexpected_type', 'Unexpected type or null returned for global stats' );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ const FooterInfo = () => {
const { hasRequiredPlan } = useProtectData();
const { stats } = useWafData();
const { globalStats } = stats;
const totalVulnerabilitiesFormatted = parseInt(
globalStats.totalVulnerabilities
).toLocaleString();
const totalVulnerabilities = parseInt( globalStats?.totalVulnerabilities );
const totalVulnerabilitiesFormatted = isNaN( totalVulnerabilities )
? '50,000'
: totalVulnerabilities.toLocaleString();

if ( hasRequiredPlan ) {
const learnMoreScanUrl = getRedirectUrl( 'protect-footer-learn-more-scan' );
Expand Down
6 changes: 5 additions & 1 deletion projects/plugins/protect/src/js/routes/scan/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const ScanPage = () => {
const { lastChecked, currentStatus, errorCode, errorMessage, hasRequiredPlan } = useProtectData();
const { stats } = useWafData();
const { globalStats } = stats;
const totalVulnerabilities = parseInt( globalStats?.totalVulnerabilities );
const totalVulnerabilitiesFormatted = isNaN( totalVulnerabilities )
? '50,000'
: totalVulnerabilities.toLocaleString();
const { hasConnectionError } = useConnectionErrorNotice();
const { refreshStatus } = useDispatch( STORE_ID );
const { statusIsFetching, scanIsUnavailable, status } = useSelect( select => ( {
Expand Down Expand Up @@ -149,7 +153,7 @@ const ScanPage = () => {
'We are scanning for security threats from our more than %s listed vulnerabilities, powered by WPScan. This could take a minute or two.',
'jetpack-protect'
),
parseInt( globalStats.totalVulnerabilities ).toLocaleString()
totalVulnerabilitiesFormatted
) }
</Text>
</Col>
Expand Down

0 comments on commit df958f1

Please sign in to comment.