-
Notifications
You must be signed in to change notification settings - Fork 545
refactor: use NetworkID
in faucet calculations
#2950
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
Changes from 4 commits
2debdf7
38d335e
3f0e6a1
dcf566b
204cb26
fa0d8ee
194ff00
6fc5b04
6c575b5
9b749bd
2fe57e5
134f320
6c4a315
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,11 +16,16 @@ export enum FaucetNetwork { | |||||
Devnet = 'faucet.devnet.rippletest.net', | ||||||
} | ||||||
|
||||||
export const FaucetNetworkPaths: Record<string, string> = { | ||||||
export const faucetNetworkPaths: Record<string, string> = { | ||||||
[FaucetNetwork.Testnet]: '/accounts', | ||||||
[FaucetNetwork.Devnet]: '/accounts', | ||||||
} | ||||||
|
||||||
export const faucetNetworkIDs: Map<number, FaucetNetwork> = new Map([ | ||||||
[1, FaucetNetwork.Testnet], | ||||||
[2, FaucetNetwork.Devnet], | ||||||
]) | ||||||
|
||||||
/** | ||||||
* Get the faucet host based on the Client connection. | ||||||
* | ||||||
|
@@ -31,19 +36,19 @@ export const FaucetNetworkPaths: Record<string, string> = { | |||||
export function getFaucetHost(client: Client): FaucetNetwork | undefined { | ||||||
const connectionUrl = client.url | ||||||
|
||||||
// 'altnet' for Ripple Testnet server and 'testnet' for XRPL Labs Testnet server | ||||||
if (connectionUrl.includes('altnet') || connectionUrl.includes('testnet')) { | ||||||
return FaucetNetwork.Testnet | ||||||
} | ||||||
|
||||||
if (connectionUrl.includes('sidechain-net2')) { | ||||||
ckeshava marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if (client.networkID == null) { | ||||||
throw new XRPLFaucetError( | ||||||
'Cannot fund an account on an issuing chain. Accounts must be created via the bridge.', | ||||||
'Cannot create faucet URL without networkID or the faucet_host information', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you want to remove the extra clause? If someone provides the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How will There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, but the error is more reasonable from a user perspective, who is never directly calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the relevance of They will need to go through XRPL documentation about I don't feel too strongly about it. However, the error message is not intuitive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you read through all the options on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I had not. |
||||||
) | ||||||
} | ||||||
|
||||||
if (connectionUrl.includes('devnet')) { | ||||||
return FaucetNetwork.Devnet | ||||||
if (faucetNetworkIDs.has(client.networkID)) { | ||||||
return faucetNetworkIDs.get(client.networkID) | ||||||
} | ||||||
|
||||||
// 'altnet' for Ripple Testnet server and 'testnet' for XRPL Labs Testnet server | ||||||
if (connectionUrl.includes('altnet') || connectionUrl.includes('testnet')) { | ||||||
return FaucetNetwork.Testnet | ||||||
} | ||||||
|
||||||
throw new XRPLFaucetError('Faucet URL is not defined or inferrable.') | ||||||
|
@@ -54,11 +59,11 @@ export function getFaucetHost(client: Client): FaucetNetwork | undefined { | |||||
* | ||||||
* @param hostname - hostname. | ||||||
* @returns A String with the correct path for the input hostname. | ||||||
* If hostname undefined or cannot find (key, value) pair in {@link FaucetNetworkPaths}, defaults to '/accounts' | ||||||
* If hostname undefined or cannot find (key, value) pair in {@link faucetNetworkPaths}, defaults to '/accounts' | ||||||
*/ | ||||||
export function getDefaultFaucetPath(hostname: string | undefined): string { | ||||||
export function getFaucetPath(hostname: string | undefined): string { | ||||||
if (hostname === undefined) { | ||||||
return '/accounts' | ||||||
} | ||||||
return FaucetNetworkPaths[hostname] || '/accounts' | ||||||
return faucetNetworkPaths[hostname] || '/accounts' | ||||||
} |
Uh oh!
There was an error while loading. Please reload this page.