Skip to content

Commit

Permalink
add expire option on marketplace
Browse files Browse the repository at this point in the history
  • Loading branch information
Cabecinha84 committed Oct 26, 2024
1 parent c251e41 commit bd5fa32
Showing 1 changed file with 73 additions and 3 deletions.
76 changes: 73 additions & 3 deletions HomeUI/src/views/apps/marketplace/AppView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@
/>
</b-form-group>
</div>
<b-form-group
v-if="appData.version >= 6"
label-cols="3"
label-cols-lg="20"
label="Period"
label-for="period"
>
<div class="mx-1">
{{ getExpireLabel }}
</div>
<b-form-input
id="period"
v-model="expirePosition"
placeholder="How long an application will live on Flux network"
type="range"
:min="0"
:max="3"
:step="1"
/>
</b-form-group>
<b-card style="padding: 0;">
<b-tabs @activate-tab="componentSelected">
<b-tab
Expand Down Expand Up @@ -901,10 +921,50 @@ export default {
const appRegistrationSpecification = ref(null);
const tooltipText = ref('Copy to clipboard');
const copyButtonRef = ref(null);
const expireOptions = ref([]);
const expirePosition = ref(Number(0));
expireOptions.value = [
{
value: 22000,
label: '1 month',
time: 30 * 24 * 60 * 60 * 1000,
},
{
value: 66000,
label: '3 months',
time: 90 * 24 * 60 * 60 * 1000,
},
{
value: 132000,
label: '6 months',
time: 180 * 24 * 60 * 60 * 1000,
},
{
value: 264000,
label: '1 year',
time: 365 * 24 * 60 * 60 * 1000,
},
];
const config = computed(() => vm.$store.state.flux.config);
const validTill = computed(() => timestamp.value + 60 * 60 * 1000); // 1 hour
const subscribedTill = computed(() => timestamp.value + 30 * 24 * 60 * 60 * 1000 + 60 * 60 * 1000); // 1 month
const subscribedTill = computed(() => {
if (props.appData.version >= 6) {
const auxArray = expireOptions.value;
if (auxArray[expirePosition.value]) {
return Date.now() + auxArray[expirePosition.value].time;
}
}
const expTime = Date.now() + 30 * 24 * 60 * 60 * 1000; // 1 month
return expTime;
});
const getExpireLabel = computed(() => {
const auxArray = expireOptions.value;
if (auxArray[expirePosition.value]) {
return auxArray[expirePosition.value].label;
}
return null;
});
const callbackValue = () => {
const { protocol, hostname, port } = window.location;
Expand Down Expand Up @@ -1527,7 +1587,8 @@ export default {
}
}
if (props.appData.version >= 6) {
appSpecification.expire = props.appData.expire || 22000;
const auxArray = expireOptions.value;
appSpecification.expire = auxArray[expirePosition.value].value || 22000;
}
if (props.appData.version >= 7) {
appSpecification.staticip = props.appData.staticip;
Expand Down Expand Up @@ -1645,10 +1706,17 @@ export default {
applicationPriceFluxDiscount.value = '';
const auxSpecsFormatted = JSON.parse(JSON.stringify(appSpecFormatted));
auxSpecsFormatted.priceUSD = props.appData.priceUSD;
console.log(auxSpecsFormatted.priceUSD);
if (appInstances.value && appInstances.value > 3) {
auxSpecsFormatted.priceUSD = Number(((auxSpecsFormatted.priceUSD * appInstances.value) / 3).toFixed(2));
}
if (expirePosition.value === '1') {
auxSpecsFormatted.priceUSD *= 3;
} else if (expirePosition.value === '2') {
auxSpecsFormatted.priceUSD *= 6;
} else if (expirePosition.value === '3') {
auxSpecsFormatted.priceUSD *= 12;
}
const response = await AppsService.appPriceUSDandFlux(auxSpecsFormatted);
if (response.data.status === 'error') {
throw new Error(response.data.data.message || response.data.data);
Expand Down Expand Up @@ -2169,6 +2237,8 @@ export default {
confirmLaunchDialogCloseShowing,
confirmLaunchDialogFinish,
confirmLaunchDialogCancel,
expirePosition,
getExpireLabel,
currentComponent,
componentSelected,
Expand Down

0 comments on commit bd5fa32

Please sign in to comment.