Skip to content

Commit

Permalink
feat: add staking toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
emccorson committed Jun 23, 2023
1 parent 832008f commit 4b2fa45
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions apps/namada-interface/src/slices/StakingAndGovernance/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import { myStakingData } from "./fakeData";
import { RootState } from "store";
import { Account } from "slices/accounts";

import { getToast, Toasts } from "slices/transfers";
import { actions as notificationsActions } from "slices/notifications";

const toValidator = ([address, votingPower]: [string, string]): Validator => ({
uuid: address,
name: address,
Expand Down Expand Up @@ -173,18 +176,45 @@ export const postNewBonding = createAsyncThunk<
const { chainId } = thunkApi.getState().settings;
const integration = getIntegration(chainId);
const signer = integration.signer() as Signer;
await signer.submitBond({
source: change.owner,
validator: change.validatorId,
amount: amountToMicro(new BigNumber(change.amount)),
nativeToken: Tokens.NAM.address || "",
tx: {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
gasLimit: new BigNumber(0),
chainId,
},
});

const toastId = `${thunkApi.requestId}-transfer`;

thunkApi.dispatch(
notificationsActions.createToast(
getToast(toastId, Toasts.TransferStarted)({
msgId: "Staking..."
})
)
);

let success = true;
try {
await signer.submitBond({
source: change.owner,
validator: change.validatorId,
amount: amountToMicro(new BigNumber(change.amount)),
nativeToken: Tokens.NAM.address || "",
tx: {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
gasLimit: new BigNumber(0),
chainId,
},
});
} catch (e) {
success = false;
}

thunkApi.dispatch(
notificationsActions.createToast(
getToast(toastId, Toasts.TransferCompleted)({
success,
msgId: success
? "Staking completed"
: "Staking did not complete"
})
)
);
});

// we post an unstake transaction
Expand Down

0 comments on commit 4b2fa45

Please sign in to comment.