Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Add testnet faucet #717

Merged
merged 13 commits into from
Jun 6, 2023
Merged

Add testnet faucet #717

merged 13 commits into from
Jun 6, 2023

Conversation

mvaivre
Copy link
Member

@mvaivre mvaivre commented May 19, 2023

Fixes #690 and #718

@mvaivre mvaivre changed the title [WIP] Faucet Add testnet faucet May 19, 2023
@nop33
Copy link
Member

nop33 commented May 23, 2023

Ready for review?

@mvaivre mvaivre requested a review from nop33 May 23, 2023 09:18
Copy link
Member

@nop33 nop33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really cool feature!!

When I clicked "Receive testnet tokens", it took a couple of seconds without any visual feedback until a success snackbar popped up. I think we can improve this with a loading state, or at least a snackbar that says "tokens requested" or sth.

Secondly, after the success message, I don't see any transactions in my transaction history. I tried refreshing and there's still nothing. Then after refreshing 2 minutes later, I could see the tokens. I did not have enough time to read the success message, maybe we can leave it open a bit longer. Moreover, since we are expecting an incoming transaction, we should refresh the data automatically, same way we refresh them with an interval when sending a tx. WDYT?

Lastly, we could improve the error handling (in the future, no need for now) when the user reaches the quota (not sure how many minutes it is). Currently it shows "Encountered error, please try again in a few minutes", but it could say "you reached the limit, try again in X minutes" or sth like that.

src/storage/assets/assetsActions.ts Outdated Show resolved Hide resolved
@mvaivre
Copy link
Member Author

mvaivre commented May 23, 2023

Yes, you saw #718 😆 I'm not happy with the current flow either, it's hard to really see that something happened. That's why I wasn't really sure if this PR was actually ready, but it's always good to get a first review.

A button spinner + fetching incoming transactions would help a lot.

I did not have enough time to read the success message, maybe we can leave it open a bit longer. Moreover, since we are expecting an incoming transaction, we should refresh the data automatically, same way we refresh them with an interval when sending a tx. WDYT?

In the meantime, this could help 💯

@mvaivre
Copy link
Member Author

mvaivre commented Jun 1, 2023

I've improved the flow by adding a "pending" state indicator.

Regarding the continuous loading of the incoming TX, I think that I'd be in favour of implementing alephium/alephium-frontend#74 directly (thus replacing our current "fake" pending TXs system altogether). You're the master of our redux state, so WDYT? :)

Note: there was a newline at the end of the testnet call response.
This made the regex and my brain useless for a little while.
@mvaivre
Copy link
Member Author

mvaivre commented Jun 2, 2023

So, it took me some time to get in the code, and this work will eventually be replaced by fetching the mempool data directly, but it's now showing incoming faucet TXs using your system.

@mvaivre mvaivre requested a review from nop33 June 2, 2023 11:10
Copy link
Member

@nop33 nop33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the displayed ALPH amount of the faucet pending incoming tx is 0.00 ALPH. Maybe we could improve this to display nothing instead since we don't know the amount (just like we do on sweep transactions where we don't know the exact amount)?

@@ -87,6 +89,11 @@ const DevToolsSettingsSection = () => {
setSelectedAddress(undefined)
}

const handleFaucetCall = () => {
defaultAddress && dispatch(receiveTestnetTokens(defaultAddress?.hash))
posthog?.capture('Testnet faucet call')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would rename this to Requested testnet tokens to match better the namings of the rest of our analytics/

const fromAddress = state.entities[pendingTransaction.fromAddress] as Address
const toAddress = state.entities[pendingTransaction.toAddress] as Address

;(fromAddress || toAddress).transactions.push(pendingTransaction.hash)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about this syntax?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if fromAddress is falsy and toAddress isn't, then toAddresss.transactions.push(pendingTransaction.hash) gets called twice, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should ensure that toAddresss.transactions.push(pendingTransaction.hash) gets called only once and also avoids the weird syntax.

if (fromAddress) fromAddress.transactions.push(pendingTransaction.hash)
if (toAddress && toAddress !== fromAddress) toAddress.transactions.push(pendingTransaction.hash)

src/storage/addresses/addressesSlice.ts Show resolved Hide resolved
src/storage/settings/settingsActions.ts Outdated Show resolved Hide resolved

const settingsSlice = createSlice({
name: 'settings',
initialState,
reducers: {},
extraReducers(builder) {
builder
.addCase(localStorageDataMigrated, () => SettingsStorage.load('general') as GeneralSettings)
.addCase(localStorageDataMigrated, () => SettingsStorage.load('general') as SettingsState)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why this change? The type of the data loaded is GeneralSettings. faucetCallPending is not stored there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because otherwise the compiler will complain, as addCase gets the expected type from initialState.
But this will be solved if I move faucetCallPending to the globalSlice as you proposed below.

src/storage/settings/settingsSlice.ts Outdated Show resolved Hide resolved
@mvaivre mvaivre requested a review from nop33 June 5, 2023 10:23
Copy link
Member

@nop33 nop33 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful! ✨

@mvaivre mvaivre merged commit 68dbb0a into next Jun 6, 2023
@mvaivre mvaivre deleted the faucet branch June 6, 2023 12:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add testnet faucet
2 participants