Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PLA-1645] infuse token #143

Merged
merged 10 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '18'
cache: 'npm'

- name: Install dependencies
run: npm install

- name: Copy config.json
run: |
cp ./resources/js/config.json.example ./resources/js/config.json
- name: Build static project
run: npm run prod-laravel

- name: Archive build artifacts
uses: actions/upload-artifact@v4
with:
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: eslint
on:
push:
branches:
- master
pull_request:

jobs:
tests:
name: Eslint & Prettier
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm install

- name: Run Pretty
run: npm run pretty:check

- name: Run Eslint
run: npm run lint
3 changes: 2 additions & 1 deletion resources/js/api/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ export class CollectionApi {
return ApiService.sendPlatformRequest(data);
}

static async trackCollection(collectionId: string) {
static async trackCollection(collectionId: string, hotSync: boolean = false) {
const data = {
query: mutations.TrackCollection,
variables: {
chainIds: [parseInt(collectionId)],
hotSync,
},
};

Expand Down
7 changes: 5 additions & 2 deletions resources/js/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class ApiService {
credentials = 'omit',
mode,
nest = true,
auth = true,
}: {
url: string;
data?: Record<string, unknown>;
Expand All @@ -35,6 +36,7 @@ export class ApiService {
credentials?: 'omit' | 'same-origin' | 'include';
mode?: 'cors' | 'no-cors' | 'same-origin' | 'navigate';
nest?: boolean;
auth?: boolean;
}): Promise<any> {
let body: string | null = null;
const fullUrl = url;
Expand All @@ -44,10 +46,10 @@ export class ApiService {
body = JSON.stringify(data);
}

if (mode) {
if (auth) {
if (!useAppStore().isMultiTenant) {
headers.Authorization = useAppStore().authorization_token;
} else if (mode) {
} else {
headers['X-CSRF-TOKEN'] = csrf;
}
}
Expand Down Expand Up @@ -160,6 +162,7 @@ export class ApiService {
method: HttpMethods.GET,
credentials: undefined,
mode: undefined,
auth: false,
});
}

Expand Down
5 changes: 3 additions & 2 deletions resources/js/components/FormInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const props = withDefaults(
type?: string;
min?: number;
modelValue?: number | string | null;
value?: number | string | null;
disabled?: boolean;
prefix?: string;
name: string;
Expand Down Expand Up @@ -109,10 +110,10 @@ const inputChange = (e: Event) => {
const localModelValue = computed({
get() {
return props.modelValue;
return props.modelValue ?? props.value;
},
set(value) {
if (localModelValue.value !== value) {
if (value && localModelValue.value !== value) {
emit('update:modelValue', value);
}
},
Expand Down
11 changes: 7 additions & 4 deletions resources/js/components/TrackCollectionModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<div class="flex justify-end space-x-4 mt-6">
<Btn dusk="trackCancelBtn" @click="closeModal">Cancel</Btn>
<Btn dusk="trackConfirmBtn" primary @click="confirm">Track</Btn>
<Btn dusk="trackConfirmBtn" primary :loading="loading" :disabled="loading" @click="confirm">Track</Btn>
</div>
</Modal>
</template>
Expand All @@ -31,24 +31,27 @@ import { DialogTitle } from '@headlessui/vue';
import Btn from '~/components/Btn.vue';
import Modal from '~/components/Modal.vue';
import FormInput from './FormInput.vue';
import { onUnmounted, ref } from 'vue';
import { onMounted, ref } from 'vue';
const props = defineProps<{ isOpen: boolean }>();
const emit = defineEmits(['closed', 'confirm']);
const collectionId = ref();
const loading = ref(false);
const confirm = async () => {
loading.value = true;
emit('confirm', collectionId.value);
closeModal();
};
const closeModal = () => {
collectionId.value = '';
emit('closed');
};
onUnmounted(() => {
onMounted(() => {
collectionId.value = '';
loading.value = false;
});
</script>
9 changes: 6 additions & 3 deletions resources/js/components/pages/Collections.vue
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ const fetchUri = async (uri) => {
}

return '-';
} catch (e) {
} catch {
return '-';
}
};
Expand Down Expand Up @@ -427,18 +427,21 @@ const openTransactionSlide = async (transactionId: string) => {

const trackCollection = async (collectionId: string) => {
try {
await CollectionApi.trackCollection(collectionId);
const hotSync = !appStore.isMultiTenant;
await CollectionApi.trackCollection(collectionId, hotSync);
await getCollections();
snackbar.success({
title: 'Tracking',
text: 'Collection tracked successfully',
save: false,
});
} catch {
snackbar.info({
snackbar.error({
title: 'Tracking',
text: 'Tracking the collection failed',
});
} finally {
trackModal.value = false;
}
};

Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/pages/Tokens.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"
>
<td
class="whitespace-nowrap px-3 py-4 text-sm text-light-content dark:text-dark-content"
class="whitespace-nowrap px-3 py-4 text-sm font-medium text-light-content-strong dark:text-dark-content-strong"
>
{{ tokenNames[`${token.collection.collectionId}-${token.tokenId}`] }}
</td>
Expand Down
66 changes: 66 additions & 0 deletions resources/js/components/pages/create/CreateToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
label="Description"
description="The description of the token."
/>
<FormInput
v-model="symbol"
name="symbol"
label="Symbol"
description="The symbol of the token."
required
/>
<FormInput
v-model="recipient"
name="recipient"
Expand Down Expand Up @@ -268,6 +275,46 @@
</div>
<div class="mt-6">
<div class="flex flex-col gap-6">
<FormCheckbox
v-model="infuseEnj"
name="infuseEnj"
label="Infuse ENJ"
description="Use this option to infuse ENJ into the token."
readmore="https://support.nft.io/hc/en-gb/articles/20436178520594"
/>
<div v-if="infuseEnj" class="space-y-4">
<FormInput
v-model="infuseAmount"
name="infuseAmount"
label="ENJ Infusion"
description="Enter the amount of ENJ you wish to infuse in each unit."
type="number"
required
/>
<FormSelect
v-model="infuseAccess"
name="infuseAccess"
label="Infusion Access"
description=""
:options="['Only Me', 'Everyone']"
/>
<template v-if="tokenType === 'ft'">
<FormInput
v-model="initialSupply"
name="itemsInfuse"
label="Number of items"
type="number"
disabled
/>
<FormInput
:value="totalInfuseAmountComputed"
name="totalInfuseAmount"
label="Total Infuse Amount"
type="number"
disabled
/>
</template>
</div>
<FormCheckbox
v-model="listingForbidden"
name="listingForbidden"
Expand Down Expand Up @@ -369,7 +416,11 @@ const tokenId = ref({
});
const initialSupply = ref(1);
const capAmount = ref();
const infuseAmount = ref();
const isCurrency = ref(false);
const infuseEnj = ref(false);
const symbol = ref('');
const infuseAccess = ref('Only Me');
const beneficiaryAddress = ref('');
const beneficiaryPercentage = ref(0);
const listingForbidden = ref(false);
Expand All @@ -392,10 +443,15 @@ const capTypes =
const collectionIds = computed(() => appStore.collections);
const isAdvanced = computed(() => mode.value === 'advanced');
const totalInfuseAmountComputed = computed(() => {
return initialSupply.value * infuseAmount.value;
});
const validation = yup.object({
imageUrl: stringNotRequiredSchema,
name: stringRequiredSchema,
description: stringNotRequiredSchema,
symbol: stringRequiredSchema,
collectionId: collectionIdRequiredSchema,
tokenId: stringRequiredSchema,
recipient: addressRequiredSchema,
Expand Down Expand Up @@ -491,10 +547,20 @@ const createToken = async () => {
isCurrency: isCurrency.value,
},
listingForbidden: listingForbidden.value,
...(infuseEnj.value
? {
infusion: totalInfuseAmountComputed.value,
anyoneCanInfuse: infuseAccess.value === 'Everyone',
}
: {}),
attributes: [
...simpleAttributes(),
...attributes.value.filter((a) => a.key !== '' && a.value !== ''),
],
metadata: {
name: name.value,
symbol: symbol.value,
},
},
idempotencyKey: idempotencyKey.value,
skipValidation: skipValidation.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ import {
addressRequiredSchema,
booleanNotRequiredSchema,
collectionIdRequiredSchema,
numberNotRequiredSchema,
numberRequiredSchema,
stringNotRequiredSchema,
stringRequiredSchema,
Expand Down Expand Up @@ -130,7 +129,6 @@ const validation = yup.object({
tokenId: stringRequiredSchema,
recipient: addressRequiredSchema,
amount: numberRequiredSchema.typeError('Amount must be a number'),
unitPrice: numberNotRequiredSchema.min(0.01).typeError('Unit price must be a number'),
idempotencyKey: stringNotRequiredSchema,
skipValidation: booleanNotRequiredSchema,
});
Expand Down
4 changes: 2 additions & 2 deletions resources/js/graphql/mutation/TrackCollection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default `mutation addToTracked($type: ModelType! = COLLECTION, $chainIds:[BigInt!]!) {
AddToTracked(type: $type, chainIds: $chainIds, hotSync: false)
export default `mutation addToTracked($type: ModelType! = COLLECTION, $chainIds:[BigInt!]!, $hotSync: Boolean = false) {
AddToTracked(type: $type, chainIds: $chainIds, hotSync: $hotSync)
}`;
Loading