Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 91
feat(processor): any-declarative payment in NEAR#1428
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { BigNumberish } from 'ethers'; | ||
| import { WalletConnection } from 'near-api-js'; | ||
| import { CurrencyTypes } from '@requestnetwork/types'; | ||
| import { INearTransactionCallback, processNearPayment } from './utils-near'; | ||
| import { NearChains } from '@requestnetwork/currency'; | ||
| /** | ||
| * Processes a transaction to make a payment in NEAR token with a reference. | ||
| * | ||
| * @notice This is used to pay a declarative request, with low-level arguments. | ||
| * | ||
| * @param paymentAddress must be a valid NEAR address on the given network. | ||
| * @param network e.g. 'near' | ||
| * @param paymentReference used to index payments. | ||
| * @param walletConnection the Near provider. | ||
| * @param amount amount to pay, in NEAR tokens. | ||
| */ | ||
| // FIXME: We could improve the method's interface by enforcing a type on `paymentInfo` for declarative requests. | ||
| export async function payNearAmountWithReference( | ||
| paymentAddress: string, | ||
| paymentReference: string, | ||
| network: CurrencyTypes.NearChainName, | ||
| walletConnection: WalletConnection, | ||
| amount: BigNumberish, | ||
| callback?: INearTransactionCallback, | ||
| ): Promise<void> { | ||
| NearChains.assertChainSupported(network); | ||
| return processNearPayment( | ||
| walletConnection, | ||
| network, | ||
| amount, | ||
| paymentAddress, | ||
| paymentReference, | ||
| '0.2.0', | ||
| callback, | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -12,12 +12,13 @@ import { | ||
| import { INearTransactionCallback, processNearPaymentWithConversion } from './utils-near'; | ||
| import { IConversionPaymentSettings } from '.'; | ||
| import { CurrencyManager, NearChains, UnsupportedCurrencyError } from '@requestnetwork/currency'; | ||
| import { validatePaymentReference } from '../utils/validation'; | ||
| /** | ||
| * Processes the transaction to pay a request in NEAR with on-chain conversion. | ||
| * @param request the request to pay | ||
| * @param walletConnection the Web3 provider, or signer. Defaults to window.ethereum. | ||
| * @param amount optionally, the amount to pay. Defaults to remaining amount of the request. | ||
| * @param walletConnection the Near provider. | ||
| * @param amount optionally, the amount to pay in request currency. Defaults to remaining amount of the request. | ||
Comment on lines
+20
to
+21
| ||
| */ | ||
| export async function payNearConversionRequest( | ||
| request: ClientTypes.IRequestData, | ||
| @@ -37,13 +38,7 @@ export async function payNearConversionRequest( | ||
| throw new UnsupportedCurrencyError(request.currencyInfo); | ||
| } | ||
| if (!paymentReference) { | ||
| throw new Error('Cannot pay without a paymentReference'); | ||
| } | ||
| if (!network || !NearChains.isChainSupported(network)) { | ||
| throw new Error('Should be a Near network'); | ||
| } | ||
yomarion marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| validatePaymentReference(paymentReference); | ||
| NearChains.assertChainSupported(network); | ||
| const amountToPay = getAmountToPay(request, amount).toString(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| /** Validates the presence of the payment reference for payment. */ | ||
| export function validatePaymentReference( | ||
| paymentReference?: string, | ||
| ): asserts paymentReference is string { | ||
| if (!paymentReference) { | ||
| throw new Error('Cannot pay without a paymentReference'); | ||
| } | ||
| } |
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.
Documentation is clear and helpful.
The function documentation provides a clear description of the function's purpose and parameters.
Offer assistance for FIXME comment.
The FIXME comment suggests improving the method's interface by enforcing a type on
paymentInfo.Would you like me to help enforce a type on
paymentInfofor declarative requests?