-
Notifications
You must be signed in to change notification settings - Fork 387
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
[SDK] Add 2 new Pay functions: convertFiatToCrypto and convertCryptoToFiat #5457
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🦋 Changeset detectedLatest commit: 07afcee The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Your org has enabled the Graphite merge queue for merging into mainAdd the label “merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
size-limit report 📦
|
a613e2e
to
980e2d3
Compare
980e2d3
to
d99b778
Compare
d99b778
to
b14876f
Compare
7f86530
to
0e1f12a
Compare
* The fiat symbol. e.g "usd" | ||
* Only USD is supported at the moment. | ||
*/ | ||
to: "usd"; |
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.
is it usd lowecase or USD uppercase? I see different casing used in the comments / tests
for a currency I think it should be uppercase everywhere
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.
Updated to uppercase (although it's not case sensitive in the backend)
0e1f12a
to
dcd6b94
Compare
dcd6b94
to
07afcee
Compare
// so we should do some basic input validations before sending the request | ||
|
||
// Make sure it's a valid EVM address | ||
if (!isAddress(fromTokenAddress)) { | ||
throw new Error( | ||
"Invalid fromTokenAddress. Expected a valid EVM contract address", | ||
); | ||
} | ||
// Make sure it's either a valid contract or a native token address | ||
if (fromTokenAddress.toLowerCase() !== NATIVE_TOKEN_ADDRESS.toLowerCase()) { | ||
const bytecode = await getBytecode( | ||
getContract({ | ||
address: fromTokenAddress, | ||
chain, | ||
client, | ||
}), | ||
).catch(() => undefined); | ||
if (!bytecode || bytecode === "0x") { | ||
throw new Error( | ||
`Error: ${fromTokenAddress} on chainId: ${chain.id} is not a valid contract address.`, |
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.
The contract validation logic could be extracted to a shared utility function used by both conversion files to reduce duplication
Spotted by Graphite Reviewer (based on CI logs)
Is this helpful? React 👍 or 👎 to let us know.
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 maybe
CNCT-2369
Problem solved
Short description of the bug fixed or feature added
PR-Codex overview
This PR introduces two new payment functions:
convertFiatToCrypto
andconvertCryptoToFiat
, along with their respective tests. These functions facilitate the conversion between fiat currency and cryptocurrency.Detailed summary
convertFiatToCrypto
function infiatToCrypto.ts
.convertCryptoToFiat
function incryptoToFiat.ts
.definitions.ts
.convertFiatToCrypto
infiatToCrypto.test.ts
.convertCryptoToFiat
incryptoToFiat.test.ts
.