Skip to content

Commit

Permalink
refactor: disable signature requirement for refresh actions (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
crnkovic authored Oct 31, 2023
1 parent 0dec26e commit 13e87ff
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ 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 { authenticatedAction } = useAuthorizedAction();
const { showToast } = useToasts();

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

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

setLoading(false);
void authenticatedAction((): void => {
setDisabled(true);

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

showToast({
type: "pending",
message: t("pages.collections.refresh.toast"),
Expand Down Expand Up @@ -60,7 +56,6 @@ export const RefreshButton = ({ wallet }: { wallet: App.Data.Wallet.WalletData |
disabled={
isTruthy(wallet?.isRefreshingCollections) ||
!isTruthy(wallet?.canRefreshCollections) ||
loading ||
disabled
}
type="button"
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Pages/Collections/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ const CollectionsView = ({

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

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

const hasSelectedTraits = useMemo(
Expand Down Expand Up @@ -266,7 +266,7 @@ const CollectionsView = ({
};

const handleRefreshActivity = (): void => {
void signedAction(async () => {
void authenticatedAction((): void => {
setIsLoadingActivity(true);
requestActivityUpdate(collection.address);

Expand All @@ -275,7 +275,7 @@ const CollectionsView = ({
isExpanded: true,
});

await axios.post<{ success: boolean }>(
void axios.post(
route("collection.refresh-activity", {
collection: collection.slug,
}),
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

0 comments on commit 13e87ff

Please sign in to comment.