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

fix logoURI split error #522

Merged
merged 11 commits into from
Nov 30, 2021
8 changes: 4 additions & 4 deletions app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dgrants/app",
"version": "0.2.18-7f04586.0",
"version": "0.2.19-cc1120d.0",
"private": true,
"scripts": {
"clean": "rimraf dist",
Expand All @@ -14,9 +14,9 @@
"prettier": "prettier --write ."
},
"dependencies": {
"@dgrants/contracts": "^0.2.15-7f04586.0",
"@dgrants/dcurve": "^0.2.15-7f04586.0",
"@dgrants/types": "^0.2.15-7f04586.0",
"@dgrants/contracts": "^0.2.16-cc1120d.0",
"@dgrants/dcurve": "^0.2.16-cc1120d.0",
"@dgrants/types": "^0.2.16-cc1120d.0",
"@fusion-icons/vue": "^0.0.0",
"@headlessui/vue": "^1.2.0",
"@tailwindcss/aspect-ratio": "^0.2.1",
Expand Down
2 changes: 2 additions & 0 deletions app/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ export const trustBonusKey = 'TrustBonus';
// LocalForage key-prefixes (partial key, we store an object for each instance)
export const grantRoundKeyPrefix = 'GrantRound-';
export const grantRoundsCLRDataKeyPrefix = 'GrantRoundsGrantData-';

export const NO_LOGO_OBJECT = { protocol: 0, pointer: '' };
13 changes: 10 additions & 3 deletions app/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,18 @@ export function decodeMetadataId(id: string): MetaPtr {
}

// Given a logoPtr, resolve it to a URI that we can fetch
export function ptrToURI(logoPtr: MetaPtr | undefined | null) {
if (!logoPtr) return null;
export function ptrToURI(logoPtr: MetaPtr | undefined | null, fallbackURI = '/placeholder_grant.svg') {
// Handle the null and undefined cases
if (!logoPtr) {
console.warn(`Received empty logoPtr, using fallback URI of ${fallbackURI}`);
return fallbackURI;
}

// Parse the pointer
const { protocol, pointer } = logoPtr;
if (protocol === 1) return getMetaPtr({ cid: pointer });
throw new Error(`Unsupported protocol ID ${protocol}`);
console.warn(`Unsupported protocol ID ${1}, using fallback URI of ${fallbackURI}`);
return fallbackURI;
}

// --- Validation ---
Expand Down
7 changes: 4 additions & 3 deletions app/src/views/GrantRegistryGrantDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ import useCartStore from 'src/store/cart';
import useDataStore from 'src/store/data';
import useWalletStore from 'src/store/wallet';
// --- Methods and Data ---
import { LOREM_IPSOM_TEXT } from 'src/utils/constants';
import { LOREM_IPSOM_TEXT, NO_LOGO_OBJECT } from 'src/utils/constants';
import { ContractTransaction } from 'src/utils/ethers';
import { DGRANTS_CHAIN_ID } from 'src/utils/chains';
import {
Expand Down Expand Up @@ -603,9 +603,10 @@ function useGrantDetail() {
if (isMetaPtrUpdated) {
const twitterURI = twitter === '' ? twitter : urlFromTwitterHandle(twitter);
const properties = { websiteURI: website, githubURI: github, twitterURI };
const cid = (gMetadata?.logoPtr as MetaPtr).pointer;
const cid = logoURI ? (gMetadata?.logoPtr as MetaPtr).pointer : '';
const logoPtr = cid ? ipfs.formatMetaPtr(cid) : NO_LOGO_OBJECT;
metaPtr = await ipfs
.uploadGrantMetadata({ name, description, logoPtr: ipfs.formatMetaPtr(cid), properties })
.uploadGrantMetadata({ name, description, logoPtr, properties })
.then((cid) => ipfs.formatMetaPtr(cid.toString()));
}

Expand Down
12 changes: 8 additions & 4 deletions app/src/views/GrantRegistryNewGrant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ import TransactionStatus from 'src/components/TransactionStatus.vue';
// --- Store ---
import useWalletStore from 'src/store/wallet';
// --- Methods and Data ---
import { LOREM_IPSOM_TEXT } from 'src/utils/constants';
import { LOREM_IPSOM_TEXT, NO_LOGO_OBJECT } from 'src/utils/constants';
import { isValidAddress, isValidWebsite, isValidGithub, isValidTwitter, isDefined, pushRoute, urlFromTwitterHandle, isValidLogo, watchTransaction } from 'src/utils/utils'; // prettier-ignore
import * as ipfs from 'src/utils/data/ipfs';

Expand Down Expand Up @@ -240,10 +240,14 @@ function useNewGrant() {
const properties = { websiteURI: website, githubURI: github, twitterURI };
if (!signer.value) throw new Error('Please connect a wallet');
if (!isCorrectNetwork.value) throw new Error('Wrong network');
const splitLogoURI = (logoURI as string).split('/');
const cid = splitLogoURI[splitLogoURI.length - 1];
let cid = '';
if (logoURI) {
const splitLogoURI = (logoURI as string).split('/');
cid = splitLogoURI[splitLogoURI.length - 1];
}
const logoPtr = cid ? ipfs.formatMetaPtr(cid) : NO_LOGO_OBJECT;
const metaPtr = await ipfs
.uploadGrantMetadata({ name, description, logoPtr: ipfs.formatMetaPtr(cid), properties })
.uploadGrantMetadata({ name, description, logoPtr, properties })
.then((cid) => ipfs.formatMetaPtr(cid.toString()));

// watch the transaction to check for any replacements/cancellations and update txHash accordingly
Expand Down
4 changes: 2 additions & 2 deletions contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@dgrants/contracts",
"version": "0.2.15-7f04586.0",
"version": "0.2.16-cc1120d.0",
"devDependencies": {
"@dgrants/types": "^0.2.15-7f04586.0",
"@dgrants/types": "^0.2.16-cc1120d.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/contracts": "3.4.1-solc-0.7-2",
Expand Down
6 changes: 3 additions & 3 deletions dcurve/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dgrants/dcurve",
"version": "0.2.15-7f04586.0",
"version": "0.2.16-cc1120d.0",
"private": true,
"description": "distribution generator for GrantCLR in dgrants",
"keywords": [
Expand Down Expand Up @@ -29,8 +29,8 @@
"extends": "../package.json"
},
"dependencies": {
"@dgrants/contracts": "^0.2.15-7f04586.0",
"@dgrants/utils": "^0.2.13-7f04586.0",
"@dgrants/contracts": "^0.2.16-cc1120d.0",
"@dgrants/utils": "^0.2.14-cc1120d.0",
"buffer": "^6.0.3",
"ethers": "^5.4.6"
},
Expand Down
2 changes: 1 addition & 1 deletion types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dgrants/types",
"version": "0.2.15-7f04586.0",
"version": "0.2.16-cc1120d.0",
"types": "src/index.d.ts",
"scripts": {
"build": "tsc -b .",
Expand Down
2 changes: 1 addition & 1 deletion utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dgrants/utils",
"version": "0.2.13-7f04586.0",
"version": "0.2.14-cc1120d.0",
"description": "common methods shared",
"keywords": [
"dgrants",
Expand Down