Skip to content

Commit c9f1a1c

Browse files
authored
chore: support 'near-testnet' aside 'aurora-testnet' (#956)
1 parent 3de8a78 commit c9f1a1c

File tree

14 files changed

+33
-11
lines changed

14 files changed

+33
-11
lines changed

packages/advanced-logic/src/extensions/payment-network/any-to-near.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { UnsupportedNetworkError } from './address-based';
44
import AnyToNativeTokenPaymentNetwork from './any-to-native';
55

66
const CURRENT_VERSION = '0.1.0';
7-
const supportedNetworks = ['aurora', 'aurora-testnet'];
7+
const supportedNetworks = ['aurora', 'aurora-testnet', 'near-testnet'];
88

99
export default class AnyToNearPaymentNetwork extends AnyToNativeTokenPaymentNetwork {
1010
public constructor(
@@ -26,6 +26,7 @@ export default class AnyToNearPaymentNetwork extends AnyToNativeTokenPaymentNetw
2626
case 'aurora':
2727
return this.isValidMainnetAddress(address);
2828
case 'aurora-testnet':
29+
case 'near-testnet':
2930
return this.isValidTestnetAddress(address);
3031
case undefined:
3132
return this.isValidMainnetAddress(address) || this.isValidTestnetAddress(address);

packages/advanced-logic/src/extensions/payment-network/near-native.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { UnsupportedNetworkError } from './address-based';
33
import NativeTokenPaymentNetwork from './native-token';
44

55
const CURRENT_VERSION = '0.2.0';
6-
const supportedNetworks = ['aurora', 'aurora-testnet'];
6+
const supportedNetworks = ['aurora', 'aurora-testnet', 'near-testnet'];
77

88
/**
99
* Implementation of the payment network to pay in Near based on input data.
@@ -27,6 +27,7 @@ export default class NearNativePaymentNetwork extends NativeTokenPaymentNetwork
2727
case 'aurora':
2828
return this.isValidMainnetAddress(address);
2929
case 'aurora-testnet':
30+
case 'near-testnet':
3031
return this.isValidTestnetAddress(address);
3132
case undefined:
3233
return this.isValidMainnetAddress(address) || this.isValidTestnetAddress(address);

packages/advanced-logic/test/extensions/payment-network/any-to-near.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ describe('extensions/payment-network/any-to-native-token', () => {
186186
network: 'another-chain',
187187
});
188188
}).toThrowError(
189-
`Payment network 'another-chain' is not supported by this extension (only aurora, aurora-testnet)`,
189+
`Payment network 'another-chain' is not supported by this extension (only aurora, aurora-testnet, near-testnet)`,
190190
);
191191
});
192192
it('throws when payment network is missing', () => {

packages/advanced-logic/test/extensions/payment-network/native-token.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ describe('extensions/payment-network/native-token', () => {
136136
paymentNetworkName: 'another-chain',
137137
});
138138
}).toThrowError(
139-
`Payment network 'another-chain' is not supported by this extension (only aurora, aurora-testnet)`,
139+
`Payment network 'another-chain' is not supported by this extension (only aurora, aurora-testnet, near-testnet)`,
140140
);
141141
});
142142
it('createCreationAction() throws without payment network', () => {

packages/currency/src/conversion-aggregators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const chainlinkCurrencyPairs: AggregatorsMap = {
3636
const fluxCurrencyPairs: AggregatorsMap = {
3737
aurora: nearAggregator,
3838
'aurora-testnet': nearTestnetAggregator,
39+
'near-testnet': nearTestnetAggregator,
3940
};
4041

4142
// FIX ME: This fix enables to get these networks registered in conversionSupportedNetworks.

packages/currency/src/currency-utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { RequestLogicTypes } from '@requestnetwork/types';
1313
*/
1414
export const isValidNearAddress = (address: string, network?: string): boolean => {
1515
if (!network) {
16-
return isValidNearAddress(address, 'aurora') || isValidNearAddress(address, 'aurora-testnet');
16+
return (
17+
isValidNearAddress(address, 'aurora') ||
18+
isValidNearAddress(address, 'aurora-testnet') ||
19+
isValidNearAddress(address, 'near-testnet')
20+
);
1721
}
1822
// see link bellow for NEAR address specification
1923
// https://nomicon.io/DataStructures/Account.html
@@ -35,6 +39,7 @@ export const isValidNearAddress = (address: string, network?: string): boolean =
3539
case 'aurora':
3640
return !!address.match(/\.near$/);
3741
case 'aurora-testnet':
42+
case 'near-testnet':
3843
return !!address.match(/\.testnet$/);
3944
default:
4045
throw new Error(`Cannot validate NEAR address for network ${network}`);

packages/payment-detection/src/eth/multichainExplorerApiProvider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class MultichainExplorerApiProvider extends ethers.providers.EtherscanPro
4646
case 'aurora':
4747
return 'https://explorer.mainnet.near.org';
4848
case 'aurora-testnet':
49+
case 'near-testnet':
4950
return 'https://explorer.testnet.near.org';
5051
case 'arbitrum-rinkeby':
5152
return 'https://testnet.arbiscan.io/';

packages/payment-detection/src/near/near-conversion-detector.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ export class NearConversionNativeTokenPaymentDetector extends AnyToAnyDetector<
5151
'aurora-testnet': {
5252
'0.1.0': 'native.conversion.reqnetwork.testnet',
5353
},
54+
'near-testnet': {
55+
'0.1.0': 'native.conversion.reqnetwork.testnet',
56+
},
5457
};
5558
if (versionMap[chainName]?.[version]) {
5659
return versionMap[chainName][version];

packages/payment-detection/src/near/near-detector.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class NearNativeTokenPaymentDetector extends ReferenceBasedDetector<
4141
'0.1.0': 'dev-1626339335241-5544297',
4242
'0.2.0': 'dev-1631521265288-35171138540673',
4343
},
44+
'near-testnet': {
45+
'0.1.0': 'dev-1626339335241-5544297',
46+
'0.2.0': 'dev-1631521265288-35171138540673',
47+
},
4448
};
4549
if (versionMap[chainName]?.[version]) {
4650
return versionMap[chainName][version];

packages/payment-detection/src/near/retrievers/near-info-retriever.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class NearInfoRetriever {
2525
protected eventName: PaymentTypes.EVENTS_NAMES,
2626
network: string,
2727
) {
28-
if (network !== 'aurora' && network !== 'aurora-testnet') {
28+
if (network !== 'aurora' && network !== 'aurora-testnet' && network !== 'near-testnet') {
2929
throw new Error('Near input data info-retriever only works with Near mainnet and testnet');
3030
}
3131

0 commit comments

Comments
 (0)