-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(processor): any-declarative payment in NEAR (#1428)
- Loading branch information
Showing
8 changed files
with
68 additions
and
32 deletions.
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
40 changes: 40 additions & 0 deletions
40
packages/payment-processor/src/payment/near-amount-with-ref.ts
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,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, | ||
); | ||
} |
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
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,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'); | ||
} | ||
} |
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