Skip to content

Commit

Permalink
fix(authz): fix error while creating authz (#1214)
Browse files Browse the repository at this point in the history
fix: fix authz

Co-authored-by: chary <57086313+charymalloju@users.noreply.github.com>
  • Loading branch information
Hemanthghs and charymalloju authored Apr 8, 2024
1 parent 80559d6 commit 7c88798
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions frontend/src/store/features/authz/authzSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,20 +388,21 @@ export const authzSlice = createSlice({
const addressMapping: Record<string, Authorization[]> = {};
const allChainsAddressToGrants = state.AddressToChainAuthz;

grants && grants.forEach((grant: Authorization) => {
const granter = grant.granter;
const cosmosAddress = getAddressByPrefix(granter, 'cosmos');
if (!addressMapping[granter]) addressMapping[granter] = [];
if (!allChainsAddressToGrants[cosmosAddress])
allChainsAddressToGrants[cosmosAddress] = {};
if (!allChainsAddressToGrants[cosmosAddress][chainID])
allChainsAddressToGrants[cosmosAddress][chainID] = [];
allChainsAddressToGrants[cosmosAddress][chainID] = [
...allChainsAddressToGrants[cosmosAddress][chainID],
grant,
];
addressMapping[granter] = [...addressMapping[granter], grant];
});
grants &&
grants.forEach((grant: Authorization) => {
const granter = grant.granter;
const cosmosAddress = getAddressByPrefix(granter, 'cosmos');
if (!addressMapping[granter]) addressMapping[granter] = [];
if (!allChainsAddressToGrants[cosmosAddress])
allChainsAddressToGrants[cosmosAddress] = {};
if (!allChainsAddressToGrants[cosmosAddress][chainID])
allChainsAddressToGrants[cosmosAddress][chainID] = [];
allChainsAddressToGrants[cosmosAddress][chainID] = [
...allChainsAddressToGrants[cosmosAddress][chainID],
grant,
];
addressMapping[granter] = [...addressMapping[granter], grant];
});
state.AddressToChainAuthz = allChainsAddressToGrants;
state.chains[chainID].GrantsToMeAddressMapping = addressMapping;
state.chains[chainID].getGrantsToMeLoading = {
Expand Down Expand Up @@ -461,6 +462,8 @@ export const authzSlice = createSlice({
builder
.addCase(txAuthzExec.pending, (state, action) => {
const chainID = action.meta.arg.basicChainInfo.chainID;
if (!state.chains[chainID])
state.chains[chainID] = cloneDeep(defaultState);
const actionType = action.meta.arg.type;
state.chains[chainID].tx.status = TxStatus.PENDING;
state.chains[chainID].tx.errMsg = '';
Expand All @@ -480,6 +483,8 @@ export const authzSlice = createSlice({
builder
.addCase(txCreateAuthzGrant.pending, (state, action) => {
const { chainID } = action.meta.arg.basicChainInfo;
if (!state.chains[chainID])
state.chains[chainID] = cloneDeep(defaultState);
state.chains[chainID].tx.status = TxStatus.PENDING;
state.chains[chainID].tx.errMsg = '';
})
Expand Down Expand Up @@ -519,6 +524,8 @@ export const authzSlice = createSlice({
builder
.addCase(txAuthzRevoke.pending, (state, action) => {
const chainID = action.meta.arg.basicChainInfo.chainID;
if (!state.chains[chainID])
state.chains[chainID] = cloneDeep(defaultState);
state.chains[chainID].tx.status = TxStatus.PENDING;
state.chains[chainID].tx.errMsg = '';
})
Expand Down

0 comments on commit 7c88798

Please sign in to comment.