Skip to content
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

refactor: disable signature requirement for refresh actions #314

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@
import { useTranslation } from "react-i18next";
import { IconButton } from "@/Components/Buttons";
import { Tooltip } from "@/Components/Tooltip";
import { useAuthorizedAction } from "@/Hooks/useAuthorizedAction";
import { useToasts } from "@/Hooks/useToasts";
import { isTruthy } from "@/Utils/is-truthy";

export const RefreshButton = ({ wallet }: { wallet: App.Data.Wallet.WalletData | null }): JSX.Element => {
const [loading, setLoading] = useState(false);
const [disabled, setDisabled] = useState(false);
const { t } = useTranslation();

const { signedAction } = useAuthorizedAction();
const { showToast } = useToasts();

const refresh = (): void => {
void signedAction(async () => {
setLoading(true);
setDisabled(true);

await window.axios.post(route("refresh-collections"));
window.axios.post(route("refresh-collections"));

Check failure on line 17 in resources/js/Pages/Collections/Components/CollectionsHeading/RefreshButton.tsx

View workflow job for this annotation

GitHub Actions / eslint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

setLoading(false);
setDisabled(true);

showToast({
type: "pending",
message: t("pages.collections.refresh.toast"),
isExpanded: true,
});
showToast({
type: "pending",
message: t("pages.collections.refresh.toast"),
isExpanded: true,
});
};

Expand Down Expand Up @@ -60,7 +52,6 @@
disabled={
isTruthy(wallet?.isRefreshingCollections) ||
!isTruthy(wallet?.canRefreshCollections) ||
loading ||
disabled
}
type="button"
Expand Down
28 changes: 12 additions & 16 deletions resources/js/Pages/Collections/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import { EmptyBlock } from "@/Components/EmptyBlock/EmptyBlock";
import { SearchInput } from "@/Components/Form/SearchInput";
import { ExternalLinkContextProvider } from "@/Contexts/ExternalLinkContext";
import { useAuthorizedAction } from "@/Hooks/useAuthorizedAction";
import { useToasts } from "@/Hooks/useToasts";
import { useWalletActivity } from "@/Hooks/useWalletActivity";
import { DefaultLayout } from "@/Layouts/DefaultLayout";
Expand Down Expand Up @@ -84,7 +83,6 @@

const [showCollectionFilterSlider, setShowCollectionFilterSlider] = useState(false);
const { requestActivityUpdate } = useWalletActivity();
const { signedAction } = useAuthorizedAction();

const { showToast } = useToasts();

Expand Down Expand Up @@ -266,21 +264,19 @@
};

const handleRefreshActivity = (): void => {
void signedAction(async () => {
setIsLoadingActivity(true);
requestActivityUpdate(collection.address);
crnkovic marked this conversation as resolved.
Show resolved Hide resolved

showToast({
message: t("common.refreshing_activity"),
isExpanded: true,
});

await axios.post<{ success: boolean }>(
route("collection.refresh-activity", {
collection: collection.slug,
}),
);
setIsLoadingActivity(true);
requestActivityUpdate(collection.address);

showToast({
message: t("common.refreshing_activity"),
isExpanded: true,
});

axios.post(

Check failure on line 275 in resources/js/Pages/Collections/View.tsx

View workflow job for this annotation

GitHub Actions / eslint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
route("collection.refresh-activity", {
collection: collection.slug,
}),
);
};

return (
Expand Down
4 changes: 1 addition & 3 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
Route::get('/tokens/breakdown', [Controllers\TokenController::class, 'breakdown'])->name('tokens.breakdown');
Route::get('/tokens/search', [Controllers\TokenController::class, 'searchTokens'])->name('tokens.search');

Route::post('/refreshed-collections', [Controllers\RefreshedCollectionController::class, 'store'])
->name('refresh-collections')
->middleware('signed_wallet');
Route::post('/refreshed-collections', [Controllers\RefreshedCollectionController::class, 'store'])->name('refresh-collections');

Route::post('/transaction-success', Controllers\TransactionSuccessController::class)
->name('transaction-success');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Jobs\RefreshWalletCollections;
use App\Models\Nft;
use App\Support\Facades\Signature;
use Illuminate\Support\Facades\Bus;

it('can dispatch jobs to refresh all collections for a wallet', function () {
Expand All @@ -15,8 +14,6 @@
'onboarded_at' => now(),
]);

Signature::setWalletIsSigned($user->wallet->id);

Nft::factory()->for($user->wallet)->create();
Nft::factory()->for($user->wallet)->create();

Expand Down
Loading