-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
@apbendi @mds1 I think this is a good solution
what this does is that it inserts the placeholder image if no logo has been uploaded, and it also resolves #532 just one question is about protocol, I believe 1 is fine now since it won't have an empty cid field |
@mk1r That solution doesn't really make sense with our The fact that we fallback to |
Hmm interesting you mention we are loading a hash, because I tested it out and it was retrieving the |
Huh interesting, that sounds like a bug then because it should be resolving the pointers using Either way, even though it does work we don't want to conflate the protocol-level spec (the Is there a reason we don't want to use this approach? |
e08e860
to
2a801b8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mk1r, I created a grant without a logo, but viewing the homepage with this branch, I still get the error "Unsupported Protocol ID 0". The app should not throw an error if there is an unsupported protocol, it should gracefully degrade and show the placeholder image instead.
So to recap:
- When creating a grant, if no image is provided, the logo metaptr should be set to 0/''
- When loading a grant, if the logo metaptr has a protocol value of anything other than
1
, the app should load the placeholder image.
Does this make sense?
@apbendi interesting, I'm not able to reproduce that error - for me, it's doing what you describe in the recap I'll also double check the code in homepage (which I haven't modified) - which network are you using btw? |
@mk1r I'm on Polygon.
Maybe I'm missing something, but it looks like we're still throwing here, so I don't see how this would be the case: https://github.com/dcgtc/dgrants/pull/522/files#diff-e87dc6bd5d221441ff0d6a39efdce1b52d884442b20b73c3457e68aca79b29dcR18 |
@apbendi but it shouldn't throw when protocol is 0 right? https://github.com/dcgtc/dgrants/pull/522/files#diff-e87dc6bd5d221441ff0d6a39efdce1b52d884442b20b73c3457e68aca79b29dcR17 |
@mk1r Ahh yes that's true, but we shouldn't be special casing protocol 0, we should be failing gracefully for all non-1 values. As for why this isn't working for me, it's not clear. If you test against Polygon right now (where my no-logo grant exists) what are you able to reproduce the error? |
@apbendi think I found the issue, it's in utils - will push out an update, good find |
2a801b8
to
381cb8c
Compare
try now @apbendi rebased as well |
app/src/utils/data/ipfs.ts
Outdated
@@ -54,7 +55,7 @@ export const getMetaPtr = ({ cid }: { cid: string | undefined }) => { | |||
*/ | |||
export const formatMetaPtr = (cid: string): MetaPtr => { | |||
return { | |||
protocol: 1, // IPFS has a protocol ID of 1 | |||
protocol: cid ? 1 : 0, // IPFS has a protocol ID of 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? We shouldn't have to special case protocol 0 within the ipfs
(protocol 1) file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this where we want to make the adjustment to the object?
i.e
{
"protocol": 0,
"pointer": ""
}
when no logo is uploaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would be better handled in the utils method that wraps around this method, similarly to help keep the app vs. protocol separation clean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point me to the file / line? This is what's being returned to be uploaded to ipfs, right? I assumed that's where this issue was #522 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m on mobile right now about to take off on a flight, but I think I see what’s happening
You’re using this in the upload logo step, which is coupled to IPFS, which is why you put it here. I thought this was for parsing the logo
It still feels a little dirty IMO to have it here instead of a createEmptyPtr() method that those files fallback to if no image is uploaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see - I'll take a look at the method, but is there a different place we want to adjust the object? Isn't this where we want to make the change to the object if no logo is uploaded?
(btw, do appreciate you chiming in as I know you're pretty much on holiday lol)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we’re setting the logo pointer of metadata JSON to be empty and point to nothing, that is entirely independent of IPFS, which is why I don’t think it should be handled in this file. You can do that in utils or just generate it directly in the file(s?) that needs it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think there is a way around modifying the object - is that what you're suggesting? i.e your option 2 #522 (comment)
bc88eea
to
9504b58
Compare
app/src/utils/utils.ts
Outdated
@@ -103,6 +103,7 @@ export function decodeMetadataId(id: string): MetaPtr { | |||
export function ptrToURI(logoPtr: MetaPtr | undefined | null) { | |||
if (!logoPtr) return null; | |||
const { protocol, pointer } = logoPtr; | |||
if (protocol === 0) return 'placeholder_grant.svg'; | |||
if (protocol === 1) return getMetaPtr({ cid: pointer }); | |||
throw new Error(`Unsupported protocol ID ${protocol}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should never throw. Even if loading the metaPtr fails, we should log to console but always degrade gracefully and show the placeholder.
app/src/utils/data/ipfs.ts
Outdated
@@ -14,7 +14,8 @@ function assertIPFSPointer(logoPtr: MetaPtr | undefined) { | |||
logoPtr = decodeMetadataId(logoPtr); | |||
} | |||
const protocol = BigNumber.from(logoPtr.protocol).toString(); | |||
if (protocol !== '1') throw new Error(`assertIPFSPointer: Expected protocol ID of 1, found ${protocol}`); | |||
if (protocol !== '1' && protocol !== '0' && !logoPtr.pointer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so as written, if anyone were to upload/update a grant with a metaPtr that had a value other than 1
or 0
, or with an empty pointer, this method would throw. Since we call this method in getMetaPtr
, and use that method to fetch metadata throughout the app, then if anyone were to do this, the app would start throwing errors.
I don't believe an unsupported protocol
value, or empty/invalid metaPtr
value, should result in the app throwing errors at any point, since users could put anything in there, and we can't control that. I think it should always degrade gracefully in some way, for example by simply excluding the grant if content fails to load. This might require a different PR though. Curious to hear what you think @mds1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally agreed! Though this file isn't the right place to handle that graceful degradation based on how I was thinking of the architecture.
For context: getMetaPtr
should primarily only be called by the ptrToURI
wrapper method, with an exception for new grant / image upload code paths that call it directly because they're currently tightly coupled to IPFS. My intent with this assertIPFSPointer
was to make sure only IPFS pointers are being passed into the methods in this file, and this file should be limited to handling cases where protocol
is 1. Therefore if we throw in this method that's a bug and in that case I think it's ok to fail loudly. Given that, this line should only be if (protocol !== '1') throw new Error(...)
and this entire file should not care about protocol
being any non-1 value
Given all that, and if you agree with that architecture decision of isolating this file to strictly deal with IPFS, then ptrToURI
and other methods in utils.ts
are where we should gracefully handle the failure.
acea1df
to
2e08c03
Compare
app/src/utils/data/ipfs.ts
Outdated
if (!['0', '1'].includes(protocol)) | ||
throw new Error(`assertIPFSPointer: Expected protocol ID of 0 or 1, found ${protocol}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed f1fd499 to revert this because this file shouldn't be aware of protocol ID 0
f1fd499
to
31d7540
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be working 👍
175a768
to
cc1120d
Compare
resolves #521