Fix visibility setting and use the account details when distributing ads

This commit is contained in:
Mark Veidemanis 2022-03-08 21:27:45 +00:00
parent 6b599902c0
commit 5ed07abc07
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 20 additions and 13 deletions

View File

@ -513,7 +513,7 @@ class Agora(util.Base):
return (min_amount, max_amount) return (min_amount, max_amount)
@util.handle_exceptions @util.handle_exceptions
def create_ad(self, asset, countrycode, currency, provider, payment_details, visible=True, edit=False, ad_id=None): def create_ad(self, asset, countrycode, currency, provider, payment_details, visible=None, edit=False, ad_id=None):
""" """
Post an ad with the given asset in a country with a given currency. Post an ad with the given asset in a country with a given currency.
Convert the min and max amounts from settings to the given currency with CurrencyRates. Convert the min and max amounts from settings to the given currency with CurrencyRates.
@ -546,8 +546,11 @@ class Agora(util.Base):
"require_trusted_by_advertiser": False, "require_trusted_by_advertiser": False,
"online_provider": provider, "online_provider": provider,
"payment_method_details": settings.Agora.PaymentMethodDetails, "payment_method_details": settings.Agora.PaymentMethodDetails,
"visible": visible,
} }
if visible is False:
form["visible"] = False
elif visible is True:
form["visible"] = False
if payment_details: if payment_details:
form["account_info"] = payment_details_text form["account_info"] = payment_details_text
form["msg"] = ad_text form["msg"] = ad_text
@ -569,12 +572,14 @@ class Agora(util.Base):
""" """
dist_list = list(self.markets.create_distribution_list(filter_asset)) dist_list = list(self.markets.create_distribution_list(filter_asset))
our_ads = self.enum_ads() our_ads = self.enum_ads()
supported_currencies, account_info = self.markets.get_valid_account_details()
# Let's get rid of the ad IDs and make it a tuple like dist_list # Let's get rid of the ad IDs and make it a tuple like dist_list
our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads] our_ads = [(x[0], x[2], x[3], x[4]) for x in our_ads]
for asset, countrycode, currency, provider in dist_list: for asset, countrycode, currency, provider in dist_list:
if (asset, countrycode, currency, provider) not in our_ads: if (asset, countrycode, currency, provider) not in our_ads:
if currency in supported_currencies:
# Create the actual ad and pass in all the stuff # Create the actual ad and pass in all the stuff
rtrn = self.create_ad(asset, countrycode, currency, provider) rtrn = self.create_ad(asset, countrycode, currency, provider, payment_details=account_info[currency])
# Bail on first error, let's not continue # Bail on first error, let's not continue
if rtrn is False: if rtrn is False:
return False return False
@ -590,7 +595,9 @@ class Agora(util.Base):
:rtype: bool or dict :rtype: bool or dict
""" """
our_ads = self.enum_ads() our_ads = self.enum_ads()
supported_currencies, account_info = self.markets.get_valid_account_details()
for asset, ad_id, countrycode, currency, provider in our_ads: for asset, ad_id, countrycode, currency, provider in our_ads:
if currency in supported_currencies:
rtrn = self.create_ad(asset, countrycode, currency, provider, edit=True, ad_id=ad_id) rtrn = self.create_ad(asset, countrycode, currency, provider, edit=True, ad_id=ad_id)
# Bail on first error, let's not continue # Bail on first error, let's not continue
if rtrn is False: if rtrn is False: