From 6044a799b127e8a0f16455da032f605c00056eef Mon Sep 17 00:00:00 2001 From: HamdiBenK <78487156+HamdiBenK@users.noreply.github.com> Date: Thu, 14 Sep 2023 16:34:00 +0100 Subject: [PATCH] New smart contract (#497) --- .../password-modal.component.ts | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/app/campaigns/components/password-modal/password-modal.component.ts b/src/app/campaigns/components/password-modal/password-modal.component.ts index bc02ef7c1..4eab80f3a 100755 --- a/src/app/campaigns/components/password-modal/password-modal.component.ts +++ b/src/app/campaigns/components/password-modal/password-modal.component.ts @@ -572,12 +572,24 @@ export class PasswordModalComponent implements OnInit { ); } - launchCampaignWithPerPerformanceReward(campaign_info: any) { + // Common logic for launching campaigns, handles date conversion and common actions. + private commonCampaignLogic(campaign_info: any, createCampaign: boolean): Observable { + // Convert the start date to Unix timestamp const startDateUnix = Math.floor(campaign_info.startDate.getTime() / 1000); campaign_info.startDate = startDateUnix; - if(campaign_info.currency === 'BNB') campaign_info.tokenAddress = null; - return this.campaignService.createCompaign(campaign_info).pipe( + + if (campaign_info.currency === 'BNB') { + campaign_info.tokenAddress = null; + } + + // Determine which campaign method to call based on the 'createCampaign' flag + const campaignObservable = createCampaign + && this.campaignService.createCompaign(campaign_info) + || this.campaignService.launchCampaignWithBounties(campaign_info); + + return campaignObservable.pipe( tap(() => { + // Reset common UI elements and flags after campaign launch this.gasError = false; this.showButtonSend = true; this.loadingButton = false; @@ -586,17 +598,12 @@ export class PasswordModalComponent implements OnInit { ); } - launchCampaignWithPerPublicationReward(campaign_info: any) { - return this.campaignService.launchCampaignWithBounties(campaign_info).pipe( - tap(() => { - this.gasError = false; + launchCampaignWithPerPerformanceReward(campaign_info: any) : Observable { + return this.commonCampaignLogic(campaign_info, true); + } - //let _campaign_Hash = Object.assign({}, this.campaign as any); - this.showButtonSend = true; - this.loadingButton = false; - this.passwordForm.reset(); - }) - ); + launchCampaignWithPerPublicationReward(campaign_info: any) : Observable { + return this.commonCampaignLogic(campaign_info, false); } handleLaunchResponseError(error: any, token: any) {