-
Notifications
You must be signed in to change notification settings - Fork 144
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
Feat: Reorganize Wallet PopUp #945
Merged
fricoben
merged 2 commits into
lfglabs-dev:testnet
from
Villarley:feat/ReorganizeWalletPopUP
Nov 13, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { sortConnectors } from "../../utils/connectors"; | ||
class MockConnector { | ||
constructor(id, name, isAvailable) { | ||
this.id = id; | ||
this.name = name; | ||
this.isAvailable = isAvailable; | ||
} | ||
available() { | ||
return this.isAvailable; | ||
} | ||
} | ||
|
||
describe("sortConnectors function", () => { | ||
it("should place available connectors first, followed by unavailable ones", () => { | ||
const connectors = [ | ||
new MockConnector("okxwallet", "Okx Wallet", false), | ||
new MockConnector("braavos", "Braavos", true), | ||
new MockConnector("bitkeep", "Bitget Wallet", false), | ||
new MockConnector("argentX", "Argent X", true), | ||
]; | ||
|
||
const sortedConnectors = sortConnectors(connectors); | ||
|
||
expect(sortedConnectors[0].name).toBe("Braavos"); | ||
expect(sortedConnectors[1].name).toBe("Argent X"); | ||
expect(sortedConnectors[2].name).toBe("Okx Wallet"); | ||
expect(sortedConnectors[3].name).toBe("Bitget Wallet"); | ||
}); | ||
|
||
it("should return an empty array if no connectors are provided", () => { | ||
const sortedConnectors = sortConnectors([]); | ||
expect(sortedConnectors).toEqual([]); | ||
}); | ||
|
||
it("should handle the case when all connectors are available", () => { | ||
const connectors = [ | ||
new MockConnector("braavos", "Braavos", true), | ||
new MockConnector("argentX", "Argent X", true), | ||
]; | ||
|
||
const sortedConnectors = sortConnectors(connectors); | ||
|
||
expect(sortedConnectors[0].name).toBe("Braavos"); | ||
expect(sortedConnectors[1].name).toBe("Argent X"); | ||
}); | ||
|
||
it("should handle the case when all connectors are unavailable", () => { | ||
const connectors = [ | ||
new MockConnector("okxwallet", "Okx Wallet", false), | ||
new MockConnector("bitkeep", "Bitget Wallet", false), | ||
]; | ||
|
||
const sortedConnectors = sortConnectors(connectors); | ||
|
||
expect(sortedConnectors[0].name).toBe("Okx Wallet"); | ||
expect(sortedConnectors[1].name).toBe("Bitget Wallet"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Connector } from "starknetkit"; | ||
|
||
export const sortConnectors = (connectors: Connector[]): Connector[] => { | ||
const available: Connector[] = []; | ||
const notAvailable: Connector[] = []; | ||
|
||
// Sort connectors | ||
connectors.forEach((connector) => { | ||
if (connector.available()) { | ||
available.push(connector); | ||
} else { | ||
notAvailable.push(connector); | ||
} | ||
}); | ||
|
||
return [ | ||
...available, | ||
// Reorganized not available connectors | ||
...notAvailable.sort((a, b) => { | ||
const order = ["okxwallet", "bitkeep"]; // desired order | ||
return order.indexOf(a.id) - order.indexOf(b.id); | ||
}), | ||
]; | ||
}; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve robustness of connector ordering logic
The current implementation has several potential issues:
Consider this improved implementation:
📝 Committable suggestion