Skip to content

Commit

Permalink
fix(admob): improve defense logic to prevent multiple calls (#4849)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsnow authored Feb 5, 2021
1 parent 129dc6a commit 5a71ad7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/admob/lib/ads/InterstitialAd.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export default class InterstitialAd extends MobileAd {

load() {
// Prevent multiple load calls
if (this._loaded) {
if (this._loaded || this._isLoadCalled) {
return;
}

this._loaded = true;
this._isLoadCalled = true;
this._admob.native.interstitialLoad(this._requestId, this._adUnitId, this._requestOptions);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/admob/lib/ads/MobileAd.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class MobileAd {
this._requestOptions = requestOptions;

this._loaded = false;
this._isLoadCalled = false;
this._onAdEventHandler = null;

this._nativeListener = admob.emitter.addListener(
Expand All @@ -45,6 +46,7 @@ export default class MobileAd {

if (type === AdEventType.CLOSED || type === RewardedAdEventType.CLOSED) {
this._loaded = false;
this._isLoadCalled = false;
}

if (this._onAdEventHandler) {
Expand Down
4 changes: 2 additions & 2 deletions packages/admob/lib/ads/RewardedAd.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export default class RewardedAd extends MobileAd {

load() {
// Prevent multiple load calls
if (this._loaded) {
if (this._loaded || this._isLoadCalled) {
return;
}

this._loaded = true;
this._isLoadCalled = true;
this._admob.native.rewardedLoad(this._requestId, this._adUnitId, this._requestOptions);
}

Expand Down

1 comment on commit 5a71ad7

@vercel
Copy link

@vercel vercel bot commented on 5a71ad7 Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.