From 787066f6646829f5514ccddccf61d292984b0d7e Mon Sep 17 00:00:00 2001 From: noumantahir Date: Tue, 27 Aug 2024 17:15:42 +0500 Subject: [PATCH 1/3] updated make options method to discard duplicate beneficiaries --- src/utils/editor.ts | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/utils/editor.ts b/src/utils/editor.ts index 5f1f49996c..538260f346 100644 --- a/src/utils/editor.ts +++ b/src/utils/editor.ts @@ -1,5 +1,6 @@ import { diff_match_patch as diffMatchPatch } from 'diff-match-patch'; import MimeTypes from 'mime-types'; +import { unionBy } from 'lodash'; import { Image } from 'react-native'; import VersionNumber from 'react-native-version-number'; import getSlug from 'speakingurl'; @@ -94,8 +95,8 @@ export const generateUniquePermlink = (prefix) => { const timeFormat = `${t.getFullYear().toString()}${(t.getMonth() + 1).toString()}${t .getDate() .toString()}t${t.getHours().toString()}${t.getMinutes().toString()}${t - .getSeconds() - .toString()}${t.getMilliseconds().toString()}z`; + .getSeconds() + .toString()}${t.getMilliseconds().toString()}z`; return `${prefix}-${timeFormat}`; }; @@ -112,37 +113,33 @@ export const makeOptions = (postObj) => { permlink: postObj.permlink, max_accepted_payout: '1000000.000 HBD', percent_hbd: 10000, - extensions: [], + extensions: [] as any, }; + + + switch (postObj.operationType) { case 'sp': a.max_accepted_payout = '1000000.000 HBD'; a.percent_hbd = 0; - if (postObj.beneficiaries && postObj.beneficiaries.length > 0) { - postObj.beneficiaries.sort((a, b) => a.account.localeCompare(b.account)); - a.extensions = [[0, { beneficiaries: postObj.beneficiaries }]]; - } break; case 'dp': a.max_accepted_payout = '0.000 HBD'; a.percent_hbd = 10000; - if (postObj.beneficiaries && postObj.beneficiaries.length > 0) { - postObj.beneficiaries.sort((a, b) => a.account.localeCompare(b.account)); - a.extensions = [[0, { beneficiaries: postObj.beneficiaries }]]; - } break; default: a.max_accepted_payout = '1000000.000 HBD'; a.percent_hbd = 10000; - if (postObj.beneficiaries && postObj.beneficiaries.length > 0) { - postObj.beneficiaries.sort((a, b) => a.account.localeCompare(b.account)); - a.extensions = [[0, { beneficiaries: postObj.beneficiaries }]]; - } break; } + if (postObj.beneficiaries && postObj.beneficiaries.length > 0) { + postObj.beneficiaries.sort((a, b) => a.account.localeCompare(b.account)); + a.extensions = [[0, { beneficiaries: unionBy(postObj.beneficiaries, 'account') }]]; + } + return a; }; From e8a8e433c7f53ce1f3c54cd5f17c95ea0c7d8b6e Mon Sep 17 00:00:00 2001 From: noumantahir Date: Tue, 27 Aug 2024 17:16:36 +0500 Subject: [PATCH 2/3] passing pre extracted beneficiaries to schedule post method --- src/screens/editor/container/editorContainer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/screens/editor/container/editorContainer.tsx b/src/screens/editor/container/editorContainer.tsx index b68d9a773b..59b76ab667 100644 --- a/src/screens/editor/container/editorContainer.tsx +++ b/src/screens/editor/container/editorContainer.tsx @@ -748,6 +748,7 @@ class EditorContainer extends Component { fields, scheduleDate, jsonMeta, + beneficiaries, }); } else { await postContent( @@ -1188,13 +1189,12 @@ class EditorContainer extends Component { _setScheduledPost = (data) => { const { dispatch, intl, currentAccount, navigation } = this.props; const { rewardType } = this.state; - const beneficiaries = this._extractBeneficiaries(); const options = makeOptions({ author: data.author, permlink: data.permlink, operationType: rewardType, - beneficiaries, + beneficiaries: data.beneficiaries, }); addSchedule( From b5f6532fb031ce450bafe25c640f90190ae83a21 Mon Sep 17 00:00:00 2001 From: noumantahir Date: Tue, 27 Aug 2024 17:17:23 +0500 Subject: [PATCH 3/3] lint --- src/utils/editor.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/editor.ts b/src/utils/editor.ts index 538260f346..ef6f56a3f3 100644 --- a/src/utils/editor.ts +++ b/src/utils/editor.ts @@ -95,8 +95,8 @@ export const generateUniquePermlink = (prefix) => { const timeFormat = `${t.getFullYear().toString()}${(t.getMonth() + 1).toString()}${t .getDate() .toString()}t${t.getHours().toString()}${t.getMinutes().toString()}${t - .getSeconds() - .toString()}${t.getMilliseconds().toString()}z`; + .getSeconds() + .toString()}${t.getMilliseconds().toString()}z`; return `${prefix}-${timeFormat}`; }; @@ -116,8 +116,6 @@ export const makeOptions = (postObj) => { extensions: [] as any, }; - - switch (postObj.operationType) { case 'sp': a.max_accepted_payout = '1000000.000 HBD';