Skip to content

Commit

Permalink
bridge_ui: safely set target chain in recovery
Browse files Browse the repository at this point in the history
Change-Id: I7d6e03b56b61129d72ef641059871ff362a3f0f4
  • Loading branch information
evan-gray committed Oct 28, 2021
1 parent a956e57 commit 4c85daa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
8 changes: 0 additions & 8 deletions bridge_ui/src/components/Recovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,6 @@ export default function Recovery() {
fullWidth
margin="normal"
/>
<TextField
variant="outlined"
label="Target Chain"
disabled
value={parsedPayload?.targetChain.toString() || ""}
fullWidth
margin="normal"
/>
<TextField
variant="outlined"
label="Target Address"
Expand Down
6 changes: 6 additions & 0 deletions bridge_ui/src/store/nftSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,14 @@ export const nftSlice = createSlice({
};
}>
) => {
const prevTargetChain = state.targetChain;
state.signedVAAHex = action.payload.vaa;
state.targetChain = action.payload.parsedPayload.targetChain;
if (state.sourceChain === action.payload.parsedPayload.targetChain) {
state.sourceChain = prevTargetChain;
state.sourceParsedTokenAccount = undefined;
state.sourceParsedTokenAccounts = getEmptyDataWrapper();
}
state.targetAddressHex = action.payload.parsedPayload.targetAddress;
state.originChain = action.payload.parsedPayload.originChain;
state.originAsset = action.payload.parsedPayload.originAddress;
Expand Down
6 changes: 6 additions & 0 deletions bridge_ui/src/store/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ export const selectNFTTargetError = (state: RootState) => {
if (!state.nft.targetChain) {
return "Select a target chain";
}
if (state.nft.sourceChain === state.nft.targetChain) {
return "Select a different target and source";
}
if (state.nft.targetChain === CHAIN_ID_SOLANA && !state.nft.targetAsset) {
// target asset is only required for solana
// in the cases of new transfers, target asset will not exist and be created on redeem
Expand Down Expand Up @@ -256,6 +259,9 @@ export const selectTransferTargetError = (state: RootState) => {
if (!state.transfer.targetChain) {
return "Select a target chain";
}
if (state.transfer.sourceChain === state.transfer.targetChain) {
return "Select a different target and source";
}
if (!state.transfer.targetAsset) {
return UNREGISTERED_ERROR_MESSAGE;
}
Expand Down
6 changes: 6 additions & 0 deletions bridge_ui/src/store/transferSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,14 @@ export const transferSlice = createSlice({
};
}>
) => {
const prevTargetChain = state.targetChain;
state.signedVAAHex = action.payload.vaa;
state.targetChain = action.payload.parsedPayload.targetChain;
if (state.sourceChain === action.payload.parsedPayload.targetChain) {
state.sourceChain = prevTargetChain;
state.sourceParsedTokenAccount = undefined;
state.sourceParsedTokenAccounts = getEmptyDataWrapper();
}
state.targetAddressHex = action.payload.parsedPayload.targetAddress;
state.originChain = action.payload.parsedPayload.originChain;
state.originAsset = action.payload.parsedPayload.originAddress;
Expand Down

0 comments on commit 4c85daa

Please sign in to comment.