-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: centralize connector dialog routes in a single ocmponent
- Loading branch information
1 parent
5044224
commit f703570
Showing
5 changed files
with
100 additions
and
106 deletions.
There are no files selected for viewing
58 changes: 0 additions & 58 deletions
58
packages/react/src/ui/Connect/components/Connector/Connecting.tsx
This file was deleted.
Oops, something went wrong.
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
63 changes: 63 additions & 0 deletions
63
packages/react/src/ui/Connect/components/Connector/utils.ts
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,63 @@ | ||
import type { FuelConnector } from 'fuels'; | ||
import { DialogState } from '../../../../providers/FuelUIProvider'; | ||
|
||
interface DialogLabelData { | ||
title: string; | ||
description?: string; | ||
buttonLabel?: string; | ||
} | ||
|
||
function getButtonLabel(dialogState: DialogState) { | ||
switch (dialogState) { | ||
case DialogState.INSTALL: | ||
return 'Install'; | ||
case DialogState.INSTALLED: | ||
return 'Connect'; | ||
case DialogState.ERROR: | ||
return 'Retry'; | ||
default: | ||
return undefined; | ||
} | ||
} | ||
|
||
function getTitle(dialogState: DialogState, connector: FuelConnector) { | ||
switch (dialogState) { | ||
case DialogState.CONNECTING: | ||
case DialogState.INSTALLED: | ||
case DialogState.INSTALL: | ||
if (connector.installed) { | ||
return `${connector.name} is Installed!`; | ||
} | ||
return `Don't have ${connector.name}?`; | ||
case DialogState.ERROR: | ||
return `Failed to connect to ${connector.name}`; | ||
default: | ||
return connector.name; | ||
} | ||
} | ||
|
||
function getDescription(dialogState: DialogState, connector: FuelConnector) { | ||
switch (dialogState) { | ||
case DialogState.CONNECTING: | ||
case DialogState.INSTALL: | ||
if (connector.installed) { | ||
return `You will be requested to connect it to ${window.location.origin}`; | ||
} | ||
return `Install ${connector.name} now by clicking the link bellow and return here to connect it!`; | ||
case DialogState.INSTALLED: | ||
return `Click on the button bellow to connect your to ${window.location.origin}`; | ||
case DialogState.ERROR: | ||
return 'Click on the button below to try again.'; | ||
default: | ||
return undefined; | ||
} | ||
} | ||
|
||
export const getDialogLabels: ( | ||
state: DialogState, | ||
connector: FuelConnector, | ||
) => DialogLabelData = (state, connector) => ({ | ||
title: getTitle(state, connector), | ||
description: getDescription(state, connector), | ||
buttonLabel: getButtonLabel(state), | ||
}); |
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