Skip to content

Commit

Permalink
Update nonFungible image
Browse files Browse the repository at this point in the history
  • Loading branch information
bokkypoobah committed Aug 1, 2024
1 parent f289244 commit fdcb8a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
31 changes: 21 additions & 10 deletions docs/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ const dataModule = {
}
Vue.set(state.tokens[chainId][contract].tokens[tokenId], 'active', !state.tokens[chainId][contract].tokens[tokenId].active);
},
setNonFungibleField(state, info) {
// console.log(now() + " INFO dataModule:mutations.setNonFungibleField: " + JSON.stringify(info, null, 2));
if (state.tokens[info.chainId] && state.tokens[info.chainId][info.contract] && state.tokens[info.chainId][info.contract].tokens[info.tokenId]) {
Vue.set(state.tokens[info.chainId][info.contract].tokens[info.tokenId], info.field, info.value);
}
},

addNewAddress(state, newAccount) {
// console.log(now() + " INFO dataModule:mutations.addNewAddress(" + JSON.stringify(newAccount, null, 2) + ")");
Expand Down Expand Up @@ -676,7 +682,7 @@ const dataModule = {
}
},
async saveData(context, types) {
console.log(now() + " INFO dataModule:actions.saveData - types: " + JSON.stringify(types));
// console.log(now() + " INFO dataModule:actions.saveData - types: " + JSON.stringify(types));
const db0 = new Dexie(context.state.db.name);
db0.version(context.state.db.version).stores(context.state.db.schemaDefinition);
for (let type of types) {
Expand All @@ -689,17 +695,17 @@ const dataModule = {
},

async toggleAddressField(context, info) {
console.log(now() + " INFO dataModule:actions.toggleAddressField - info: " + JSON.stringify(info));
// console.log(now() + " INFO dataModule:actions.toggleAddressField - info: " + JSON.stringify(info));
await context.commit('toggleAddressField', info);
await context.dispatch('saveData', ['addresses']);
},
async setAddressField(context, info) {
console.log(now() + " INFO dataModule:actions.setAddressField - info: " + JSON.stringify(info));
// console.log(now() + " INFO dataModule:actions.setAddressField - info: " + JSON.stringify(info));
await context.commit('setAddressField', info);
await context.dispatch('saveData', ['addresses']);
},
async updateFungibleTotalSupply(context, info) {
console.log(now() + " INFO dataModule:actions.updateFungibleTotalSupply - info: " + JSON.stringify(info));
// console.log(now() + " INFO dataModule:actions.updateFungibleTotalSupply - info: " + JSON.stringify(info));
const provider = new ethers.providers.Web3Provider(window.ethereum);
const interface = new ethers.Contract(info.contract, ERC20ABI, provider);
try {
Expand All @@ -710,32 +716,37 @@ const dataModule = {
// await context.dispatch('saveData', ['tokens']);
},
async toggleFungibleJunk(context, item) {
console.log(now() + " INFO dataModule:actions.toggleFungibleJunk - item: " + JSON.stringify(item));
// console.log(now() + " INFO dataModule:actions.toggleFungibleJunk - item: " + JSON.stringify(item));
await context.commit('toggleFungibleJunk', item);
await context.dispatch('saveData', ['tokens']);
},
async toggleFungibleActive(context, item) {
console.log(now() + " INFO dataModule:actions.toggleFungibleActive - item: " + JSON.stringify(item));
// console.log(now() + " INFO dataModule:actions.toggleFungibleActive - item: " + JSON.stringify(item));
await context.commit('toggleFungibleActive', item);
await context.dispatch('saveData', ['tokens']);
},
async setFungibleField(context, item) {
console.log(now() + " INFO dataModule:actions.setFungibleField - item: " + JSON.stringify(item));
// console.log(now() + " INFO dataModule:actions.setFungibleField - item: " + JSON.stringify(item));
await context.commit('setFungibleField', item);
await context.dispatch('saveData', ['tokens']);
},
async toggleNonFungibleJunk(context, item) {
console.log(now() + " INFO dataModule:actions.toggleNonFungibleJunk - item: " + JSON.stringify(item));
// console.log(now() + " INFO dataModule:actions.toggleNonFungibleJunk - item: " + JSON.stringify(item));
await context.commit('toggleNonFungibleJunk', item);
await context.dispatch('saveData', ['tokens']);
},
async toggleNonFungibleActive(context, item) {
console.log(now() + " INFO dataModule:actions.toggleNonFungibleActive - item: " + JSON.stringify(item));
// console.log(now() + " INFO dataModule:actions.toggleNonFungibleActive - item: " + JSON.stringify(item));
await context.commit('toggleNonFungibleActive', item);
await context.dispatch('saveData', ['tokens']);
},
async setNonFungibleField(context, item) {
// console.log(now() + " INFO dataModule:actions.setNonFungibleField - item: " + JSON.stringify(item));
await context.commit('setNonFungibleField', item);
await context.dispatch('saveData', ['tokens']);
},
async addNonFungibleMetadata(context, info) {
console.log(now() + " INFO dataModule:actions.addNonFungibleMetadata - info: " + JSON.stringify(info, null, 2));
// console.log(now() + " INFO dataModule:actions.addNonFungibleMetadata - info: " + JSON.stringify(info, null, 2));
context.commit('addNonFungibleMetadata', info);
await context.dispatch('saveData', ['tokens']);
},
Expand Down
13 changes: 13 additions & 0 deletions docs/viewNonFungible.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ const ViewNonFungible = {
</b-img> -->
</b-form-group>
<b-form-group label="" label-for="token-updateimage" label-size="sm" label-cols-sm="3" label-align-sm="right" class="mx-0 my-1 p-0">
<b-form-file size="sm" id="token-updateimage" @change="handleImage" accept="image/*" placeholder="Update image" class="w-50">
</b-form-file>
</b-form-group>
</b-col>
<b-col>
<b-form-group label="Attributes:" label-for="token-image" label-size="sm" label-cols-sm="3" label-align-sm="right" class="mx-0 my-1 p-0">
Expand Down Expand Up @@ -378,6 +382,15 @@ const ViewNonFungible = {
},
},
methods: {
async handleImage(e) {
const selectedImage = e.target.files[0];
try {
const image = await toBase64(selectedImage);
store.dispatch('data/setNonFungibleField', { chainId: this.chainId, contract: this.contract, tokenId: this.tokenId, field: 'image', value: image });
} catch (e) {
console.log(now() + " ERROR ViewNonFungible:methods.handleImage: " + e.message);
}
},
nonFungibleViewerURL(contract, tokenId) {
return this.nonFungibleViewer.replace(/\${contract}/, contract).replace(/\${tokenId}/, tokenId);
},
Expand Down

0 comments on commit fdcb8a5

Please sign in to comment.