-
Notifications
You must be signed in to change notification settings - Fork 4k
Update zerion extension #18165
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
Closed
Closed
Update zerion extension #18165
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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,72 @@ | ||
import { getZpiHeaders, ZPI_URL } from "../shared/api"; | ||
import { normalizeAddress } from "../shared/NormalizedAddress"; | ||
import { AddressPortfolio, Position } from "../shared/types"; | ||
import { handleError } from "../shared/utils"; | ||
|
||
type Input = { | ||
/** | ||
* Ethereum address or ENS domain to look up | ||
*/ | ||
addressOrDomain: string; | ||
}; | ||
|
||
export default async function (input: Input): Promise<{ portfolio?: AddressPortfolio; positions?: Position[] }> { | ||
let address: string | null = null; | ||
|
||
try { | ||
const response = await fetch(`${ZPI_URL}wallet/get-meta/v1?identifiers=${input.addressOrDomain}`, { | ||
headers: getZpiHeaders(), | ||
}); | ||
const result = await response.json(); | ||
address = normalizeAddress(result.data[0]?.address); | ||
} catch (error) { | ||
handleError({ title: "Failed to fetch wallet", error }); | ||
return {}; | ||
} | ||
|
||
let portfolio: { data: AddressPortfolio } | null = null; | ||
|
||
try { | ||
const portfolioResponse = await fetch(`${ZPI_URL}wallet/get-portfolio/v1`, { | ||
method: "POST", | ||
headers: getZpiHeaders({ "Zerion-Wallet-Provider": "Watch Address" }), | ||
body: JSON.stringify({ | ||
addresses: [address], | ||
currency: "usd", | ||
nftPriceType: "not_included", | ||
}), | ||
}); | ||
portfolio = await portfolioResponse.json(); | ||
} catch (error) { | ||
handleError({ title: "Failed to fetch wallet portfolio", error }); | ||
return {}; | ||
} | ||
|
||
let cleanedPositions: Position[] = []; | ||
try { | ||
const positionsResponse = await fetch(`${ZPI_URL}wallet/get-positions/v1`, { | ||
method: "POST", | ||
headers: getZpiHeaders({ "Zerion-Wallet-Provider": "Watch Address" }), | ||
body: JSON.stringify({ | ||
addresses: [address], | ||
currency: "usd", | ||
}), | ||
}); | ||
const positions = await positionsResponse.json(); | ||
cleanedPositions = positions.data.map((position: Position) => { | ||
return { | ||
value: position.value, | ||
chain: position.chain, | ||
name: position.asset.name, | ||
symbol: position.asset.symbol, | ||
id: position.asset.id, | ||
}; | ||
}); | ||
} catch (error) { | ||
handleError({ title: "Failed to fetch wallet positions", error }); | ||
} | ||
return { | ||
portfolio: portfolio?.data, | ||
positions: cleanedPositions, | ||
}; | ||
} |
This file contains hidden or 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,43 @@ | ||
import { getZpiHeaders, ZPI_URL } from "../shared/api"; | ||
import { handleError } from "../shared/utils"; | ||
|
||
interface Input { | ||
/** | ||
* Ethereum address of the token | ||
* required parameter | ||
* example: 0x6b175474e89094c44da98b954eedeac495271d0f | ||
*/ | ||
tokenId: string; | ||
/** | ||
* Time period until now that we want to check the price points | ||
* optional parameter | ||
* check the last year price by default | ||
*/ | ||
period?: "1h" | "1d" | "1w" | "1m" | "1y" | "max"; | ||
} | ||
|
||
/** | ||
* this tool returns the historical price of a token as an array of pair [timestamp, price] | ||
*/ | ||
export default async function (input: Input): Promise<[string, number][]> { | ||
try { | ||
const response = await fetch(`${ZPI_URL}asset/get-fungible-chart/v1`, { | ||
method: "POST", | ||
headers: getZpiHeaders(), | ||
body: JSON.stringify({ | ||
fungibleId: input.tokenId, | ||
currency: "usd", | ||
addresses: [], | ||
period: input.period, | ||
}), | ||
}); | ||
const chartPointsRaw = await response.json(); | ||
return chartPointsRaw.data.points.map((item: { timestamp: string; value: number; extra: null }) => [ | ||
item.timestamp, | ||
item.value, | ||
]); | ||
} catch (error) { | ||
handleError({ title: "Failed to fetch token price chart", error }); | ||
return []; | ||
} | ||
} |
This file contains hidden or 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,45 @@ | ||
import { open } from "@raycast/api"; | ||
import { handleError } from "../shared/utils"; | ||
|
||
interface Input { | ||
/** | ||
* Chain ID of the network | ||
* example: ethereum, polygon, zero | ||
*/ | ||
chain?: string; | ||
/** | ||
* Token ID of the token to send | ||
* it should not be a token name or symbol! | ||
* example: 0x6b175474e89094c44da98b954eedeac495271d0f or c582638a-e7c3-45b9-ac7e-1e7295b822b5 | ||
*/ | ||
sendTokenId?: string; | ||
/** | ||
* Amount to send | ||
* example: 100 | ||
*/ | ||
sendAmount?: number; | ||
/** | ||
* Ethereum address or ens domain to receive the token | ||
*/ | ||
recipient?: string; | ||
} | ||
|
||
/** | ||
* Generate and open a link to send some tokens to a recepient on Zerion | ||
* you can pass recepient as is from the request | ||
* in case some params are not given, leave them empty | ||
*/ | ||
export default async function (input: Input) { | ||
const urlParams = new URLSearchParams({ | ||
tokenChain: input.chain || "", | ||
addressInputValue: input.recipient || "", | ||
tokenAssetCode: input.sendTokenId || "", | ||
tokenValue: input.sendAmount?.toString() || "", | ||
}); | ||
const link = `https://app.zerion.io/send?${urlParams.toString()}`; | ||
try { | ||
await open(link); | ||
} catch (error) { | ||
await handleError({ title: "Failed to open Zerion Send Form", error }); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.