Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handler for address change - reset state, add unfinished to history #285

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/components/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,23 @@ export default function History(props: { size?: interfaces.SimplifiedSize }) {
<p
className={cls(
cmn.p,
[cmn.p3, size == 'sm'],
[cmn.p2, size == 'md'],
[cmn.p3, size === 'sm'],
[cmn.p2, size === 'md'],
cmn.p600,
cmn.cap,
cmn.pPrim,
cmn.mleft5,
cmn.flexg
)}
>
•{' '}
{transfer.address.substring(0, 6) +
'...' +
transfer.address.substring(transfer.address.length - 4)}
{transfer.address !== undefined
? `• ${transfer.address.substring(0, 6)}...${transfer.address.substring(
transfer.address.length - 4
)}`
: '• UNFINISHED'}
</p>
</div>
</div>

<SkPaper gray>
{transfer.transactions.map((transactionData: interfaces.TransactionHistory) => (
<TransactionData
Expand Down
5 changes: 5 additions & 0 deletions src/components/WidgetBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function WidgetBody(props) {
const tokenBalances = useMetaportStore((state) => state.tokenBalances)

const transferInProgress = useMetaportStore((state) => state.transferInProgress)
const addressChanged = useMetaportStore((state) => state.addressChanged)

const theme = useUIStore((state) => state.theme)

Expand All @@ -64,6 +65,10 @@ export function WidgetBody(props) {
setChainName2(mpc.config.chains ? mpc.config.chains[1] : '')
}, [])

useEffect(() => {
addressChanged()
}, [address])

useEffect(() => {
if (tokens && !token) {
if (tokens.erc20 && Object.values(tokens.erc20)[0]) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/interfaces/TransactionHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface TransactionHistory {
export interface TransferHistory {
transactions: TransactionHistory[]
tokenKeyname: string
address: AddressType
address: AddressType | undefined
chainName1: string
chainName2: string
amount: string
Expand Down
2 changes: 2 additions & 0 deletions src/store/MetaportState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export interface MetaportState {
setChainName1: (name: string) => void
setChainName2: (name: string) => void

addressChanged: () => void

appName1: string
appName2: string

Expand Down
23 changes: 23 additions & 0 deletions src/store/MetaportStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,29 @@ export const useMetaportStore = create<MetaportState>()((set, get) => ({
set(get().mpc.chainChanged(get().chainName1, name, get().token))
},

addressChanged: () => {
if (get().currentStep !== 0) {
get().setTransfersHistory([
...get().transfersHistory,
{
transactions: get().transactionsHistory,
chainName1: get().chainName1,
chainName2: get().chainName2,
amount: get().amount,
tokenKeyname: get().token.keyname,
address: undefined
}
])
}
set({
tokenBalances: {},
wrappedTokenBalances: {},
currentStep: 0,
amount: '',
transferInProgress: false
})
},

tokens: getEmptyTokenDataMap(),

token: null,
Expand Down
Loading