@@ -28,11 +28,7 @@ import "./index.scss";
28
28
import { useCallback } from "react" ;
29
29
import { useDispatch } from "react-redux" ;
30
30
import { showModal } from "src/reducers/modalSlice" ;
31
- import {
32
- Address ,
33
- BaseAddress ,
34
- RewardAddress ,
35
- } from "@emurgo/cardano-serialization-lib-asmjs" ;
31
+ import { getStakeKey } from "./utils/common.function" ;
36
32
37
33
let Buffer = require ( "buffer" ) . Buffer ;
38
34
@@ -84,28 +80,8 @@ function Rewards({ connectedWallet, wrongNetwork }: Params) {
84
80
* we want the stake address
85
81
* if it is cardano address, get the staking address
86
82
*/
87
-
88
- let address = searchAddress ;
89
-
90
- if ( searchAddress . includes ( "addr" ) ) {
91
- const addressObject = Address . from_bech32 ( searchAddress ) ;
92
- const stakeAddress =
93
- BaseAddress . from_address ( addressObject ) ;
94
- let rewardAddressBytes = new Uint8Array ( 29 ) ;
95
- rewardAddressBytes . set ( [ 0xe0 ] , 0 ) ;
96
-
97
- if ( stakeAddress == null ) return ;
98
- rewardAddressBytes . set (
99
- stakeAddress . stake_cred ( ) . to_bytes ( ) . slice ( 4 , 32 ) ,
100
- 1
101
- ) ;
102
- let rewardAddress = RewardAddress . from_address (
103
- Address . from_bytes ( rewardAddressBytes )
104
- ) ;
105
-
106
- if ( rewardAddress == null ) return ;
107
- address = rewardAddress ?. to_address ( ) . to_bech32 ( ) ;
108
- }
83
+ let address = getStakeKey ( searchAddress ) ;
84
+ if ( address == null ) throw new Error ( ) ;
109
85
110
86
const rewards = await getRewards ( address ) ;
111
87
@@ -125,14 +101,16 @@ function Rewards({ connectedWallet, wrongNetwork }: Params) {
125
101
setRewardsLoader ( false ) ;
126
102
}
127
103
} catch ( ex : any ) {
128
- if ( ex ?. response ?. status === 404 ) {
129
- dispatch (
130
- showModal ( {
131
- text : "Account not found." ,
132
- type : ModalTypes . info ,
133
- } )
134
- ) ;
135
- setRewardsLoader ( false ) ;
104
+ switch ( true ) {
105
+ case ex ?. response ?. status === 404 :
106
+ default :
107
+ dispatch (
108
+ showModal ( {
109
+ text : "Account not found." ,
110
+ type : ModalTypes . info ,
111
+ } )
112
+ ) ;
113
+ setRewardsLoader ( false ) ;
136
114
}
137
115
}
138
116
}
0 commit comments