-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
Create NonStandardFallbackClass #838
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { BN } from 'ethereumjs-util'; | ||
import { UNKNOWN_STANDARD } from '../../constants'; | ||
import { ERC721Standard } from './CollectibleStandards/ERC721/ERC721Standard'; | ||
import { ERC20Standard } from './ERC20Standard'; | ||
|
||
export class NonStandardFallback { | ||
private erc20Standard: ERC20Standard; | ||
|
||
private erc721Standard: ERC721Standard; | ||
|
||
constructor({ | ||
erc20Standard, | ||
erc721Standard, | ||
}: { | ||
erc20Standard: ERC20Standard; | ||
erc721Standard: ERC721Standard; | ||
}) { | ||
this.erc20Standard = erc20Standard; | ||
this.erc721Standard = erc721Standard; | ||
} | ||
|
||
/** | ||
* Query for useful values if a contract does not fully implement one of the three major token interfaces we support (ERC20, ERC721, ERC1155). | ||
* | ||
* @param address - Asset contract address. | ||
* @param ipfsGateway - The user's preferred IPFS gateway. | ||
* @param userAddress - The public address for the currently active user's account. | ||
* @param tokenId - tokenId of a given token in the contract. | ||
* @returns Promise resolving an object containing the standard, decimals, symbol and balance of the given contract/userAddress pair. | ||
*/ | ||
async getDetails( | ||
address: string, | ||
ipfsGateway: string, | ||
userAddress?: string, | ||
tokenId?: string, | ||
): Promise<{ | ||
standard: string; | ||
symbol: string | undefined; | ||
decimals: string | undefined; | ||
balance: BN | undefined; | ||
name: string | undefined; | ||
tokenURI: string | undefined; | ||
image: string | undefined; | ||
}> { | ||
let decimals, symbol, balance, name, image, tokenURI; | ||
|
||
try { | ||
decimals = await this.erc20Standard.getTokenDecimals(address); | ||
} catch { | ||
// ignore | ||
} | ||
|
||
try { | ||
decimals = await this.erc20Standard.getTokenSymbol(address); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} catch { | ||
// ignore | ||
} | ||
|
||
if (userAddress) { | ||
try { | ||
balance = await this.erc20Standard.getBalanceOf(address, userAddress); | ||
} catch { | ||
// ignore | ||
} | ||
} | ||
|
||
try { | ||
name = await this.erc721Standard.getAssetName(address); | ||
} catch { | ||
// ignore | ||
} | ||
|
||
if (tokenId) { | ||
({ tokenURI, image } = await this.erc721Standard.getTokenURIAndImage( | ||
address, | ||
ipfsGateway, | ||
tokenId, | ||
)); | ||
} | ||
|
||
return { | ||
standard: UNKNOWN_STANDARD, | ||
decimals, | ||
symbol, | ||
balance, | ||
name, | ||
tokenURI, | ||
image, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ export const RINKEBY_CHAIN_ID = '4'; | |
export const ERC721 = 'ERC721'; | ||
export const ERC1155 = 'ERC1155'; | ||
export const ERC20 = 'ERC20'; | ||
export const UNKNOWN_STANDARD = 'UNKNOWN_STANDARD'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The important thing is how we handle this in the extension imo. |
||
|
||
// TOKEN INTERFACE IDS | ||
export const ERC721_INTERFACE_ID = '0x80ac58cd'; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 may potentially leak users IP. Needs to be an issue created if there isn't already.